* fix: PyCapsule_GetDestructor is allowed to return a nullptr destructor Previously, this code would error out if the destructor happened to be a nullptr. This is incorrect. nullptrs are allowed for capsule destructors. "It is legal for a capsule to have a NULL destructor. This makes a NULL return code somewhat ambiguous; use PyCapsule_IsValid() or PyErr_Occurred() to disambiguate." See: https://docs.python.org/3/c-api/capsule.html#c.PyCapsule_GetDestructor I noticed this while working on a type caster related to #3858 DLPack happens to allow the destructor not to be defined on a capsule, and I encountered such a case. See: https://github.com/dmlc/dlpack/blob/e2bdd3bee8cb6501558042633fa59144cc8b7f5f/include/dlpack/dlpack.h#L219 * Add test for the fix. * Update tests/test_pytypes.cpp I tried this locally and it works! I never knew that there are cases where `reinterpret_cast` does not work but `static_cast` does. Let's see if all compilers are happy with this. Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> * style: pre-commit fixes Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: Ralf W. Grosse-Kunstleve <rwgkio@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
| Name |
Last commit
|
Last Update |
|---|---|---|
| .. | ||
| extra_python_package | Loading commit data... | |
| extra_setuptools | Loading commit data... | |
| test_cmake_build | Loading commit data... | |
| test_embed | Loading commit data... | |
| CMakeLists.txt | Loading commit data... | |
| conftest.py | Loading commit data... | |
| constructor_stats.h | Loading commit data... | |
| cross_module_gil_utils.cpp | Loading commit data... | |
| cross_module_interleaved_error_already_set.cpp | Loading commit data... | |
| env.py | Loading commit data... | |
| local_bindings.h | Loading commit data... | |
| object.h | Loading commit data... | |
| pybind11_cross_module_tests.cpp | Loading commit data... | |
| pybind11_tests.cpp | Loading commit data... | |
| pybind11_tests.h | Loading commit data... | |
| pytest.ini | Loading commit data... | |
| requirements.txt | Loading commit data... | |
| test_async.cpp | Loading commit data... | |
| test_async.py | Loading commit data... | |
| test_buffers.cpp | Loading commit data... | |
| test_buffers.py | Loading commit data... | |
| test_builtin_casters.cpp | Loading commit data... | |
| test_builtin_casters.py | Loading commit data... | |
| test_call_policies.cpp | Loading commit data... | |
| test_call_policies.py | Loading commit data... | |
| test_callbacks.cpp | Loading commit data... | |
| test_callbacks.py | Loading commit data... | |
| test_chrono.cpp | Loading commit data... | |
| test_chrono.py | Loading commit data... | |
| test_class.cpp | Loading commit data... | |
| test_class.py | Loading commit data... | |
| test_const_name.cpp | Loading commit data... | |
| test_const_name.py | Loading commit data... | |
| test_constants_and_functions.cpp | Loading commit data... | |
| test_constants_and_functions.py | Loading commit data... | |
| test_copy_move.cpp | Loading commit data... | |
| test_copy_move.py | Loading commit data... | |
| test_custom_type_casters.cpp | Loading commit data... | |
| test_custom_type_casters.py | Loading commit data... | |
| test_custom_type_setup.cpp | Loading commit data... | |
| test_custom_type_setup.py | Loading commit data... | |
| test_docstring_options.cpp | Loading commit data... | |
| test_docstring_options.py | Loading commit data... | |
| test_eigen.cpp | Loading commit data... | |
| test_eigen.py | Loading commit data... | |
| test_enum.cpp | Loading commit data... | |
| test_enum.py | Loading commit data... | |
| test_eval.cpp | Loading commit data... | |
| test_eval.py | Loading commit data... | |
| test_eval_call.py | Loading commit data... | |
| test_exceptions.cpp | Loading commit data... | |
| test_exceptions.h | Loading commit data... | |
| test_exceptions.py | Loading commit data... | |
| test_factory_constructors.cpp | Loading commit data... | |
| test_factory_constructors.py | Loading commit data... | |
| test_gil_scoped.cpp | Loading commit data... | |
| test_gil_scoped.py | Loading commit data... | |
| test_iostream.cpp | Loading commit data... | |
| test_iostream.py | Loading commit data... | |
| test_kwargs_and_defaults.cpp | Loading commit data... | |
| test_kwargs_and_defaults.py | Loading commit data... | |
| test_local_bindings.cpp | Loading commit data... | |
| test_local_bindings.py | Loading commit data... | |
| test_methods_and_attributes.cpp | Loading commit data... | |
| test_methods_and_attributes.py | Loading commit data... | |
| test_modules.cpp | Loading commit data... | |
| test_modules.py | Loading commit data... | |
| test_multiple_inheritance.cpp | Loading commit data... | |
| test_multiple_inheritance.py | Loading commit data... | |
| test_numpy_array.cpp | Loading commit data... | |
| test_numpy_array.py | Loading commit data... | |
| test_numpy_dtypes.cpp | Loading commit data... | |
| test_numpy_dtypes.py | Loading commit data... | |
| test_numpy_vectorize.cpp | Loading commit data... | |
| test_numpy_vectorize.py | Loading commit data... | |
| test_opaque_types.cpp | Loading commit data... | |
| test_opaque_types.py | Loading commit data... | |
| test_operator_overloading.cpp | Loading commit data... | |
| test_operator_overloading.py | Loading commit data... | |
| test_pickling.cpp | Loading commit data... | |
| test_pickling.py | Loading commit data... | |
| test_pytypes.cpp | Loading commit data... | |
| test_pytypes.py | Loading commit data... | |
| test_sequences_and_iterators.cpp | Loading commit data... | |
| test_sequences_and_iterators.py | Loading commit data... | |
| test_smart_ptr.cpp | Loading commit data... | |
| test_smart_ptr.py | Loading commit data... | |
| test_stl.cpp | Loading commit data... | |
| test_stl.py | Loading commit data... | |
| test_stl_binders.cpp | Loading commit data... | |
| test_stl_binders.py | Loading commit data... | |
| test_tagbased_polymorphic.cpp | Loading commit data... | |
| test_tagbased_polymorphic.py | Loading commit data... | |
| test_thread.cpp | Loading commit data... | |
| test_thread.py | Loading commit data... | |
| test_union.cpp | Loading commit data... | |
| test_union.py | Loading commit data... | |
| test_virtual_functions.cpp | Loading commit data... | |
| test_virtual_functions.py | Loading commit data... | |
| valgrind-numpy-scipy.supp | Loading commit data... | |
| valgrind-python.supp | Loading commit data... |