mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Pass reference to func, as well as args, when pushing frame. (GH-31100)
This commit is contained in:
parent
2d080347d7
commit
da4d4ec185
5 changed files with 11 additions and 29 deletions
|
@ -87,12 +87,12 @@ static inline void _PyFrame_StackPush(InterpreterFrame *f, PyObject *value) {
|
||||||
|
|
||||||
void _PyFrame_Copy(InterpreterFrame *src, InterpreterFrame *dest);
|
void _PyFrame_Copy(InterpreterFrame *src, InterpreterFrame *dest);
|
||||||
|
|
||||||
|
/* Consumes reference to func */
|
||||||
static inline void
|
static inline void
|
||||||
_PyFrame_InitializeSpecials(
|
_PyFrame_InitializeSpecials(
|
||||||
InterpreterFrame *frame, PyFunctionObject *func,
|
InterpreterFrame *frame, PyFunctionObject *func,
|
||||||
PyObject *locals, int nlocalsplus)
|
PyObject *locals, int nlocalsplus)
|
||||||
{
|
{
|
||||||
Py_INCREF(func);
|
|
||||||
frame->f_func = func;
|
frame->f_func = func;
|
||||||
frame->f_code = (PyCodeObject *)Py_NewRef(func->func_code);
|
frame->f_code = (PyCodeObject *)Py_NewRef(func->func_code);
|
||||||
frame->f_builtins = func->func_builtins;
|
frame->f_builtins = func->func_builtins;
|
||||||
|
@ -166,9 +166,6 @@ _PyFrame_FastToLocalsWithError(InterpreterFrame *frame);
|
||||||
void
|
void
|
||||||
_PyFrame_LocalsToFast(InterpreterFrame *frame, int clear);
|
_PyFrame_LocalsToFast(InterpreterFrame *frame, int clear);
|
||||||
|
|
||||||
InterpreterFrame *_PyThreadState_PushFrame(
|
|
||||||
PyThreadState *tstate, PyFunctionObject *func, PyObject *locals);
|
|
||||||
|
|
||||||
extern InterpreterFrame *
|
extern InterpreterFrame *
|
||||||
_PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size);
|
_PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size);
|
||||||
|
|
||||||
|
@ -189,6 +186,7 @@ _PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size)
|
||||||
|
|
||||||
void _PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame *frame);
|
void _PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame *frame);
|
||||||
|
|
||||||
|
/* Consume reference to func */
|
||||||
InterpreterFrame *
|
InterpreterFrame *
|
||||||
_PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func);
|
_PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func);
|
||||||
|
|
||||||
|
|
|
@ -784,6 +784,8 @@ _Py_IDENTIFIER(__builtins__);
|
||||||
static void
|
static void
|
||||||
init_frame(InterpreterFrame *frame, PyFunctionObject *func, PyObject *locals)
|
init_frame(InterpreterFrame *frame, PyFunctionObject *func, PyObject *locals)
|
||||||
{
|
{
|
||||||
|
/* _PyFrame_InitializeSpecials consumes reference to func */
|
||||||
|
Py_INCREF(func);
|
||||||
PyCodeObject *code = (PyCodeObject *)func->func_code;
|
PyCodeObject *code = (PyCodeObject *)func->func_code;
|
||||||
_PyFrame_InitializeSpecials(frame, func, locals, code->co_nlocalsplus);
|
_PyFrame_InitializeSpecials(frame, func, locals, code->co_nlocalsplus);
|
||||||
for (Py_ssize_t i = 0; i < code->co_nlocalsplus; i++) {
|
for (Py_ssize_t i = 0; i < code->co_nlocalsplus; i++) {
|
||||||
|
|
|
@ -2243,6 +2243,7 @@ handle_eval_breaker:
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
CALL_STAT_INC(frames_pushed);
|
CALL_STAT_INC(frames_pushed);
|
||||||
|
Py_INCREF(getitem);
|
||||||
_PyFrame_InitializeSpecials(new_frame, getitem,
|
_PyFrame_InitializeSpecials(new_frame, getitem,
|
||||||
NULL, code->co_nlocalsplus);
|
NULL, code->co_nlocalsplus);
|
||||||
STACK_SHRINK(2);
|
STACK_SHRINK(2);
|
||||||
|
@ -4590,7 +4591,6 @@ handle_eval_breaker:
|
||||||
STACK_SHRINK(call_shape.postcall_shrink);
|
STACK_SHRINK(call_shape.postcall_shrink);
|
||||||
// The frame has stolen all the arguments from the stack,
|
// The frame has stolen all the arguments from the stack,
|
||||||
// so there is no need to clean them up.
|
// so there is no need to clean them up.
|
||||||
Py_DECREF(function);
|
|
||||||
if (new_frame == NULL) {
|
if (new_frame == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -4675,7 +4675,6 @@ handle_eval_breaker:
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
STACK_SHRINK(call_shape.postcall_shrink);
|
STACK_SHRINK(call_shape.postcall_shrink);
|
||||||
Py_DECREF(func);
|
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||||
new_frame->previous = frame;
|
new_frame->previous = frame;
|
||||||
frame = cframe.current_frame = new_frame;
|
frame = cframe.current_frame = new_frame;
|
||||||
|
@ -4712,7 +4711,6 @@ handle_eval_breaker:
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
STACK_SHRINK(call_shape.postcall_shrink);
|
STACK_SHRINK(call_shape.postcall_shrink);
|
||||||
Py_DECREF(func);
|
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||||
new_frame->previous = frame;
|
new_frame->previous = frame;
|
||||||
frame = cframe.current_frame = new_frame;
|
frame = cframe.current_frame = new_frame;
|
||||||
|
@ -6077,7 +6075,7 @@ fail_post_args:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Consumes all the references to the args */
|
/* Consumes references to func and all the args */
|
||||||
static InterpreterFrame *
|
static InterpreterFrame *
|
||||||
_PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
|
_PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
|
||||||
PyObject *locals, PyObject* const* args,
|
PyObject *locals, PyObject* const* args,
|
||||||
|
@ -6131,7 +6129,9 @@ _PyEval_Vector(PyThreadState *tstate, PyFunctionObject *func,
|
||||||
PyObject* const* args, size_t argcount,
|
PyObject* const* args, size_t argcount,
|
||||||
PyObject *kwnames)
|
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++) {
|
for (size_t i = 0; i < argcount; i++) {
|
||||||
Py_INCREF(args[i]);
|
Py_INCREF(args[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ _PyFrame_Clear(InterpreterFrame *frame)
|
||||||
Py_DECREF(frame->f_code);
|
Py_DECREF(frame->f_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Consumes reference to func */
|
||||||
InterpreterFrame *
|
InterpreterFrame *
|
||||||
_PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func)
|
_PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func)
|
||||||
{
|
{
|
||||||
|
@ -117,6 +118,7 @@ _PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func)
|
||||||
CALL_STAT_INC(frames_pushed);
|
CALL_STAT_INC(frames_pushed);
|
||||||
InterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size);
|
InterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size);
|
||||||
if (new_frame == NULL) {
|
if (new_frame == NULL) {
|
||||||
|
Py_DECREF(func);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
_PyFrame_InitializeSpecials(new_frame, func, NULL, code->co_nlocalsplus);
|
_PyFrame_InitializeSpecials(new_frame, func, NULL, code->co_nlocalsplus);
|
||||||
|
|
|
@ -2212,26 +2212,6 @@ _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size)
|
||||||
return (InterpreterFrame *)base;
|
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
|
void
|
||||||
_PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame * frame)
|
_PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame * frame)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue