Skip to content

Commit 65219b2

Browse files
authored
Merge pull request #17 from markshannon/simple_cframe
Tweaks
2 parents 9210541 + 9a0ceab commit 65219b2

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

Python/ceval.c

+7-23
Original file line numberDiff line numberDiff line change
@@ -1523,24 +1523,6 @@ trace_function_entry(PyThreadState *tstate, InterpreterFrame *frame)
15231523
return 0;
15241524
}
15251525

1526-
/* Create a frame structure from a python function stealing ownership from an array of arguments.
1527-
* In case of error, it returns NULL and the caller still owns the references to all arguments */
1528-
static InterpreterFrame*
1529-
_PyEval_FrameFromPyFunctionAndArgs(PyThreadState *tstate, PyObject* const *args, int nargs, PyObject *function) {
1530-
assert(PyFunction_Check(function));
1531-
size_t nargsf = nargs | PY_VECTORCALL_ARGUMENTS_OFFSET;
1532-
assert(args != NULL || PyVectorcall_NARGS(nargsf) == 0);
1533-
assert(PyVectorcall_Function(function) == _PyFunction_Vectorcall);
1534-
PyFrameConstructor *con = PyFunction_AS_FRAME_CONSTRUCTOR(function);
1535-
Py_ssize_t vector_nargs = PyVectorcall_NARGS(nargsf);
1536-
assert(vector_nargs >= 0);
1537-
assert(vector_nargs == 0 || args != NULL);
1538-
PyCodeObject *code = (PyCodeObject *)con->fc_code;
1539-
PyObject *locals = (code->co_flags & CO_OPTIMIZED) ? NULL : con->fc_globals;
1540-
assert(!(code->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)));
1541-
return _PyEvalFramePushAndInit(tstate, con, locals, args, vector_nargs, NULL, 1);
1542-
}
1543-
15441526
static PyObject *
15451527
make_coro(PyThreadState *tstate, PyFrameConstructor *con,
15461528
PyObject *locals,
@@ -4645,14 +4627,16 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
46454627
PyObject *function = PEEK(oparg + 1);
46464628
if (Py_TYPE(function) == &PyFunction_Type) {
46474629
PyCodeObject *code = (PyCodeObject*)PyFunction_GET_CODE(function);
4648-
STACK_SHRINK(oparg + 1);
4630+
PyObject *locals = code->co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function);
46494631
if ((code->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) == 0) {
4650-
InterpreterFrame *new_frame = _PyEval_FrameFromPyFunctionAndArgs(tstate, stack_pointer+1, oparg, function);
4632+
InterpreterFrame *new_frame = _PyEvalFramePushAndInit(
4633+
tstate, PyFunction_AS_FRAME_CONSTRUCTOR(function), locals, stack_pointer-oparg, oparg, NULL, 1);
46514634
if (new_frame == NULL) {
46524635
// When we exit here, we own all variables in the stack (the frame creation has not stolen
46534636
// any variable) so we need to clean the whole stack (done in the "error" label).
46544637
goto error;
46554638
}
4639+
STACK_SHRINK(oparg + 1);
46564640
assert(tstate->interp->eval_frame != NULL);
46574641
// The frame has stolen all the arguments from the stack, so there is no need to clean them up.```
46584642
Py_DECREF(function);
@@ -4663,9 +4647,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
46634647
}
46644648
else {
46654649
/* Callable is a generator or coroutine function: create coroutine or generator. */
4666-
PyObject *locals = code->co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function);
4667-
res = make_coro(tstate, PyFunction_AS_FRAME_CONSTRUCTOR(function), locals, stack_pointer+1, oparg, NULL);
4668-
for (int i = 0; i < oparg+1; i++) {
4650+
res = make_coro(tstate, PyFunction_AS_FRAME_CONSTRUCTOR(function), locals, stack_pointer-oparg, oparg, NULL);
4651+
STACK_SHRINK(oparg + 1);
4652+
for (int i = 0; i < oparg + 1; i++) {
46694653
Py_DECREF(stack_pointer[i]);
46704654
}
46714655
}

0 commit comments

Comments
 (0)