Commit Graph

1184 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
c8eb29c8f5 Fixing up cast.h and smart_holder.h after rebase. 2021-02-09 06:47:45 -08:00
Ralf W. Grosse-Kunstleve
b9eb2a46c4 Setting record.default_holder correctly for PYBIND11_USE_SMART_HOLDER_AS_DEFAULT.
With this test_class.cpp builds and even mostly runs, except
`test_multiple_instances_with_same_pointer`, which segfaults because it is
using a `unique_ptr` holder but `smart_holder` `type_caster`.

Also adding `static_assert`s to generate build errors for such situations,
but guarding with `#if 0` to first pivot to test_factory_constructors.cpp.
2021-02-09 06:47:44 -08:00
Ralf W. Grosse-Kunstleve
ce79f9126d Introducing PYBIND11_USE_SMART_HOLDER_AS_DEFAULT macro (tested only undefined; there are many errors with the macro defined). 2021-02-09 06:47:44 -08:00
Ralf W. Grosse-Kunstleve
72f52be256 Unification of unique_ptr, unique_ptr_with_deleter code in smart_holder_poc.h. Leads to more fitting error messages. Enables use of unique_ptr<T, D> smart_holder_type_casters also for unique_ptr<T>. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
a9bfcbdcc3 Adding smart_holder_type_casters for unique_ptr with custom deleter. SEVERE CODE DUPLICATION. This commit is to establish a baseline for consolidating the unique_ptr code. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
231bd84fa0 Moving up is_smart_holder_type_caster, to also use in cast_is_temporary_value_reference. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
c9d73aaa43 Giving up on idea to use legacy init_instance only if is_base_of<type_caster_generic, type_caster<T>. There are use cases in the wild that define both a custom type_caster and class_. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
149e332b3e Adding classu alias for class_<U, std::unique_ptr<U>>. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
1e4c2e04ae Fixing oversight. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
742bc0eaf7 Replacing detail::is_smart_holder<H> in cast.h with detail::is_smart_holder_type_caster<T>.
Moving get_local_load_function_ptr, init_instance_for_type to smart_holder_type_caster_class_hooks.
Expanding static_assert in py::type::handle_of<> to accommodate smart_holder_type_casters.
2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
87acc89b21 Reintroducing py::classh, this time as a simple alias for py::class_<U, py::smart_holder>. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
4a4087fdd5 Moving define PYBIND11_SMART_HOLDER_TYPE_CASTERS(T) down in the file. NO functional changes. Preparation for follow-up work (to keep that diff smaller). 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
d5b591d7f8 Making use of the new find_existing_python_instance() function factored out with PR #2822. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
63fe989148 Adding copyright notices to new header files. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
94eeb34b01 Reusing type_caster_base make_copy_constructor, make_move_constructor with a trick. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
56a71520b5 32-bit compatibility. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
eac5b49fe1 clang-tidy fixes. 2021-02-09 06:47:08 -08:00
Ralf W. Grosse-Kunstleve
bda4178163 Renaming all "classh" to "smart_holder" in pybind11/detail/smart_holder_type_casters.h.
The user-facing macro is now PYBIND11_SMART_HOLDER_TYPE_CASTERS.
2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
e96c06e61a Renaming files in include directory, creating pybind11/smart_holder.h. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
661eeb381c Adding py::smart_holder support to py::class_, purging py::classh completely. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
2d463aa3b6 Purging obsolete pybind11/vptr_holder.h and associated test. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
d659a1411b Removing debugging comments (GET_STACK, GET_INT_STACK). cast.h is identical to current master again, pybind11.h only has the generic_type::initialize(..., &type_caster_generic::local_load) change. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
3d17f6f6a1 Using unique_ptr in local_load to replace static variable. Also adding local_load_safety_guard. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
631a288d69 Folding convert_type into lvalue_ref and rvalue_ref paths. Some smart_holder_type_caster_load cleanup. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
e7325dfc26 Factoring out convert_type and folding into loaded_as_unique_ptr. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
db9af62ad8 Cleaning up loaded_as_raw_ptr_unowned, loaded_as_shared_ptr. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
c30cc404c9 Removing rtti_held from smart_holder. See updated comment. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
0f82a0b014 Adding smart_holder_type_caster_load::loaded_as_shared_ptr, currently bypassing smart_holder shared_ptr tracking completely, but the tests pass and are sanitizer clean. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
cbebb6da1f Tests for classh py::module_local() feature. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
5608b71e09 Removing stray isinstance<T>(src): it interferes with the py::module_local feature. Adding missing #includes. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
c362b91a80 Minimal test covering classh_type_casters load_impl Case 2b. 2021-02-09 06:47:07 -08:00
Ralf W. Grosse-Kunstleve
82f619bdb2 Changes and tests covering classh_type_casters try_implicit_casts. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
3d4bf091f3 Decoupling generic_type from type_caster_generic. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
e345db05bd First pass adjusting try_implicit_casts and try_load_foreign_module_local to capture loaded_v_h, but untested and guarded with pybind11_failure("Untested"). This was done mainly to determine general feasibility. Note the TODO in pybind11.h, where type_caster_generic::local_load is currently hard-coded. test_classh_wip and test_classh_inheritance still pass, as before. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
383f7e9b84 Minimal changes needed to pass test_classh_inheritance. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
dc537a0013 Folding in modified_type_caster_generic_load_impl, just enough to pass test_class_wip. test_classh_inheritance is still failing, but with a different error: [RuntimeError: Incompatible type (as_raw_ptr_unowned).] 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
d7efc9b8b1 Adding & using PYBIND11_CLASSH_TYPE_CASTERS define. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
1ef19a1e04 Using pybind11/detail/classh_type_casters.h from test_classh_wip.cpp. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
29414e6e95 Copying classh type_casters from test_classh_wip.cpp UNMODIFIED, as a baseline for generalizing the code. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
2a7d41c193 Moving factored-out make_constructor to test_classh_wip.cpp, restoring previous version of cast.h. This is currently the most practical approach. See PR #2798 for background. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
ec86f10038 Using factored-out make_constructor (PR #2798), removing duplicate code. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
86ba2081af Removing enable_shared_from_this stub, simplifying existing code, clang-format.
Open question, with respect to the original code:
76a160070b/include/pybind11/pybind11.h (L1510)
To me it looks like the exact situation marked as `std::shared_ptr<Good> gp1 = not_so_good.getptr();` here: https://en.cppreference.com/w/cpp/memory/enable_shared_from_this
The comment there is: `// undefined behavior (until C++17) and std::bad_weak_ptr thrown (since C++17)`
Does the existing code have UB pre C++17?

I'll leave handling of enable_shared_from_this for later, as the need arises.
2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
e4d6d860b6 Fixing bugs discovered by ASAN. The code is now ASAN, MSAN, UBSAN clean. 2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
3bc50c57b4 Bug fix: vptr_deleter_armed_flag_ptr has to live on the heap.
See new bullet point in comment section near the top.

The variable was also renamed to reflect its function more accurately.
2021-02-09 06:47:06 -08:00
Ralf W. Grosse-Kunstleve
6601ec4ea7 static handle cast implementations for rtrn_shmp, rtrn_shcp. 2021-02-09 06:47:05 -08:00
Ralf W. Grosse-Kunstleve
649eb91f21 Adding comment re potential use_count data race. 2021-02-09 06:47:05 -08:00
Ralf W. Grosse-Kunstleve
e7aea026bb Pure clang-format --style=file -i change. 2021-02-09 06:47:05 -08:00
Ralf W. Grosse-Kunstleve
6277910abd Improved error messaging: Cannot disown nullptr (as_unique_ptr). 2021-02-09 06:47:05 -08:00
Ralf W. Grosse-Kunstleve
fe5427fc23 Adding rvalue_ref, renaming const_value_ref to lvalue_ref & removing const. 2021-02-09 06:47:05 -08:00
Ralf W. Grosse-Kunstleve
c8d19f9599 Hard-coding smart_holder into classh. 2021-02-09 06:47:05 -08:00