@@ -825,7 +825,7 @@ gen_getsuspended_get_impl(PyGenObject *self)
825825}
826826
827827static PyObject *
828- _gen_getframe (PyGenObject * self , const char * name )
828+ gen_getframe_lock_held (PyGenObject * self , const char * name )
829829{
830830 PyGenObject * gen = _PyGen_CAST (self );
831831 if (PySys_Audit ("object.__getattr__" , "Os" , gen , name ) < 0 ) {
@@ -843,7 +843,7 @@ gen_getframe(PyObject *self, void *Py_UNUSED(ignored))
843843 PyGenObject * gen = _PyGen_CAST (self );
844844 PyObject * res ;
845845 Py_BEGIN_CRITICAL_SECTION (gen );
846- res = _gen_getframe (gen , "gi_frame" );
846+ res = gen_getframe_lock_held (gen , "gi_frame" );
847847 Py_END_CRITICAL_SECTION ();
848848 return res ;
849849}
@@ -1210,7 +1210,11 @@ cr_getrunning(PyObject *self, void *Py_UNUSED(ignored))
12101210static PyObject *
12111211cr_getframe (PyObject * coro , void * Py_UNUSED (ignored ))
12121212{
1213- return _gen_getframe (_PyGen_CAST (coro ), "cr_frame" );
1213+ PyObject * res ;
1214+ Py_BEGIN_CRITICAL_SECTION (coro );
1215+ res = gen_getframe_lock_held (_PyGen_CAST (coro ), "cr_frame" );
1216+ Py_END_CRITICAL_SECTION ();
1217+ return res ;
12141218}
12151219
12161220static PyObject *
@@ -1632,7 +1636,11 @@ async_gen_athrow(PyAsyncGenObject *o, PyObject *args)
16321636static PyObject *
16331637ag_getframe (PyObject * ag , void * Py_UNUSED (ignored ))
16341638{
1635- return _gen_getframe ((PyGenObject * )ag , "ag_frame" );
1639+ PyObject * res ;
1640+ Py_BEGIN_CRITICAL_SECTION (ag );
1641+ res = gen_getframe_lock_held ((PyGenObject * )ag , "ag_frame" );
1642+ Py_END_CRITICAL_SECTION ();
1643+ return res ;
16361644}
16371645
16381646static PyObject *
0 commit comments