mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
bpo-46564: do not create frame object for super object (GH-31002)
This commit is contained in:
parent
108e66b6d2
commit
b9ebde8db7
2 changed files with 9 additions and 12 deletions
|
@ -0,0 +1 @@
|
||||||
|
Do not create frame objects when creating :class:`super` object. Patch by Kumar Aditya.
|
|
@ -9012,7 +9012,7 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
super_init_without_args(PyFrameObject *f, PyCodeObject *co,
|
super_init_without_args(InterpreterFrame *cframe, PyCodeObject *co,
|
||||||
PyTypeObject **type_p, PyObject **obj_p)
|
PyTypeObject **type_p, PyObject **obj_p)
|
||||||
{
|
{
|
||||||
if (co->co_argcount == 0) {
|
if (co->co_argcount == 0) {
|
||||||
|
@ -9021,13 +9021,13 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(f->f_frame->f_code->co_nlocalsplus > 0);
|
assert(cframe->f_code->co_nlocalsplus > 0);
|
||||||
PyObject *firstarg = _PyFrame_GetLocalsArray(f->f_frame)[0];
|
PyObject *firstarg = _PyFrame_GetLocalsArray(cframe)[0];
|
||||||
// The first argument might be a cell.
|
// The first argument might be a cell.
|
||||||
if (firstarg != NULL && (_PyLocals_GetKind(co->co_localspluskinds, 0) & CO_FAST_CELL)) {
|
if (firstarg != NULL && (_PyLocals_GetKind(co->co_localspluskinds, 0) & CO_FAST_CELL)) {
|
||||||
// "firstarg" is a cell here unless (very unlikely) super()
|
// "firstarg" is a cell here unless (very unlikely) super()
|
||||||
// was called from the C-API before the first MAKE_CELL op.
|
// was called from the C-API before the first MAKE_CELL op.
|
||||||
if (f->f_frame->f_lasti >= 0) {
|
if (cframe->f_lasti >= 0) {
|
||||||
assert(_Py_OPCODE(*co->co_firstinstr) == MAKE_CELL || _Py_OPCODE(*co->co_firstinstr) == COPY_FREE_VARS);
|
assert(_Py_OPCODE(*co->co_firstinstr) == MAKE_CELL || _Py_OPCODE(*co->co_firstinstr) == COPY_FREE_VARS);
|
||||||
assert(PyCell_Check(firstarg));
|
assert(PyCell_Check(firstarg));
|
||||||
firstarg = PyCell_GET(firstarg);
|
firstarg = PyCell_GET(firstarg);
|
||||||
|
@ -9047,7 +9047,7 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co,
|
||||||
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i);
|
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i);
|
||||||
assert(PyUnicode_Check(name));
|
assert(PyUnicode_Check(name));
|
||||||
if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) {
|
if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) {
|
||||||
PyObject *cell = _PyFrame_GetLocalsArray(f->f_frame)[i];
|
PyObject *cell = _PyFrame_GetLocalsArray(cframe)[i];
|
||||||
if (cell == NULL || !PyCell_Check(cell)) {
|
if (cell == NULL || !PyCell_Check(cell)) {
|
||||||
PyErr_SetString(PyExc_RuntimeError,
|
PyErr_SetString(PyExc_RuntimeError,
|
||||||
"super(): bad __class__ cell");
|
"super(): bad __class__ cell");
|
||||||
|
@ -9096,17 +9096,13 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
/* Call super(), without args -- fill in from __class__
|
/* Call super(), without args -- fill in from __class__
|
||||||
and first local variable on the stack. */
|
and first local variable on the stack. */
|
||||||
PyThreadState *tstate = _PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
PyFrameObject *frame = PyThreadState_GetFrame(tstate);
|
InterpreterFrame *cframe = tstate->cframe->current_frame;
|
||||||
if (frame == NULL) {
|
if (cframe == NULL) {
|
||||||
PyErr_SetString(PyExc_RuntimeError,
|
PyErr_SetString(PyExc_RuntimeError,
|
||||||
"super(): no current frame");
|
"super(): no current frame");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
int res = super_init_without_args(cframe, cframe->f_code, &type, &obj);
|
||||||
PyCodeObject *code = PyFrame_GetCode(frame);
|
|
||||||
int res = super_init_without_args(frame, code, &type, &obj);
|
|
||||||
Py_DECREF(frame);
|
|
||||||
Py_DECREF(code);
|
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue