Skip to content

Commit 6447a82

Browse files
committed
Lock _PyGen_yf
1 parent ebdc293 commit 6447a82

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Objects/genobject.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ is_resume(_Py_CODEUNIT *instr)
366366
);
367367
}
368368

369-
PyObject *
370-
_PyGen_yf(PyGenObject *gen)
369+
static PyObject *
370+
_PyGen_yf_lock_held(PyGenObject *gen)
371371
{
372372
if (gen->gi_frame_state == FRAME_SUSPENDED_YIELD_FROM) {
373373
_PyInterpreterFrame *frame = &gen->gi_iframe;
@@ -379,8 +379,18 @@ _PyGen_yf(PyGenObject *gen)
379379
return NULL;
380380
}
381381

382+
PyObject *
383+
_PyGen_yf(PyGenObject *gen)
384+
{
385+
PyObject *res;
386+
Py_BEGIN_CRITICAL_SECTION(gen);
387+
res = _PyGen_yf_lock_held(gen);
388+
Py_END_CRITICAL_SECTION();
389+
return res;
390+
}
391+
382392
static PyObject *
383-
gen_close(PyObject *self, PyObject *args)
393+
gen_close_lock_held(PyObject *self, PyObject *args)
384394
{
385395
PyGenObject *gen = _PyGen_CAST(self);
386396

@@ -446,7 +456,6 @@ gen_close(PyObject *self, PyObject *args)
446456
return NULL;
447457
}
448458

449-
450459
PyDoc_STRVAR(throw_doc,
451460
"throw(value)\n\
452461
throw(type[,value[,tb]])\n\

0 commit comments

Comments
 (0)