File tree Expand file tree Collapse file tree 1 file changed +6
-14
lines changed
Expand file tree Collapse file tree 1 file changed +6
-14
lines changed Original file line number Diff line number Diff line change @@ -251,16 +251,12 @@ extern "C" inline void pybind11_meta_dealloc(PyObject *obj) {
251251 }
252252 });
253253
254+ PyType_Type.tp_dealloc (obj);
255+
254256 // Release the references to the internals capsules that were acquired in make_new_python_type.
255257 // See the comment there for details on preventing use-after-free during interpreter shutdown.
256- if (PyObject *capsule = get_internals_capsule ()) {
257- Py_DECREF (capsule);
258- }
259- if (PyObject *capsule = get_local_internals_capsule ()) {
260- Py_DECREF (capsule);
261- }
262-
263- PyType_Type.tp_dealloc (obj);
258+ Py_XDECREF (get_internals_capsule ());
259+ Py_XDECREF (get_local_internals_capsule ());
264260}
265261
266262/* * This metaclass is assigned by default to all pybind11 types and is required in order
@@ -844,12 +840,8 @@ inline PyObject *make_new_python_type(const type_record &rec) {
844840 // would recreate an empty internals and fail because the type registry is gone. By holding
845841 // references to the capsules, we ensure they outlive all pybind11 types. The decref happens
846842 // in pybind11_meta_dealloc.
847- if (PyObject *capsule = get_internals_capsule ()) {
848- Py_INCREF (capsule);
849- }
850- if (PyObject *capsule = get_local_internals_capsule ()) {
851- Py_INCREF (capsule);
852- }
843+ Py_XINCREF (get_internals_capsule ());
844+ Py_XINCREF (get_local_internals_capsule ());
853845
854846 return reinterpret_cast <PyObject *>(type);
855847}
You can’t perform that action at this time.
0 commit comments