-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Using dynamic_cast<AliasType>
to determine pointee_depends_on_holder_owner
.
#2910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…Python cannot be transferred to C++. TODO: static_assert alias class needs to inherit from virtual_overrider_self_life_support.
…to C++.", but based on dynamic_cast<AliasType>.
05cab00
to
cac54ba
Compare
…ling for To = void. Adding corresponding missing test in test_class_sh_virtual_py_cpp_mix. Moving dynamic_raw_ptr_cast_if_possible to separate header.
…al_overrider_self_life_support.
The CI is green, also with |
rwgk
added a commit
to google/clif
that referenced
this pull request
Mar 19, 2021
pybind/pybind11#2910 Also importing a few other changes from smart_holder branch, to bring third_party/pybind11 in sync with HEAD. Two tests under third_party/clif have to be adjusted in connection with PR #2910. The TGP test is for an intermediate snapshot of this CL, but it is highly unlikely that the changes made after that snapshot have any impact outside third_party/pybind11 or third_party/clif. Manual retesting succeeds: ``` blaze test third_party/pybind11/... third_party/pybind11_abseil/... third_party/pybind11_protobuf/... third_party/clif/... ``` http://sponge2/c54daa2b-9216-4898-82ae-9d5ac6c8ff26 When testing with ASAN all test pass, except one breakage unrelated to this CL: http://sponge2/03bd6edc-7b01-4b32-939d-fc760d81eaa0 The ASAN breakage was introduced with cl/363927286 and is being worked on separately. - 784092dfd29d861af6fa611c6920c172389d97c4 Missing cast from const unique_ptr& (#2904) by Robert Haschke <rhaschke@users.noreply.github.com> - 2ada792085777d9cc8b4006b60476f4a103b6870 Pure clang-format cleanup (after #2904), NO other changes. by Ralf W. Grosse-Kunstleve <rwgk@google.com> - 245d31cb0369fa51d94641853bb7beb6ed144b4f Renaming PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS to PY... by Ralf W. Grosse-Kunstleve <rwgk@google.com> - 62a8d35831525d5dcc4f6a53717d36a11c143f2a Fixing oversight: clang-format pybind11.h (affecting smar... by Ralf W. Grosse-Kunstleve <rwgk@google.com> - 3f35af74410dcace27b6cf9e8203934e13a32249 Adding smart_holder branch to workflow_dispatch in all pl... by Ralf W. Grosse-Kunstleve <rwgk@google.com> - 5319ca3817c77bb1fae233086ceeb71ec142c36f Using `dynamic_cast<AliasType>` to determine `pointee_dep... by Ralf W. Grosse-Kunstleve <rwgk@google.com> PiperOrigin-RevId: 363957176
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
smart holder
See: https://github.com/pybind/pybind11/blob/smart_holder/README_smart_holder.rst
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a follow-on to PR #2902, implementing a refinement of a safety guard that previously prevented not only unsafe behavior, but also safe behavior. All relevant situations are exercised by the newly added test_class_sh_virtual_py_cpp_mix.py. Specifically, e.g.
m.get_from_cpp_unique_ptr(m.Base())
fails before this PR.The critical change in this PR is in smart_holder_type_casters.h:
has_alias
is true for any instance of apy::class_
with an alias class (aka trampoline). E.g. it is true form.Base()
andPyBase()
in test_class_sh_virtual_py_cpp_mix.py. The newly useddynamic_cast
-based test is true only forPyBase()
.The idea for using a
dynamic_cast
here goes back to:pybind11/include/pybind11/detail/init.h
Line 49 in 0e01c24
The exception message for the safety guard (also in smart_holder_type_casters.h) was made more precise and helpful:
Not directly related to the behavior change,
py::detail::virtual_overrider_self_life_support
was moved topy::virtual_overrider_self_life_support
, to reflect that it is part of the public interface.The behavior change under this PR has an effect on test_class_sh_trampoline_shared_ptr_cpp_arg.py, which was adopted from PR #2839 previously.
test_shared_ptr_alias_nonpython
is now in line with the behavior under PR #2839, buttest_shared_ptr_arg_identity
behaves differently here. This may need another look, but it appears that thehas_alias/is_alias
logic under PR #2839 may need a refinement similar to what is implemented in this PR.