summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-02-03 18:36:28 (GMT)
committerGitHub <noreply@github.com>2022-02-03 18:36:28 (GMT)
commitda4d4ec1851714bb56a5e8d0c1cd5bf9842b4cee (patch)
tree0a59b7362a584322ba0042f411b28555353b4a67 /Python
parent2d080347d74078a55c47715d232d1ab8dc8cd603 (diff)
downloadcpython-da4d4ec1851714bb56a5e8d0c1cd5bf9842b4cee.zip
cpython-da4d4ec1851714bb56a5e8d0c1cd5bf9842b4cee.tar.gz
cpython-da4d4ec1851714bb56a5e8d0c1cd5bf9842b4cee.tar.bz2
Pass reference to func, as well as args, when pushing frame. (GH-31100)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c10
-rw-r--r--Python/frame.c2
-rw-r--r--Python/pystate.c20
3 files changed, 7 insertions, 25 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 3c52c58..3197fe8 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2243,6 +2243,7 @@ handle_eval_breaker:
goto error;
}
CALL_STAT_INC(frames_pushed);
+ Py_INCREF(getitem);
_PyFrame_InitializeSpecials(new_frame, getitem,
NULL, code->co_nlocalsplus);
STACK_SHRINK(2);
@@ -4590,7 +4591,6 @@ handle_eval_breaker:
STACK_SHRINK(call_shape.postcall_shrink);
// The frame has stolen all the arguments from the stack,
// so there is no need to clean them up.
- Py_DECREF(function);
if (new_frame == NULL) {
goto error;
}
@@ -4675,7 +4675,6 @@ handle_eval_breaker:
new_frame->localsplus[i] = NULL;
}
STACK_SHRINK(call_shape.postcall_shrink);
- Py_DECREF(func);
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
frame = cframe.current_frame = new_frame;
@@ -4712,7 +4711,6 @@ handle_eval_breaker:
new_frame->localsplus[i] = NULL;
}
STACK_SHRINK(call_shape.postcall_shrink);
- Py_DECREF(func);
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
frame = cframe.current_frame = new_frame;
@@ -6077,7 +6075,7 @@ fail_post_args:
return -1;
}
-/* Consumes all the references to the args */
+/* Consumes references to func and all the args */
static InterpreterFrame *
_PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
PyObject *locals, PyObject* const* args,
@@ -6131,7 +6129,9 @@ _PyEval_Vector(PyThreadState *tstate, PyFunctionObject *func,
PyObject* const* args, size_t argcount,
PyObject *kwnames)
{
- /* _PyEvalFramePushAndInit consumes all the references to its arguments */
+ /* _PyEvalFramePushAndInit consumes the references
+ * to func and all its arguments */
+ Py_INCREF(func);
for (size_t i = 0; i < argcount; i++) {
Py_INCREF(args[i]);
}
diff --git a/Python/frame.c b/Python/frame.c
index ca7c5f9..76697cf 100644
--- a/Python/frame.c
+++ b/Python/frame.c
@@ -109,6 +109,7 @@ _PyFrame_Clear(InterpreterFrame *frame)
Py_DECREF(frame->f_code);
}
+/* Consumes reference to func */
InterpreterFrame *
_PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func)
{
@@ -117,6 +118,7 @@ _PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func)
CALL_STAT_INC(frames_pushed);
InterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size);
if (new_frame == NULL) {
+ Py_DECREF(func);
return NULL;
}
_PyFrame_InitializeSpecials(new_frame, func, NULL, code->co_nlocalsplus);
diff --git a/Python/pystate.c b/Python/pystate.c
index 7746794..a85460c 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -2212,26 +2212,6 @@ _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size)
return (InterpreterFrame *)base;
}
-
-InterpreterFrame *
-_PyThreadState_PushFrame(PyThreadState *tstate, PyFunctionObject *func, PyObject *locals)
-{
- PyCodeObject *code = (PyCodeObject *)func->func_code;
- int nlocalsplus = code->co_nlocalsplus;
- size_t size = nlocalsplus + code->co_stacksize +
- FRAME_SPECIALS_SIZE;
- CALL_STAT_INC(frames_pushed);
- InterpreterFrame *frame = _PyThreadState_BumpFramePointer(tstate, size);
- if (frame == NULL) {
- return NULL;
- }
- _PyFrame_InitializeSpecials(frame, func, locals, nlocalsplus);
- for (int i=0; i < nlocalsplus; i++) {
- frame->localsplus[i] = NULL;
- }
- return frame;
-}
-
void
_PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame * frame)
{