pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

[smart_holder] Add `gil_scoped_acquire` to `shared_ptr_trampoline_self_life_support` ctor.

Open rwgk opened this issue 3 years ago • 0 comments

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:


rwgk avatar Sep 25 '22 22:09 rwgk