mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-12 00:23:53 +00:00
c07ec31edf
If we need to initialize a holder around an unowned instance, and the holder type is non-copyable (i.e. a unique_ptr), we currently construct the holder type around the value pointer, but then never actually destruct the holder: the holder destructor is called only for the instance that actually has `inst->owned = true` set. This seems no pointer, however, in creating such a holder around an unowned instance: we never actually intend to use anything that the unique_ptr gives us: and, in fact, do not want the unique_ptr (because if it ever actually got destroyed, it would cause destruction of the wrapped pointer, despite the fact that that wrapped pointer isn't owned). This commit changes the logic to only create a unique_ptr holder if we actually own the instance, and to destruct via the constructed holder whenever we have a constructed holder--which will now only be the case for owned-unique-holder or shared-holder types. Other changes include: * Added test for non-movable holder constructor/destructor counts The three alive assertions now pass, before #478 they fail with counts of 2/2/1 respectively, because of the unique_ptr that we don't want and don't destroy (because we don't *want* its destructor to run). * Return cstats reference; fix ConstructStats doc Small cleanup to the #478 test code, and fix to the ConstructStats documentation (the static method definition should use `reference` not `reference_internal`). * Rename inst->constructed to inst->holder_constructed This makes it clearer exactly what it's referring to. |
||
---|---|---|
.. | ||
CMakeLists.txt | ||
conftest.py | ||
constructor_stats.h | ||
object.h | ||
pybind11_tests.cpp | ||
pybind11_tests.h | ||
test_alias_initialization.cpp | ||
test_alias_initialization.py | ||
test_buffers.cpp | ||
test_buffers.py | ||
test_callbacks.cpp | ||
test_callbacks.py | ||
test_chrono.cpp | ||
test_chrono.py | ||
test_class_args.cpp | ||
test_class_args.py | ||
test_constants_and_functions.cpp | ||
test_constants_and_functions.py | ||
test_copy_move_policies.cpp | ||
test_copy_move_policies.py | ||
test_eigen.cpp | ||
test_eigen.py | ||
test_enum.cpp | ||
test_enum.py | ||
test_eval_call.py | ||
test_eval.cpp | ||
test_eval.py | ||
test_exceptions.cpp | ||
test_exceptions.py | ||
test_inheritance.cpp | ||
test_inheritance.py | ||
test_issues.cpp | ||
test_issues.py | ||
test_keep_alive.cpp | ||
test_keep_alive.py | ||
test_kwargs_and_defaults.cpp | ||
test_kwargs_and_defaults.py | ||
test_methods_and_attributes.cpp | ||
test_methods_and_attributes.py | ||
test_modules.cpp | ||
test_modules.py | ||
test_multiple_inheritance.cpp | ||
test_multiple_inheritance.py | ||
test_numpy_array.cpp | ||
test_numpy_array.py | ||
test_numpy_dtypes.cpp | ||
test_numpy_dtypes.py | ||
test_numpy_vectorize.cpp | ||
test_numpy_vectorize.py | ||
test_opaque_types.cpp | ||
test_opaque_types.py | ||
test_operator_overloading.cpp | ||
test_operator_overloading.py | ||
test_pickling.cpp | ||
test_pickling.py | ||
test_python_types.cpp | ||
test_python_types.py | ||
test_sequences_and_iterators.cpp | ||
test_sequences_and_iterators.py | ||
test_smart_ptr.cpp | ||
test_smart_ptr.py | ||
test_stl_binders.cpp | ||
test_stl_binders.py | ||
test_virtual_functions.cpp | ||
test_virtual_functions.py |