summaryrefslogtreecommitdiff
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-02-23 10:19:01 +0000
committerGitHub <noreply@github.com>2023-02-23 10:19:01 +0000
commit22b8d77b98a5944e688be0927b8139c49d4a7257 (patch)
treec3693ee3bc939140e9ad885677d58cab59673993 /Python/ceval.c
parent572223f9ce99e8816abdcc1536db6c4ceed2d848 (diff)
downloadcpython-git-22b8d77b98a5944e688be0927b8139c49d4a7257.tar.gz
GH-100719: Remove redundant `gi_code` field from generator object. (GH-100749)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 001bdb15c0..b382d2109b 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1604,41 +1604,6 @@ fail_post_args:
return -1;
}
-/* Consumes references to func, locals and all the args */
-static _PyInterpreterFrame *
-_PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
- PyObject *locals, PyObject* const* args,
- size_t argcount, PyObject *kwnames)
-{
- PyCodeObject * code = (PyCodeObject *)func->func_code;
- CALL_STAT_INC(frames_pushed);
- _PyInterpreterFrame *frame = _PyThreadState_PushFrame(tstate, code->co_framesize);
- if (frame == NULL) {
- goto fail;
- }
- _PyFrame_Initialize(frame, func, locals, code, 0);
- PyObject **localsarray = &frame->localsplus[0];
- if (initialize_locals(tstate, func, localsarray, args, argcount, kwnames)) {
- assert(frame->owner != FRAME_OWNED_BY_GENERATOR);
- _PyEvalFrameClearAndPop(tstate, frame);
- return NULL;
- }
- return frame;
-fail:
- /* Consume the references */
- for (size_t i = 0; i < argcount; i++) {
- Py_DECREF(args[i]);
- }
- if (kwnames) {
- Py_ssize_t kwcount = PyTuple_GET_SIZE(kwnames);
- for (Py_ssize_t i = 0; i < kwcount; i++) {
- Py_DECREF(args[i+argcount]);
- }
- }
- PyErr_NoMemory();
- return NULL;
-}
-
static void
clear_thread_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
{
@@ -1649,7 +1614,8 @@ clear_thread_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
tstate->datastack_top);
tstate->c_recursion_remaining--;
assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame);
- _PyFrame_Clear(frame);
+ _PyFrame_ClearExceptCode(frame);
+ Py_DECREF(frame->f_code);
tstate->c_recursion_remaining++;
_PyThreadState_PopFrame(tstate, frame);
}
@@ -1665,7 +1631,7 @@ clear_gen_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
gen->gi_exc_state.previous_item = NULL;
tstate->c_recursion_remaining--;
assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame);
- _PyFrame_Clear(frame);
+ _PyFrame_ClearExceptCode(frame);
tstate->c_recursion_remaining++;
frame->previous = NULL;
}
@@ -1681,6 +1647,39 @@ _PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame * frame)
}
}
+/* Consumes references to func, locals and all the args */
+static _PyInterpreterFrame *
+_PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
+ PyObject *locals, PyObject* const* args,
+ size_t argcount, PyObject *kwnames)
+{
+ PyCodeObject * code = (PyCodeObject *)func->func_code;
+ CALL_STAT_INC(frames_pushed);
+ _PyInterpreterFrame *frame = _PyThreadState_PushFrame(tstate, code->co_framesize);
+ if (frame == NULL) {
+ goto fail;
+ }
+ _PyFrame_Initialize(frame, func, locals, code, 0);
+ if (initialize_locals(tstate, func, frame->localsplus, args, argcount, kwnames)) {
+ assert(frame->owner == FRAME_OWNED_BY_THREAD);
+ clear_thread_frame(tstate, frame);
+ return NULL;
+ }
+ return frame;
+fail:
+ /* Consume the references */
+ for (size_t i = 0; i < argcount; i++) {
+ Py_DECREF(args[i]);
+ }
+ if (kwnames) {
+ Py_ssize_t kwcount = PyTuple_GET_SIZE(kwnames);
+ for (Py_ssize_t i = 0; i < kwcount; i++) {
+ Py_DECREF(args[i+argcount]);
+ }
+ }
+ PyErr_NoMemory();
+ return NULL;
+}
PyObject *
_PyEval_Vector(PyThreadState *tstate, PyFunctionObject *func,