pybind11
pybind11 copied to clipboard
[smart_holder] Add `gil_scoped_acquire` to `shared_ptr_trampoline_self_life_support` ctor.
Description
This change fixes 9 failing targets discovered via Google-internal global testing with added PyGILState_Check() asserts in Py_INCREF() and Py_DECREF() (diff below).
TODO: Reduce failing tests and add as unit tests under pybind11/tests.
Python 3.9 Include/object.h:
PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
+PyAPI_FUNC(int) PyGILState_Check(void); /* Include/cpython/pystate.h */
+
static inline void _Py_INCREF(PyObject *op)
{
+ assert(PyGILState_Check());
#ifdef Py_REF_DEBUG
_Py_RefTotal++;
#endif
@@ -433,6 +436,7 @@ static inline void _Py_DECREF(
#endif
PyObject *op)
{
+ assert(PyGILState_Check());
#ifdef Py_REF_DEBUG
_Py_RefTotal--;
#endif
Internal testing ID: OCL:441666819:BASE:476672625:1664085876295:2e44fcc
Suggested changelog entry: