diff options
author | Mark Shannon <mark@hotpy.org> | 2022-08-25 09:16:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-25 09:16:55 (GMT) |
commit | c09fa7542c6d9b724e423b14c6fb5f4338eabd12 (patch) | |
tree | e65689bd1bbb0d69a4cd54f3e475e79cc8d92d89 /Python/ceval.c | |
parent | 8db7693bbff55f5ed4bfc194c77c561e71471bf3 (diff) | |
download | cpython-c09fa7542c6d9b724e423b14c6fb5f4338eabd12.zip cpython-c09fa7542c6d9b724e423b14c6fb5f4338eabd12.tar.gz cpython-c09fa7542c6d9b724e423b14c6fb5f4338eabd12.tar.bz2 |
GH-96237: Allow non-functions as reference-holder in frames. (GH-96238)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index ac77ab8..b3a0a36 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -154,11 +154,12 @@ lltrace_instruction(_PyInterpreterFrame *frame, static void lltrace_resume_frame(_PyInterpreterFrame *frame) { - PyFunctionObject *f = frame->f_func; - if (f == NULL) { + PyObject *fobj = frame->f_funcobj; + if (fobj == NULL || !PyFunction_Check(fobj)) { printf("\nResuming frame."); return; } + PyFunctionObject *f = (PyFunctionObject *)fobj; PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); PyObject *name = f->func_qualname; @@ -2619,7 +2620,8 @@ handle_eval_breaker: TARGET(COPY_FREE_VARS) { /* Copy closure variables to free variables */ PyCodeObject *co = frame->f_code; - PyObject *closure = frame->f_func->func_closure; + assert(PyFunction_Check(frame->f_funcobj)); + PyObject *closure = ((PyFunctionObject *)frame->f_funcobj)->func_closure; int offset = co->co_nlocals + co->co_nplaincellvars; assert(oparg == co->co_nfreevars); for (int i = 0; i < oparg; ++i) { @@ -4897,7 +4899,9 @@ handle_eval_breaker: } TARGET(RETURN_GENERATOR) { - PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(frame->f_func); + assert(PyFunction_Check(frame->f_funcobj)); + PyFunctionObject *func = (PyFunctionObject *)frame->f_funcobj; + PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(func); if (gen == NULL) { goto error; } @@ -4919,7 +4923,7 @@ handle_eval_breaker: /* Make sure that frame is in a valid state */ frame->stacktop = 0; frame->f_locals = NULL; - Py_INCREF(frame->f_func); + Py_INCREF(frame->f_funcobj); Py_INCREF(frame->f_code); /* Restore previous cframe and return. */ tstate->cframe = cframe.previous; |