@@ -12360,18 +12360,16 @@ _super_lookup_descr(PyTypeObject *su_type, PyTypeObject *su_obj_type, PyObject *
1236012360 PyObject * mro , * res ;
1236112361 Py_ssize_t i , n ;
1236212362
12363- BEGIN_TYPE_LOCK ();
1236412363 mro = lookup_tp_mro (su_obj_type );
12365- /* keep a strong reference to mro because su_obj_type->tp_mro can be
12366- replaced during PyDict_GetItemRef(dict, name, &res) and because
12367- another thread can modify it after we end the critical section
12368- below */
12369- Py_XINCREF (mro );
12370- END_TYPE_LOCK ();
12371-
1237212364 if (mro == NULL )
1237312365 return NULL ;
1237412366
12367+ /* Keep a strong reference to mro because su_obj_type->tp_mro can be
12368+ replaced during PyDict_GetItemRef(dict, name, &res). */
12369+ PyThreadState * tstate = _PyThreadState_GET ();
12370+ _PyCStackRef mro_ref ;
12371+ _PyThreadState_PushCStackRefNew (tstate , & mro_ref , mro );
12372+
1237512373 assert (PyTuple_Check (mro ));
1237612374 n = PyTuple_GET_SIZE (mro );
1237712375
@@ -12382,7 +12380,7 @@ _super_lookup_descr(PyTypeObject *su_type, PyTypeObject *su_obj_type, PyObject *
1238212380 }
1238312381 i ++ ; /* skip su->type (if any) */
1238412382 if (i >= n ) {
12385- Py_DECREF ( mro );
12383+ _PyThreadState_PopCStackRef ( tstate , & mro_ref );
1238612384 return NULL ;
1238712385 }
1238812386
@@ -12393,13 +12391,13 @@ _super_lookup_descr(PyTypeObject *su_type, PyTypeObject *su_obj_type, PyObject *
1239312391
1239412392 if (PyDict_GetItemRef (dict , name , & res ) != 0 ) {
1239512393 // found or error
12396- Py_DECREF ( mro );
12394+ _PyThreadState_PopCStackRef ( tstate , & mro_ref );
1239712395 return res ;
1239812396 }
1239912397
1240012398 i ++ ;
1240112399 } while (i < n );
12402- Py_DECREF ( mro );
12400+ _PyThreadState_PopCStackRef ( tstate , & mro_ref );
1240312401 return NULL ;
1240412402}
1240512403
0 commit comments