bpo-44530: Add co_qualname field to PyCodeObject (GH-26941)

This commit is contained in:
Gabriele N. Tornetta 2021-07-07 12:21:51 +01:00 committed by GitHub
parent 32096df0e0
commit 2f180ce2cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 7457 additions and 7444 deletions

View file

@ -4161,13 +4161,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
}
case TARGET(MAKE_FUNCTION): {
PyObject *qualname = POP();
PyObject *codeobj = POP();
PyFunctionObject *func = (PyFunctionObject *)
PyFunction_NewWithQualName(codeobj, GLOBALS(), qualname);
PyFunction_New(codeobj, GLOBALS());
Py_DECREF(codeobj);
Py_DECREF(qualname);
if (func == NULL) {
goto error;
}

View file

@ -1195,7 +1195,7 @@ stack_effect(int opcode, int oparg, int jump)
case CALL_FUNCTION_EX:
return -1 - ((oparg & 0x01) != 0);
case MAKE_FUNCTION:
return -1 - ((oparg & 0x01) != 0) - ((oparg & 0x02) != 0) -
return 0 - ((oparg & 0x01) != 0) - ((oparg & 0x02) != 0) -
((oparg & 0x04) != 0) - ((oparg & 0x08) != 0);
case BUILD_SLICE:
if (oparg == 3)
@ -2138,7 +2138,6 @@ compiler_make_closure(struct compiler *c, PyCodeObject *co, Py_ssize_t flags,
ADDOP_I(c, BUILD_TUPLE, co->co_nfreevars);
}
ADDOP_LOAD_CONST(c, (PyObject*)co);
ADDOP_LOAD_CONST(c, qualname);
ADDOP_I(c, MAKE_FUNCTION, flags);
return 1;
}
@ -7389,7 +7388,6 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
PyObject *consts = NULL;
PyObject *localsplusnames = NULL;
PyObject *localspluskinds = NULL;
PyObject *name = NULL;
names = dict_keys_inorder(c->u->u_names, 0);
if (!names) {
@ -7433,6 +7431,7 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
struct _PyCodeConstructor con = {
.filename = c->c_filename,
.name = c->u->u_name,
.qualname = c->u->u_qualname ? c->u->u_qualname : c->u->u_name,
.flags = flags,
.code = a->a_bytecode,
@ -7475,7 +7474,6 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
Py_XDECREF(consts);
Py_XDECREF(localsplusnames);
Py_XDECREF(localspluskinds);
Py_XDECREF(name);
return co;
}

View file

@ -7,7 +7,8 @@ const unsigned char _Py_M__hello[] = {
105,110,105,116,105,97,108,105,122,101,100,218,5,112,114,105,
110,116,169,0,243,0,0,0,0,122,14,60,102,114,111,122,
101,110,32,104,101,108,108,111,62,218,8,60,109,111,100,117,
108,101,62,1,0,0,0,243,4,0,0,0,4,0,12,1,
114,4,0,0,0,115,16,0,0,0,15,19,1,12,1,6,
7,21,1,22,1,22,1,22,1,22,114,2,0,0,0,
108,101,62,114,3,0,0,0,1,0,0,0,243,4,0,0,
0,4,0,12,1,114,4,0,0,0,115,16,0,0,0,15,
19,1,12,1,6,7,21,1,22,1,22,1,22,1,22,114,
2,0,0,0,
};

5059
Python/importlib.h generated

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -522,6 +522,7 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
w_object(co->co_localspluskinds, p);
w_object(co->co_filename, p);
w_object(co->co_name, p);
w_object(co->co_qualname, p);
w_long(co->co_firstlineno, p);
w_object(co->co_linetable, p);
w_object(co->co_endlinetable, p);
@ -1315,6 +1316,7 @@ r_object(RFILE *p)
PyObject *localspluskinds = NULL;
PyObject *filename = NULL;
PyObject *name = NULL;
PyObject *qualname = NULL;
int firstlineno;
PyObject *linetable = NULL;
PyObject* endlinetable = NULL;
@ -1365,6 +1367,9 @@ r_object(RFILE *p)
name = r_object(p);
if (name == NULL)
goto code_error;
qualname = r_object(p);
if (qualname == NULL)
goto code_error;
firstlineno = (int)r_long(p);
if (firstlineno == -1 && PyErr_Occurred())
break;
@ -1384,6 +1389,7 @@ r_object(RFILE *p)
struct _PyCodeConstructor con = {
.filename = filename,
.name = name,
.qualname = qualname,
.flags = flags,
.code = code,
@ -1426,6 +1432,7 @@ r_object(RFILE *p)
Py_XDECREF(localspluskinds);
Py_XDECREF(filename);
Py_XDECREF(name);
Py_XDECREF(qualname);
Py_XDECREF(linetable);
Py_XDECREF(endlinetable);
Py_XDECREF(columntable);