forked from pybind/pybind11
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change implementation of the `__init__() must be called when overridi…
…ng __init__` safety feature to work for any metaclass. (#30095) * Also wrap with `py::metaclass((PyObject *) &PyType_Type)` * Transfer additional tests from PyCLIF python_multiple_inheritance_test.py * Expand tests to fully cover wrapping with alternative metaclasses. * * Factor out `ensure_base_init_functions_were_called()`. * Call from new `tp_init_intercepted()` (adopting mechanism first added in PyCLIF: google/clif@7cba87d). * Remove `pybind11_meta_call()` (which was added with pybind#2152). * Bug fix (maybe actually two bugs?): simplify condition to `type->tp_init != tp_init_intercepted` * Removing `Py_DECREF(self)` that leads to MSAN failure (Google toolchain). ``` ==6380==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x5611589c9a58 in Py_DECREF third_party/python_runtime/v3_11/Include/object.h:537:9 ... Uninitialized value was created by a heap deallocation #0 0x5611552757b0 in free third_party/llvm/llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:218:3 #1 0x56115898e06b in _PyMem_RawFree third_party/python_runtime/v3_11/Objects/obmalloc.c:154:5 #2 0x56115898f6ad in PyObject_Free third_party/python_runtime/v3_11/Objects/obmalloc.c:769:5 #3 0x561158271bcc in PyObject_GC_Del third_party/python_runtime/v3_11/Modules/gcmodule.c:2407:5 #4 0x7f21224b070c in pybind11_object_dealloc third_party/pybind11/include/pybind11/detail/class.h:483:5 #5 0x5611589c2ed0 in subtype_dealloc third_party/python_runtime/v3_11/Objects/typeobject.c:1463:5 ... ``` * IncludeCleaner fixes (Google toolchain). * Restore `type->tp_call = pybind11_meta_call;` for PyPy only. * pytest.skip("ensure_base_init_functions_were_called() does not work with PyPy and Python `type` as metaclass") * Do not intercept our own `tp_init` function (`pybind11_object_init`). * Add `derived_tp_init_registry` weakref-based cleanup. * Replace `assert()` with `if` to resolve erroneous `lambda capture 'type' is not used` diagnostics (many CI jobs; seems to be a clang issue). * Add `derived_tp_init_registry()->count(type) == 0` condition. * Changes based on feedback from @rainwoodman * Use PYBIND11_INIT_SAFETY_CHECKS_VIA_* macros, based on suggestion from @rainwoodman
- Loading branch information
Ralf W. Grosse-Kunstleve
authored
Feb 1, 2024
1 parent
80c9ee6
commit 54f8341
Showing
4 changed files
with
234 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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