Skip to content

Commit bdb12a7

Browse files
Add a light-weight check to super_init_without_args().
1 parent 8693744 commit bdb12a7

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Objects/typeobject.c

+7-10
Original file line numberDiff line numberDiff line change
@@ -8880,16 +8880,13 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co,
88808880
PyObject *firstarg = f->f_localsptr[0];
88818881
// The first argument might be a cell.
88828882
if (firstarg != NULL && (co->co_localspluskinds[0] & CO_FAST_CELL)) {
8883-
// The only way firstarg is not a cell is if MAKE_CELL hasn't
8884-
// run yet, which isn't possible from Python code since "super()"
8885-
// will always come after MAKE_CELL. So the only way firstarg
8886-
// isn't a cell is if super() were called via the C-API, and
8887-
// execution is at the very beginning of the function. This is
8888-
// sufficiently unlikely that we disllow it. Otherwise we'd
8889-
// incur the expense of checking to make sure MAKE_CELL ran
8890-
// already, like we do in PyFrame_FastToLocals().
8891-
assert(PyCell_Check(firstarg));
8892-
firstarg = PyCell_GET(firstarg);
8883+
// "firstarg" is a cell here unless (very unlikely) super()
8884+
// was called from the C-API before the first MAKE_CELL op.
8885+
if (f->f_lasti >= 0) {
8886+
assert(_Py_OPCODE(*co->co_firstinstr) == MAKE_CELL);
8887+
assert(PyCell_Check(firstarg));
8888+
firstarg = PyCell_GET(firstarg);
8889+
}
88938890
}
88948891
if (firstarg == NULL) {
88958892
PyErr_SetString(PyExc_RuntimeError,

0 commit comments

Comments
 (0)