mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
bpo-44530: Add co_qualname field to PyCodeObject (GH-26941)
This commit is contained in:
parent
32096df0e0
commit
2f180ce2cb
20 changed files with 7457 additions and 7444 deletions
105
Objects/clinic/codeobject.c.h
generated
105
Objects/clinic/codeobject.c.h
generated
|
|
@ -5,8 +5,8 @@ preserve
|
|||
PyDoc_STRVAR(code_new__doc__,
|
||||
"code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n"
|
||||
" flags, codestring, constants, names, varnames, filename, name,\n"
|
||||
" firstlineno, linetable, endlinetable, columntable, exceptiontable,\n"
|
||||
" freevars=(), cellvars=(), /)\n"
|
||||
" qualname, firstlineno, linetable, endlinetable, columntable,\n"
|
||||
" exceptiontable, freevars=(), cellvars=(), /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Create a code object. Not for the faint of heart.");
|
||||
|
|
@ -16,9 +16,10 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
|
|||
int kwonlyargcount, int nlocals, int stacksize, int flags,
|
||||
PyObject *code, PyObject *consts, PyObject *names,
|
||||
PyObject *varnames, PyObject *filename, PyObject *name,
|
||||
int firstlineno, PyObject *linetable, PyObject *endlinetable,
|
||||
PyObject *columntable, PyObject *exceptiontable,
|
||||
PyObject *freevars, PyObject *cellvars);
|
||||
PyObject *qualname, int firstlineno, PyObject *linetable,
|
||||
PyObject *endlinetable, PyObject *columntable,
|
||||
PyObject *exceptiontable, PyObject *freevars,
|
||||
PyObject *cellvars);
|
||||
|
||||
static PyObject *
|
||||
code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||
|
|
@ -36,6 +37,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
PyObject *varnames;
|
||||
PyObject *filename;
|
||||
PyObject *name;
|
||||
PyObject *qualname;
|
||||
int firstlineno;
|
||||
PyObject *linetable;
|
||||
PyObject *endlinetable;
|
||||
|
|
@ -48,7 +50,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
!_PyArg_NoKeywords("code", kwargs)) {
|
||||
goto exit;
|
||||
}
|
||||
if (!_PyArg_CheckPositional("code", PyTuple_GET_SIZE(args), 17, 19)) {
|
||||
if (!_PyArg_CheckPositional("code", PyTuple_GET_SIZE(args), 18, 20)) {
|
||||
goto exit;
|
||||
}
|
||||
argcount = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
|
||||
|
|
@ -111,38 +113,38 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
goto exit;
|
||||
}
|
||||
name = PyTuple_GET_ITEM(args, 11);
|
||||
firstlineno = _PyLong_AsInt(PyTuple_GET_ITEM(args, 12));
|
||||
if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 12))) {
|
||||
_PyArg_BadArgument("code", "argument 13", "str", PyTuple_GET_ITEM(args, 12));
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(PyTuple_GET_ITEM(args, 12)) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
qualname = PyTuple_GET_ITEM(args, 12);
|
||||
firstlineno = _PyLong_AsInt(PyTuple_GET_ITEM(args, 13));
|
||||
if (firstlineno == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 13))) {
|
||||
_PyArg_BadArgument("code", "argument 14", "bytes", PyTuple_GET_ITEM(args, 13));
|
||||
goto exit;
|
||||
}
|
||||
linetable = PyTuple_GET_ITEM(args, 13);
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 14))) {
|
||||
_PyArg_BadArgument("code", "argument 15", "bytes", PyTuple_GET_ITEM(args, 14));
|
||||
goto exit;
|
||||
}
|
||||
endlinetable = PyTuple_GET_ITEM(args, 14);
|
||||
linetable = PyTuple_GET_ITEM(args, 14);
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 15))) {
|
||||
_PyArg_BadArgument("code", "argument 16", "bytes", PyTuple_GET_ITEM(args, 15));
|
||||
goto exit;
|
||||
}
|
||||
columntable = PyTuple_GET_ITEM(args, 15);
|
||||
endlinetable = PyTuple_GET_ITEM(args, 15);
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 16))) {
|
||||
_PyArg_BadArgument("code", "argument 17", "bytes", PyTuple_GET_ITEM(args, 16));
|
||||
goto exit;
|
||||
}
|
||||
exceptiontable = PyTuple_GET_ITEM(args, 16);
|
||||
if (PyTuple_GET_SIZE(args) < 18) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 17))) {
|
||||
_PyArg_BadArgument("code", "argument 18", "tuple", PyTuple_GET_ITEM(args, 17));
|
||||
columntable = PyTuple_GET_ITEM(args, 16);
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 17))) {
|
||||
_PyArg_BadArgument("code", "argument 18", "bytes", PyTuple_GET_ITEM(args, 17));
|
||||
goto exit;
|
||||
}
|
||||
freevars = PyTuple_GET_ITEM(args, 17);
|
||||
exceptiontable = PyTuple_GET_ITEM(args, 17);
|
||||
if (PyTuple_GET_SIZE(args) < 19) {
|
||||
goto skip_optional;
|
||||
}
|
||||
|
|
@ -150,9 +152,17 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
_PyArg_BadArgument("code", "argument 19", "tuple", PyTuple_GET_ITEM(args, 18));
|
||||
goto exit;
|
||||
}
|
||||
cellvars = PyTuple_GET_ITEM(args, 18);
|
||||
freevars = PyTuple_GET_ITEM(args, 18);
|
||||
if (PyTuple_GET_SIZE(args) < 20) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 19))) {
|
||||
_PyArg_BadArgument("code", "argument 20", "tuple", PyTuple_GET_ITEM(args, 19));
|
||||
goto exit;
|
||||
}
|
||||
cellvars = PyTuple_GET_ITEM(args, 19);
|
||||
skip_optional:
|
||||
return_value = code_new_impl(type, argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize, flags, code, consts, names, varnames, filename, name, firstlineno, linetable, endlinetable, columntable, exceptiontable, freevars, cellvars);
|
||||
return_value = code_new_impl(type, argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize, flags, code, consts, names, varnames, filename, name, qualname, firstlineno, linetable, endlinetable, columntable, exceptiontable, freevars, cellvars);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
|
|
@ -164,8 +174,8 @@ PyDoc_STRVAR(code_replace__doc__,
|
|||
" co_flags=-1, co_firstlineno=-1, co_code=None, co_consts=None,\n"
|
||||
" co_names=None, co_varnames=None, co_freevars=None,\n"
|
||||
" co_cellvars=None, co_filename=None, co_name=None,\n"
|
||||
" co_linetable=None, co_endlinetable=None, co_columntable=None,\n"
|
||||
" co_exceptiontable=None)\n"
|
||||
" co_qualname=None, co_linetable=None, co_endlinetable=None,\n"
|
||||
" co_columntable=None, co_exceptiontable=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a copy of the code object with new values for the specified fields.");
|
||||
|
|
@ -181,7 +191,8 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
|
|||
PyObject *co_consts, PyObject *co_names,
|
||||
PyObject *co_varnames, PyObject *co_freevars,
|
||||
PyObject *co_cellvars, PyObject *co_filename,
|
||||
PyObject *co_name, PyBytesObject *co_linetable,
|
||||
PyObject *co_name, PyObject *co_qualname,
|
||||
PyBytesObject *co_linetable,
|
||||
PyBytesObject *co_endlinetable,
|
||||
PyBytesObject *co_columntable,
|
||||
PyBytesObject *co_exceptiontable);
|
||||
|
|
@ -190,9 +201,9 @@ static PyObject *
|
|||
code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
static const char * const _keywords[] = {"co_argcount", "co_posonlyargcount", "co_kwonlyargcount", "co_nlocals", "co_stacksize", "co_flags", "co_firstlineno", "co_code", "co_consts", "co_names", "co_varnames", "co_freevars", "co_cellvars", "co_filename", "co_name", "co_linetable", "co_endlinetable", "co_columntable", "co_exceptiontable", NULL};
|
||||
static const char * const _keywords[] = {"co_argcount", "co_posonlyargcount", "co_kwonlyargcount", "co_nlocals", "co_stacksize", "co_flags", "co_firstlineno", "co_code", "co_consts", "co_names", "co_varnames", "co_freevars", "co_cellvars", "co_filename", "co_name", "co_qualname", "co_linetable", "co_endlinetable", "co_columntable", "co_exceptiontable", NULL};
|
||||
static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0};
|
||||
PyObject *argsbuf[19];
|
||||
PyObject *argsbuf[20];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
int co_argcount = self->co_argcount;
|
||||
int co_posonlyargcount = self->co_posonlyargcount;
|
||||
|
|
@ -209,6 +220,7 @@ code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje
|
|||
PyObject *co_cellvars = self->co_cellvars;
|
||||
PyObject *co_filename = self->co_filename;
|
||||
PyObject *co_name = self->co_name;
|
||||
PyObject *co_qualname = self->co_qualname;
|
||||
PyBytesObject *co_linetable = (PyBytesObject *)self->co_linetable;
|
||||
PyBytesObject *co_endlinetable = (PyBytesObject *)self->co_endlinetable;
|
||||
PyBytesObject *co_columntable = (PyBytesObject *)self->co_columntable;
|
||||
|
|
@ -371,42 +383,55 @@ code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje
|
|||
}
|
||||
}
|
||||
if (args[15]) {
|
||||
if (!PyBytes_Check(args[15])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_linetable'", "bytes", args[15]);
|
||||
if (!PyUnicode_Check(args[15])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_qualname'", "str", args[15]);
|
||||
goto exit;
|
||||
}
|
||||
co_linetable = (PyBytesObject *)args[15];
|
||||
if (PyUnicode_READY(args[15]) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
co_qualname = args[15];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (args[16]) {
|
||||
if (!PyBytes_Check(args[16])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_endlinetable'", "bytes", args[16]);
|
||||
_PyArg_BadArgument("replace", "argument 'co_linetable'", "bytes", args[16]);
|
||||
goto exit;
|
||||
}
|
||||
co_endlinetable = (PyBytesObject *)args[16];
|
||||
co_linetable = (PyBytesObject *)args[16];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (args[17]) {
|
||||
if (!PyBytes_Check(args[17])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_columntable'", "bytes", args[17]);
|
||||
_PyArg_BadArgument("replace", "argument 'co_endlinetable'", "bytes", args[17]);
|
||||
goto exit;
|
||||
}
|
||||
co_columntable = (PyBytesObject *)args[17];
|
||||
co_endlinetable = (PyBytesObject *)args[17];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (!PyBytes_Check(args[18])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_exceptiontable'", "bytes", args[18]);
|
||||
if (args[18]) {
|
||||
if (!PyBytes_Check(args[18])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_columntable'", "bytes", args[18]);
|
||||
goto exit;
|
||||
}
|
||||
co_columntable = (PyBytesObject *)args[18];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (!PyBytes_Check(args[19])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_exceptiontable'", "bytes", args[19]);
|
||||
goto exit;
|
||||
}
|
||||
co_exceptiontable = (PyBytesObject *)args[18];
|
||||
co_exceptiontable = (PyBytesObject *)args[19];
|
||||
skip_optional_kwonly:
|
||||
return_value = code_replace_impl(self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_linetable, co_endlinetable, co_columntable, co_exceptiontable);
|
||||
return_value = code_replace_impl(self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_qualname, co_linetable, co_endlinetable, co_columntable, co_exceptiontable);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
|
|
@ -448,4 +473,4 @@ code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t n
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=a75c9ca013d9bf7d input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=12b394f0212b1c1e input=a9049054013a1b77]*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue