|
11 | 11 |
|
12 | 12 | #include <pybind11/attr.h> |
13 | 13 | #include <pybind11/options.h> |
| 14 | +#include <pybind11/pybind11.h> |
| 15 | +#include <pybind11/pytypes.h> |
14 | 16 |
|
15 | 17 | #include "exception_translation.h" |
16 | 18 |
|
17 | 19 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) |
| 20 | + |
| 21 | +class weakref; |
| 22 | +class cpp_function; |
| 23 | + |
18 | 24 | PYBIND11_NAMESPACE_BEGIN(detail) |
19 | 25 |
|
20 | 26 | #if !defined(PYPY_VERSION) |
@@ -252,11 +258,6 @@ extern "C" inline void pybind11_meta_dealloc(PyObject *obj) { |
252 | 258 | }); |
253 | 259 |
|
254 | 260 | PyType_Type.tp_dealloc(obj); |
255 | | - |
256 | | - // Release the references to the internals capsules that were acquired in make_new_python_type. |
257 | | - // See the comment there for details on preventing use-after-free during interpreter shutdown. |
258 | | - Py_XDECREF(get_internals_capsule()); |
259 | | - Py_XDECREF(get_local_internals_capsule()); |
260 | 261 | } |
261 | 262 |
|
262 | 263 | /** This metaclass is assigned by default to all pybind11 types and is required in order |
@@ -834,15 +835,6 @@ inline PyObject *make_new_python_type(const type_record &rec) { |
834 | 835 |
|
835 | 836 | PYBIND11_SET_OLDPY_QUALNAME(type, qualname); |
836 | 837 |
|
837 | | - // Prevent use-after-free during interpreter shutdown. GC order is not guaranteed, so the |
838 | | - // internals capsule may be destroyed (resetting internals via internals_shutdown) before all |
839 | | - // pybind11 types are destroyed. If a type's tp_traverse/tp_clear then calls py::cast, it |
840 | | - // would recreate an empty internals and fail because the type registry is gone. By holding |
841 | | - // references to the capsules, we ensure they outlive all pybind11 types. The decref happens |
842 | | - // in pybind11_meta_dealloc. |
843 | | - Py_XINCREF(get_internals_capsule()); |
844 | | - Py_XINCREF(get_local_internals_capsule()); |
845 | | - |
846 | 838 | return reinterpret_cast<PyObject *>(type); |
847 | 839 | } |
848 | 840 |
|
|
0 commit comments