File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -350,13 +350,19 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) {
350
350
auto type = Py_TYPE (self);
351
351
type->tp_free (self);
352
352
353
+ #if PY_VERSION_HEX < 0x03080000
353
354
// `type->tp_dealloc != pybind11_object_dealloc` means that we're being called
354
355
// as part of a derived type's dealloc, in which case we're not allowed to decref
355
356
// the type here. For cross-module compatibility, we shouldn't compare directly
356
357
// with `pybind11_object_dealloc`, but with the common one stashed in internals.
357
358
auto pybind11_object_type = (PyTypeObject *) get_internals ().instance_base ;
358
359
if (type->tp_dealloc == pybind11_object_type->tp_dealloc )
359
360
Py_DECREF (type);
361
+ #else
362
+ // This was not needed before Python 3.8 (Python issue 35810)
363
+ // https://github.com/pybind/pybind11/issues/1946
364
+ Py_DECREF (type);
365
+ #endif
360
366
}
361
367
362
368
/* * Create the type which can be used as a common base for all classes. This is
You can’t perform that action at this time.
0 commit comments