diff --git a/Objects/genobject.c b/Objects/genobject.c index 562d41d674c..19d388eeebf 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -167,7 +167,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) /* Check for __future__ generator_stop and conditionally turn * a leaking StopIteration into RuntimeError (with its cause * set appropriately). */ - if (((PyCodeObject *)gen->gi_code)->co_flags & + if (gen->gi_code != NULL && ((PyCodeObject *)gen->gi_code)->co_flags & (CO_FUTURE_GENERATOR_STOP | CO_COROUTINE | CO_ITERABLE_COROUTINE)) { PyObject *exc, *val, *val2, *tb;