summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-08-25 09:16:55 (GMT)
committerGitHub <noreply@github.com>2022-08-25 09:16:55 (GMT)
commitc09fa7542c6d9b724e423b14c6fb5f4338eabd12 (patch)
treee65689bd1bbb0d69a4cd54f3e475e79cc8d92d89 /Objects
parent8db7693bbff55f5ed4bfc194c77c561e71471bf3 (diff)
downloadcpython-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 'Objects')
-rw-r--r--Objects/frameobject.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 26b38ba..d2647bd 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -910,7 +910,7 @@ frame_dealloc(PyFrameObject *f)
/* Don't clear code object until the end */
co = frame->f_code;
frame->f_code = NULL;
- Py_CLEAR(frame->f_func);
+ Py_CLEAR(frame->f_funcobj);
Py_CLEAR(frame->f_locals);
PyObject **locals = _PyFrame_GetLocalsArray(frame);
for (int i = 0; i < frame->stacktop; i++) {
@@ -1154,10 +1154,12 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) {
// COPY_FREE_VARS has no quickened forms, so no need to use _PyOpcode_Deopt
// here:
int lasti = _PyInterpreterFrame_LASTI(frame);
- if (lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS) {
+ if (lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS
+ && PyFunction_Check(frame->f_funcobj))
+ {
/* Free vars have not been initialized -- Do that */
PyCodeObject *co = frame->f_code;
- PyObject *closure = frame->f_func->func_closure;
+ PyObject *closure = ((PyFunctionObject *)frame->f_funcobj)->func_closure;
int offset = co->co_nlocals + co->co_nplaincellvars;
for (int i = 0; i < co->co_nfreevars; ++i) {
PyObject *o = PyTuple_GET_ITEM(closure, i);