-
-
Notifications
You must be signed in to change notification settings - Fork 32k
GH-100719: Remove redundant gi_code
field from generator object.
#100749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
24c9400
d68ce2c
3a9df11
d891db9
d81c042
f7e9c71
453f804
a3e6ac6
1357cf0
47858c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Remove gi_code field from generator (and coroutine and async generator) | ||
objects as it is redundant. The frame already includes a reference to the | ||
code object. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1604,41 +1604,6 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func, | |
return -1; | ||
} | ||
|
||
/* Consumes references to func, locals and all the args */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this moved downwards? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a small change, it now calls |
||
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, | ||
|
Uh oh!
There was an error while loading. Please reload this page.