File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ extern "C" {
64
64
65
65
# define _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED (op ) \
66
66
if (Py_REFCNT(op) != 1) { \
67
- _Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(& _PyObject_CAST(op)->ob_mutex ); \
67
+ _PyCriticalSection_AssertHeldObj( _PyObject_CAST(op)); \
68
68
}
69
69
70
70
#else /* Py_DEBUG */
@@ -239,6 +239,28 @@ _PyCriticalSection_AssertHeld(PyMutex *mutex)
239
239
#endif
240
240
}
241
241
242
+ static inline void
243
+ _PyCriticalSection_AssertHeldObj (PyObject * op )
244
+ {
245
+ #ifdef Py_DEBUG
246
+ PyMutex * mutex = & _PyObject_CAST (op )-> ob_mutex ;
247
+ PyThreadState * tstate = _PyThreadState_GET ();
248
+ uintptr_t prev = tstate -> critical_section ;
249
+ if (prev & _Py_CRITICAL_SECTION_TWO_MUTEXES ) {
250
+ PyCriticalSection2 * cs = (PyCriticalSection2 * )(prev & ~_Py_CRITICAL_SECTION_MASK );
251
+ _PyObject_ASSERT_WITH_MSG (op ,
252
+ (cs != NULL && (cs -> _cs_base ._cs_mutex == mutex || cs -> _cs_mutex2 == mutex )),
253
+ "Critical section of object is not held" );
254
+ }
255
+ else {
256
+ PyCriticalSection * cs = (PyCriticalSection * )(prev & ~_Py_CRITICAL_SECTION_MASK );
257
+ _PyObject_ASSERT_WITH_MSG (op ,
258
+ (cs != NULL && cs -> _cs_mutex == mutex ),
259
+ "Critical section of object is not held" );
260
+ }
261
+
262
+ #endif
263
+ }
242
264
#endif /* Py_GIL_DISABLED */
243
265
244
266
#ifdef __cplusplus
You can’t perform that action at this time.
0 commit comments