You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Change implementation of the __init__() must be called when overriding __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/pybind11#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
0 commit comments