2019-05-24 18:57:23 -03:00
|
|
|
/*[clinic input]
|
|
|
|
preserve
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
2022-08-11 18:25:49 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2023-08-31 18:42:34 -03:00
|
|
|
# include "pycore_gc.h" // PyGC_Head
|
|
|
|
# include "pycore_runtime.h" // _Py_ID()
|
2022-08-11 18:25:49 -03:00
|
|
|
#endif
|
2023-10-17 09:30:31 -03:00
|
|
|
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2020-07-10 04:12:04 -03:00
|
|
|
PyDoc_STRVAR(code_new__doc__,
|
|
|
|
"code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n"
|
|
|
|
" flags, codestring, constants, names, varnames, filename, name,\n"
|
2022-04-21 12:10:37 -03:00
|
|
|
" qualname, firstlineno, linetable, exceptiontable, freevars=(),\n"
|
|
|
|
" cellvars=(), /)\n"
|
2020-07-10 04:12:04 -03:00
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Create a code object. Not for the faint of heart.");
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
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,
|
2021-07-07 08:21:51 -03:00
|
|
|
PyObject *qualname, int firstlineno, PyObject *linetable,
|
|
|
|
PyObject *exceptiontable, PyObject *freevars,
|
|
|
|
PyObject *cellvars);
|
2020-07-10 04:12:04 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2023-01-31 16:42:03 -04:00
|
|
|
PyTypeObject *base_tp = &PyCode_Type;
|
2020-07-10 04:12:04 -03:00
|
|
|
int argcount;
|
|
|
|
int posonlyargcount;
|
|
|
|
int kwonlyargcount;
|
|
|
|
int nlocals;
|
|
|
|
int stacksize;
|
|
|
|
int flags;
|
|
|
|
PyObject *code;
|
|
|
|
PyObject *consts;
|
|
|
|
PyObject *names;
|
|
|
|
PyObject *varnames;
|
|
|
|
PyObject *filename;
|
|
|
|
PyObject *name;
|
2021-07-07 08:21:51 -03:00
|
|
|
PyObject *qualname;
|
2020-07-10 04:12:04 -03:00
|
|
|
int firstlineno;
|
2020-11-12 05:43:29 -04:00
|
|
|
PyObject *linetable;
|
2021-05-07 11:19:19 -03:00
|
|
|
PyObject *exceptiontable;
|
2020-07-10 04:12:04 -03:00
|
|
|
PyObject *freevars = NULL;
|
|
|
|
PyObject *cellvars = NULL;
|
|
|
|
|
2023-01-31 16:42:03 -04:00
|
|
|
if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
|
2020-07-10 04:12:04 -03:00
|
|
|
!_PyArg_NoKeywords("code", kwargs)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2022-04-21 12:10:37 -03:00
|
|
|
if (!_PyArg_CheckPositional("code", PyTuple_GET_SIZE(args), 16, 18)) {
|
2020-07-10 04:12:04 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-24 19:51:22 -03:00
|
|
|
argcount = PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
|
2020-07-10 04:12:04 -03:00
|
|
|
if (argcount == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-24 19:51:22 -03:00
|
|
|
posonlyargcount = PyLong_AsInt(PyTuple_GET_ITEM(args, 1));
|
2020-07-10 04:12:04 -03:00
|
|
|
if (posonlyargcount == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-24 19:51:22 -03:00
|
|
|
kwonlyargcount = PyLong_AsInt(PyTuple_GET_ITEM(args, 2));
|
2020-07-10 04:12:04 -03:00
|
|
|
if (kwonlyargcount == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-24 19:51:22 -03:00
|
|
|
nlocals = PyLong_AsInt(PyTuple_GET_ITEM(args, 3));
|
2020-07-10 04:12:04 -03:00
|
|
|
if (nlocals == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-24 19:51:22 -03:00
|
|
|
stacksize = PyLong_AsInt(PyTuple_GET_ITEM(args, 4));
|
2020-07-10 04:12:04 -03:00
|
|
|
if (stacksize == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-24 19:51:22 -03:00
|
|
|
flags = PyLong_AsInt(PyTuple_GET_ITEM(args, 5));
|
2020-07-10 04:12:04 -03:00
|
|
|
if (flags == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 6))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 7", "bytes", PyTuple_GET_ITEM(args, 6));
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
code = PyTuple_GET_ITEM(args, 6);
|
|
|
|
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 7))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 8", "tuple", PyTuple_GET_ITEM(args, 7));
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
consts = PyTuple_GET_ITEM(args, 7);
|
|
|
|
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 8))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 9", "tuple", PyTuple_GET_ITEM(args, 8));
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
names = PyTuple_GET_ITEM(args, 8);
|
|
|
|
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 9))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 10", "tuple", PyTuple_GET_ITEM(args, 9));
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
varnames = PyTuple_GET_ITEM(args, 9);
|
|
|
|
if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 10))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 11", "str", PyTuple_GET_ITEM(args, 10));
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
filename = PyTuple_GET_ITEM(args, 10);
|
|
|
|
if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 11))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 12", "str", PyTuple_GET_ITEM(args, 11));
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
name = PyTuple_GET_ITEM(args, 11);
|
2021-07-07 08:21:51 -03:00
|
|
|
if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 12))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 13", "str", PyTuple_GET_ITEM(args, 12));
|
2020-07-10 04:12:04 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2021-07-07 08:21:51 -03:00
|
|
|
qualname = PyTuple_GET_ITEM(args, 12);
|
2023-08-24 19:51:22 -03:00
|
|
|
firstlineno = PyLong_AsInt(PyTuple_GET_ITEM(args, 13));
|
2021-07-07 08:21:51 -03:00
|
|
|
if (firstlineno == -1 && PyErr_Occurred()) {
|
2020-07-10 04:12:04 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2021-05-07 11:19:19 -03:00
|
|
|
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 14))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 15", "bytes", PyTuple_GET_ITEM(args, 14));
|
2020-07-10 04:12:04 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2021-07-07 08:21:51 -03:00
|
|
|
linetable = PyTuple_GET_ITEM(args, 14);
|
2022-04-21 12:10:37 -03:00
|
|
|
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 15))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 16", "bytes", PyTuple_GET_ITEM(args, 15));
|
2020-07-10 04:12:04 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2022-04-21 12:10:37 -03:00
|
|
|
exceptiontable = PyTuple_GET_ITEM(args, 15);
|
|
|
|
if (PyTuple_GET_SIZE(args) < 17) {
|
2021-05-07 11:19:19 -03:00
|
|
|
goto skip_optional;
|
|
|
|
}
|
2022-04-21 12:10:37 -03:00
|
|
|
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 16))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 17", "tuple", PyTuple_GET_ITEM(args, 16));
|
2021-05-07 11:19:19 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2022-04-21 12:10:37 -03:00
|
|
|
freevars = PyTuple_GET_ITEM(args, 16);
|
|
|
|
if (PyTuple_GET_SIZE(args) < 18) {
|
2021-07-07 08:21:51 -03:00
|
|
|
goto skip_optional;
|
|
|
|
}
|
2022-04-21 12:10:37 -03:00
|
|
|
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 17))) {
|
|
|
|
_PyArg_BadArgument("code", "argument 18", "tuple", PyTuple_GET_ITEM(args, 17));
|
2021-07-07 08:21:51 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2022-04-21 12:10:37 -03:00
|
|
|
cellvars = PyTuple_GET_ITEM(args, 17);
|
2020-07-10 04:12:04 -03:00
|
|
|
skip_optional:
|
2022-04-21 12:10:37 -03:00
|
|
|
return_value = code_new_impl(type, argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize, flags, code, consts, names, varnames, filename, name, qualname, firstlineno, linetable, exceptiontable, freevars, cellvars);
|
2020-07-10 04:12:04 -03:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2019-05-24 18:57:23 -03:00
|
|
|
PyDoc_STRVAR(code_replace__doc__,
|
2023-08-07 17:34:53 -03:00
|
|
|
"replace($self, /, **changes)\n"
|
2019-05-24 18:57:23 -03:00
|
|
|
"--\n"
|
|
|
|
"\n"
|
2020-01-01 02:11:16 -04:00
|
|
|
"Return a copy of the code object with new values for the specified fields.");
|
2019-05-24 18:57:23 -03:00
|
|
|
|
|
|
|
#define CODE_REPLACE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"replace", _PyCFunction_CAST(code_replace), METH_FASTCALL|METH_KEYWORDS, code_replace__doc__},
|
2019-05-24 18:57:23 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
code_replace_impl(PyCodeObject *self, int co_argcount,
|
|
|
|
int co_posonlyargcount, int co_kwonlyargcount,
|
|
|
|
int co_nlocals, int co_stacksize, int co_flags,
|
2023-08-07 17:34:53 -03:00
|
|
|
int co_firstlineno, PyObject *co_code, PyObject *co_consts,
|
|
|
|
PyObject *co_names, PyObject *co_varnames,
|
|
|
|
PyObject *co_freevars, PyObject *co_cellvars,
|
|
|
|
PyObject *co_filename, PyObject *co_name,
|
|
|
|
PyObject *co_qualname, PyObject *co_linetable,
|
|
|
|
PyObject *co_exceptiontable);
|
2019-05-24 18:57:23 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 18
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(co_argcount), &_Py_ID(co_posonlyargcount), &_Py_ID(co_kwonlyargcount), &_Py_ID(co_nlocals), &_Py_ID(co_stacksize), &_Py_ID(co_flags), &_Py_ID(co_firstlineno), &_Py_ID(co_code), &_Py_ID(co_consts), &_Py_ID(co_names), &_Py_ID(co_varnames), &_Py_ID(co_freevars), &_Py_ID(co_cellvars), &_Py_ID(co_filename), &_Py_ID(co_name), &_Py_ID(co_qualname), &_Py_ID(co_linetable), &_Py_ID(co_exceptiontable), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-04-21 12:10:37 -03:00
|
|
|
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_exceptiontable", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "replace",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2022-04-21 12:10:37 -03:00
|
|
|
PyObject *argsbuf[18];
|
2019-05-24 18:57:23 -03:00
|
|
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
|
|
|
int co_argcount = self->co_argcount;
|
|
|
|
int co_posonlyargcount = self->co_posonlyargcount;
|
|
|
|
int co_kwonlyargcount = self->co_kwonlyargcount;
|
|
|
|
int co_nlocals = self->co_nlocals;
|
|
|
|
int co_stacksize = self->co_stacksize;
|
|
|
|
int co_flags = self->co_flags;
|
|
|
|
int co_firstlineno = self->co_firstlineno;
|
2023-08-07 17:34:53 -03:00
|
|
|
PyObject *co_code = NULL;
|
2019-05-24 18:57:23 -03:00
|
|
|
PyObject *co_consts = self->co_consts;
|
|
|
|
PyObject *co_names = self->co_names;
|
2022-03-21 08:11:17 -03:00
|
|
|
PyObject *co_varnames = NULL;
|
|
|
|
PyObject *co_freevars = NULL;
|
|
|
|
PyObject *co_cellvars = NULL;
|
2019-05-24 18:57:23 -03:00
|
|
|
PyObject *co_filename = self->co_filename;
|
|
|
|
PyObject *co_name = self->co_name;
|
2021-07-07 08:21:51 -03:00
|
|
|
PyObject *co_qualname = self->co_qualname;
|
2023-08-07 17:34:53 -03:00
|
|
|
PyObject *co_linetable = self->co_linetable;
|
|
|
|
PyObject *co_exceptiontable = self->co_exceptiontable;
|
2019-05-24 18:57:23 -03:00
|
|
|
|
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
|
|
|
|
if (!args) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
if (args[0]) {
|
2023-08-24 19:51:22 -03:00
|
|
|
co_argcount = PyLong_AsInt(args[0]);
|
2019-05-24 18:57:23 -03:00
|
|
|
if (co_argcount == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[1]) {
|
2023-08-24 19:51:22 -03:00
|
|
|
co_posonlyargcount = PyLong_AsInt(args[1]);
|
2019-05-24 18:57:23 -03:00
|
|
|
if (co_posonlyargcount == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[2]) {
|
2023-08-24 19:51:22 -03:00
|
|
|
co_kwonlyargcount = PyLong_AsInt(args[2]);
|
2019-05-24 18:57:23 -03:00
|
|
|
if (co_kwonlyargcount == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[3]) {
|
2023-08-24 19:51:22 -03:00
|
|
|
co_nlocals = PyLong_AsInt(args[3]);
|
2019-05-24 18:57:23 -03:00
|
|
|
if (co_nlocals == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[4]) {
|
2023-08-24 19:51:22 -03:00
|
|
|
co_stacksize = PyLong_AsInt(args[4]);
|
2019-05-24 18:57:23 -03:00
|
|
|
if (co_stacksize == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[5]) {
|
2023-08-24 19:51:22 -03:00
|
|
|
co_flags = PyLong_AsInt(args[5]);
|
2019-05-24 18:57:23 -03:00
|
|
|
if (co_flags == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[6]) {
|
2023-08-24 19:51:22 -03:00
|
|
|
co_firstlineno = PyLong_AsInt(args[6]);
|
2019-05-24 18:57:23 -03:00
|
|
|
if (co_firstlineno == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[7]) {
|
|
|
|
if (!PyBytes_Check(args[7])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("replace", "argument 'co_code'", "bytes", args[7]);
|
2019-05-24 18:57:23 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-07 17:34:53 -03:00
|
|
|
co_code = args[7];
|
2019-05-24 18:57:23 -03:00
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[8]) {
|
|
|
|
if (!PyTuple_Check(args[8])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("replace", "argument 'co_consts'", "tuple", args[8]);
|
2019-05-24 18:57:23 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
co_consts = args[8];
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[9]) {
|
|
|
|
if (!PyTuple_Check(args[9])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("replace", "argument 'co_names'", "tuple", args[9]);
|
2019-05-24 18:57:23 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
co_names = args[9];
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[10]) {
|
|
|
|
if (!PyTuple_Check(args[10])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("replace", "argument 'co_varnames'", "tuple", args[10]);
|
2019-05-24 18:57:23 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
co_varnames = args[10];
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[11]) {
|
|
|
|
if (!PyTuple_Check(args[11])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("replace", "argument 'co_freevars'", "tuple", args[11]);
|
2019-05-24 18:57:23 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
co_freevars = args[11];
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[12]) {
|
|
|
|
if (!PyTuple_Check(args[12])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("replace", "argument 'co_cellvars'", "tuple", args[12]);
|
2019-05-24 18:57:23 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
co_cellvars = args[12];
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[13]) {
|
|
|
|
if (!PyUnicode_Check(args[13])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("replace", "argument 'co_filename'", "str", args[13]);
|
2019-05-24 18:57:23 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
co_filename = args[13];
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args[14]) {
|
|
|
|
if (!PyUnicode_Check(args[14])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("replace", "argument 'co_name'", "str", args[14]);
|
2019-05-24 18:57:23 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
co_name = args[14];
|
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
2021-05-07 11:19:19 -03:00
|
|
|
if (args[15]) {
|
2021-07-07 08:21:51 -03:00
|
|
|
if (!PyUnicode_Check(args[15])) {
|
|
|
|
_PyArg_BadArgument("replace", "argument 'co_qualname'", "str", args[15]);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
co_qualname = args[15];
|
2021-05-07 11:19:19 -03:00
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
2021-07-02 11:10:11 -03:00
|
|
|
if (args[16]) {
|
|
|
|
if (!PyBytes_Check(args[16])) {
|
2021-07-07 08:21:51 -03:00
|
|
|
_PyArg_BadArgument("replace", "argument 'co_linetable'", "bytes", args[16]);
|
2021-07-02 11:10:11 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-07 17:34:53 -03:00
|
|
|
co_linetable = args[16];
|
2021-07-02 11:10:11 -03:00
|
|
|
if (!--noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
}
|
2022-04-21 12:10:37 -03:00
|
|
|
if (!PyBytes_Check(args[17])) {
|
|
|
|
_PyArg_BadArgument("replace", "argument 'co_exceptiontable'", "bytes", args[17]);
|
2019-05-24 18:57:23 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-07 17:34:53 -03:00
|
|
|
co_exceptiontable = args[17];
|
2019-05-24 18:57:23 -03:00
|
|
|
skip_optional_kwonly:
|
2022-04-21 12:10:37 -03:00
|
|
|
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_exceptiontable);
|
2019-05-24 18:57:23 -03:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2021-06-07 15:22:26 -03:00
|
|
|
|
|
|
|
PyDoc_STRVAR(code__varname_from_oparg__doc__,
|
|
|
|
"_varname_from_oparg($self, /, oparg)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"(internal-only) Return the local variable name for the given oparg.\n"
|
|
|
|
"\n"
|
|
|
|
"WARNING: this method is for internal use only and may change or go away.");
|
|
|
|
|
|
|
|
#define CODE__VARNAME_FROM_OPARG_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"_varname_from_oparg", _PyCFunction_CAST(code__varname_from_oparg), METH_FASTCALL|METH_KEYWORDS, code__varname_from_oparg__doc__},
|
2021-06-07 15:22:26 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
code__varname_from_oparg_impl(PyCodeObject *self, int oparg);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 1
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(oparg), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2021-06-07 15:22:26 -03:00
|
|
|
static const char * const _keywords[] = {"oparg", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "_varname_from_oparg",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2021-06-07 15:22:26 -03:00
|
|
|
PyObject *argsbuf[1];
|
|
|
|
int oparg;
|
|
|
|
|
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
|
|
|
if (!args) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2023-08-24 19:51:22 -03:00
|
|
|
oparg = PyLong_AsInt(args[0]);
|
2021-06-07 15:22:26 -03:00
|
|
|
if (oparg == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = code__varname_from_oparg_impl(self, oparg);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2023-10-17 09:30:31 -03:00
|
|
|
/*[clinic end generated code: output=d604263a3ca72a0f input=a9049054013a1b77]*/
|