don't run frame if it has no stack (closes #17669)
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 597aed3..016bfa2 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -178,7 +178,7 @@
     PyObject *yf = NULL;
     PyFrameObject *f = gen->gi_frame;
 
-    if (f) {
+    if (f && f->f_stacktop) {
         PyObject *bytecode = f->f_code->co_code;
         unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode);