Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9ebde8

Browse files
bpo-46564: do not create frame object for super object (GH-31002)
1 parent 108e66b commit b9ebde8

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not create frame objects when creating :class:`super` object. Patch by Kumar Aditya.

Objects/typeobject.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9012,7 +9012,7 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
90129012
}
90139013

90149014
static int
9015-
super_init_without_args(PyFrameObject *f, PyCodeObject *co,
9015+
super_init_without_args(InterpreterFrame *cframe, PyCodeObject *co,
90169016
PyTypeObject **type_p, PyObject **obj_p)
90179017
{
90189018
if (co->co_argcount == 0) {
@@ -9021,13 +9021,13 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co,
90219021
return -1;
90229022
}
90239023

9024-
assert(f->f_frame->f_code->co_nlocalsplus > 0);
9025-
PyObject *firstarg = _PyFrame_GetLocalsArray(f->f_frame)[0];
9024+
assert(cframe->f_code->co_nlocalsplus > 0);
9025+
PyObject *firstarg = _PyFrame_GetLocalsArray(cframe)[0];
90269026
// The first argument might be a cell.
90279027
if (firstarg != NULL && (_PyLocals_GetKind(co->co_localspluskinds, 0) & CO_FAST_CELL)) {
90289028
// "firstarg" is a cell here unless (very unlikely) super()
90299029
// was called from the C-API before the first MAKE_CELL op.
9030-
if (f->f_frame->f_lasti >= 0) {
9030+
if (cframe->f_lasti >= 0) {
90319031
assert(_Py_OPCODE(*co->co_firstinstr) == MAKE_CELL || _Py_OPCODE(*co->co_firstinstr) == COPY_FREE_VARS);
90329032
assert(PyCell_Check(firstarg));
90339033
firstarg = PyCell_GET(firstarg);
@@ -9047,7 +9047,7 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co,
90479047
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i);
90489048
assert(PyUnicode_Check(name));
90499049
if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) {
9050-
PyObject *cell = _PyFrame_GetLocalsArray(f->f_frame)[i];
9050+
PyObject *cell = _PyFrame_GetLocalsArray(cframe)[i];
90519051
if (cell == NULL || !PyCell_Check(cell)) {
90529052
PyErr_SetString(PyExc_RuntimeError,
90539053
"super(): bad __class__ cell");
@@ -9096,17 +9096,13 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
90969096
/* Call super(), without args -- fill in from __class__
90979097
and first local variable on the stack. */
90989098
PyThreadState *tstate = _PyThreadState_GET();
9099-
PyFrameObject *frame = PyThreadState_GetFrame(tstate);
9100-
if (frame == NULL) {
9099+
InterpreterFrame *cframe = tstate->cframe->current_frame;
9100+
if (cframe == NULL) {
91019101
PyErr_SetString(PyExc_RuntimeError,
91029102
"super(): no current frame");
91039103
return -1;
91049104
}
9105-
9106-
PyCodeObject *code = PyFrame_GetCode(frame);
9107-
int res = super_init_without_args(frame, code, &type, &obj);
9108-
Py_DECREF(frame);
9109-
Py_DECREF(code);
9105+
int res = super_init_without_args(cframe, cframe->f_code, &type, &obj);
91109106

91119107
if (res < 0) {
91129108
return -1;

0 commit comments

Comments
 (0)