From 49c51135a0471a829483d76a670e752e90914ae9 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Sat, 29 Jan 2022 04:30:27 +0000 Subject: [PATCH 1/5] do not create frame object for super --- Objects/typeobject.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 621ad9745d8448..798d0cfa96ea3b 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -9012,7 +9012,7 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type) } static int -super_init_without_args(PyFrameObject *f, PyCodeObject *co, +super_init_without_args(InterpreterFrame *cframe, PyCodeObject *co, PyTypeObject **type_p, PyObject **obj_p) { if (co->co_argcount == 0) { @@ -9021,13 +9021,13 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, return -1; } - assert(f->f_frame->f_code->co_nlocalsplus > 0); - PyObject *firstarg = _PyFrame_GetLocalsArray(f->f_frame)[0]; + assert(cframe->f_code->co_nlocalsplus > 0); + PyObject *firstarg = _PyFrame_GetLocalsArray(cframe)[0]; // The first argument might be a cell. if (firstarg != NULL && (_PyLocals_GetKind(co->co_localspluskinds, 0) & CO_FAST_CELL)) { // "firstarg" is a cell here unless (very unlikely) super() // 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(PyCell_Check(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); assert(PyUnicode_Check(name)); 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)) { PyErr_SetString(PyExc_RuntimeError, "super(): bad __class__ cell"); @@ -9096,17 +9096,14 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds) /* Call super(), without args -- fill in from __class__ and first local variable on the stack. */ PyThreadState *tstate = _PyThreadState_GET(); - PyFrameObject *frame = PyThreadState_GetFrame(tstate); - if (frame == NULL) { + InterpreterFrame *cframe = tstate->cframe->current_frame; + if (cframe == NULL) { PyErr_SetString(PyExc_RuntimeError, "super(): no current frame"); return -1; } - - PyCodeObject *code = PyFrame_GetCode(frame); - int res = super_init_without_args(frame, code, &type, &obj); - Py_DECREF(frame); - Py_DECREF(code); + PyCodeObject *code = cframe->f_code; + int res = super_init_without_args(cframe, code, &type, &obj); if (res < 0) { return -1; From 2573827d10224951902fbccdf3d33ef0cbbe1928 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 1 Feb 2022 10:23:21 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst new file mode 100644 index 00000000000000..a81b3c3420802a --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst @@ -0,0 +1 @@ +Do not create frame objects for creating :class:`super` object. \ No newline at end of file From 3c5de54459340536b85ff3bf1ab7232ca8f0947c Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Tue, 1 Feb 2022 15:55:36 +0530 Subject: [PATCH 3/5] style fix --- Objects/typeobject.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 798d0cfa96ea3b..f7e0775e2225b7 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -9102,8 +9102,7 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds) "super(): no current frame"); return -1; } - PyCodeObject *code = cframe->f_code; - int res = super_init_without_args(cframe, code, &type, &obj); + int res = super_init_without_args(cframe, cframe->f_code, &type, &obj); if (res < 0) { return -1; From a3bc1ab88f8dfd639cb5f5affefd49b7f4aa921c Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Tue, 1 Feb 2022 15:59:58 +0530 Subject: [PATCH 4/5] Update Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst --- .../Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst index a81b3c3420802a..c6fe513666e1fb 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst @@ -1 +1 @@ -Do not create frame objects for creating :class:`super` object. \ No newline at end of file +Do not create frame objects for creating :class:`super` object. Patch by Kumar Aditya. \ No newline at end of file From 03cc71a7df7b5a6581dc4f80e71b9d75afa10ea5 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Tue, 1 Feb 2022 20:58:55 +0800 Subject: [PATCH 5/5] Update news --- .../Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst index c6fe513666e1fb..4ffa6800989d75 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-01-10-23-21.bpo-46564.6Xc2_H.rst @@ -1 +1 @@ -Do not create frame objects for creating :class:`super` object. Patch by Kumar Aditya. \ No newline at end of file +Do not create frame objects when creating :class:`super` object. Patch by Kumar Aditya. \ No newline at end of file