From 7f61d9d84843e3445f62eb00c47902f0daa30a72 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Thu, 28 Oct 2021 16:14:59 +0100 Subject: bpo-45256: Rationalize code around Python-to-Python calls a bit. (GH-29235) --- Python/pystate.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index 114f91559d..a9ed08a7e3 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2065,12 +2065,8 @@ push_chunk(PyThreadState *tstate, int size) } InterpreterFrame * -_PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) +_PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size) { - PyCodeObject *code = (PyCodeObject *)con->fc_code; - int nlocalsplus = code->co_nlocalsplus; - size_t size = nlocalsplus + code->co_stacksize + - FRAME_SPECIALS_SIZE; assert(size < INT_MAX/sizeof(PyObject *)); PyObject **base = tstate->datastack_top; PyObject **top = base + size; @@ -2083,7 +2079,21 @@ _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObjec else { tstate->datastack_top = top; } - InterpreterFrame *frame = (InterpreterFrame *)base; + return (InterpreterFrame *)base; +} + + +InterpreterFrame * +_PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) +{ + PyCodeObject *code = (PyCodeObject *)con->fc_code; + int nlocalsplus = code->co_nlocalsplus; + size_t size = nlocalsplus + code->co_stacksize + + FRAME_SPECIALS_SIZE; + InterpreterFrame *frame = _PyThreadState_BumpFramePointer(tstate, size); + if (frame == NULL) { + return NULL; + } _PyFrame_InitializeSpecials(frame, con, locals, nlocalsplus); for (int i=0; i < nlocalsplus; i++) { frame->localsplus[i] = NULL; -- cgit v1.2.1