(root)/
Python-3.11.7/
Objects/
clinic/
codeobject.c.h
       1  /*[clinic input]
       2  preserve
       3  [clinic start generated code]*/
       4  
       5  PyDoc_STRVAR(code_new__doc__,
       6  "code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n"
       7  "     flags, codestring, constants, names, varnames, filename, name,\n"
       8  "     qualname, firstlineno, linetable, exceptiontable, freevars=(),\n"
       9  "     cellvars=(), /)\n"
      10  "--\n"
      11  "\n"
      12  "Create a code object.  Not for the faint of heart.");
      13  
      14  static PyObject *
      15  code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
      16                int kwonlyargcount, int nlocals, int stacksize, int flags,
      17                PyObject *code, PyObject *consts, PyObject *names,
      18                PyObject *varnames, PyObject *filename, PyObject *name,
      19                PyObject *qualname, int firstlineno, PyObject *linetable,
      20                PyObject *exceptiontable, PyObject *freevars,
      21                PyObject *cellvars);
      22  
      23  static PyObject *
      24  code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
      25  {
      26      PyObject *return_value = NULL;
      27      int argcount;
      28      int posonlyargcount;
      29      int kwonlyargcount;
      30      int nlocals;
      31      int stacksize;
      32      int flags;
      33      PyObject *code;
      34      PyObject *consts;
      35      PyObject *names;
      36      PyObject *varnames;
      37      PyObject *filename;
      38      PyObject *name;
      39      PyObject *qualname;
      40      int firstlineno;
      41      PyObject *linetable;
      42      PyObject *exceptiontable;
      43      PyObject *freevars = NULL;
      44      PyObject *cellvars = NULL;
      45  
      46      if ((type == &PyCode_Type ||
      47           type->tp_init == PyCode_Type.tp_init) &&
      48          !_PyArg_NoKeywords("code", kwargs)) {
      49          goto exit;
      50      }
      51      if (!_PyArg_CheckPositional("code", PyTuple_GET_SIZE(args), 16, 18)) {
      52          goto exit;
      53      }
      54      argcount = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
      55      if (argcount == -1 && PyErr_Occurred()) {
      56          goto exit;
      57      }
      58      posonlyargcount = _PyLong_AsInt(PyTuple_GET_ITEM(args, 1));
      59      if (posonlyargcount == -1 && PyErr_Occurred()) {
      60          goto exit;
      61      }
      62      kwonlyargcount = _PyLong_AsInt(PyTuple_GET_ITEM(args, 2));
      63      if (kwonlyargcount == -1 && PyErr_Occurred()) {
      64          goto exit;
      65      }
      66      nlocals = _PyLong_AsInt(PyTuple_GET_ITEM(args, 3));
      67      if (nlocals == -1 && PyErr_Occurred()) {
      68          goto exit;
      69      }
      70      stacksize = _PyLong_AsInt(PyTuple_GET_ITEM(args, 4));
      71      if (stacksize == -1 && PyErr_Occurred()) {
      72          goto exit;
      73      }
      74      flags = _PyLong_AsInt(PyTuple_GET_ITEM(args, 5));
      75      if (flags == -1 && PyErr_Occurred()) {
      76          goto exit;
      77      }
      78      if (!PyBytes_Check(PyTuple_GET_ITEM(args, 6))) {
      79          _PyArg_BadArgument("code", "argument 7", "bytes", PyTuple_GET_ITEM(args, 6));
      80          goto exit;
      81      }
      82      code = PyTuple_GET_ITEM(args, 6);
      83      if (!PyTuple_Check(PyTuple_GET_ITEM(args, 7))) {
      84          _PyArg_BadArgument("code", "argument 8", "tuple", PyTuple_GET_ITEM(args, 7));
      85          goto exit;
      86      }
      87      consts = PyTuple_GET_ITEM(args, 7);
      88      if (!PyTuple_Check(PyTuple_GET_ITEM(args, 8))) {
      89          _PyArg_BadArgument("code", "argument 9", "tuple", PyTuple_GET_ITEM(args, 8));
      90          goto exit;
      91      }
      92      names = PyTuple_GET_ITEM(args, 8);
      93      if (!PyTuple_Check(PyTuple_GET_ITEM(args, 9))) {
      94          _PyArg_BadArgument("code", "argument 10", "tuple", PyTuple_GET_ITEM(args, 9));
      95          goto exit;
      96      }
      97      varnames = PyTuple_GET_ITEM(args, 9);
      98      if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 10))) {
      99          _PyArg_BadArgument("code", "argument 11", "str", PyTuple_GET_ITEM(args, 10));
     100          goto exit;
     101      }
     102      if (PyUnicode_READY(PyTuple_GET_ITEM(args, 10)) == -1) {
     103          goto exit;
     104      }
     105      filename = PyTuple_GET_ITEM(args, 10);
     106      if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 11))) {
     107          _PyArg_BadArgument("code", "argument 12", "str", PyTuple_GET_ITEM(args, 11));
     108          goto exit;
     109      }
     110      if (PyUnicode_READY(PyTuple_GET_ITEM(args, 11)) == -1) {
     111          goto exit;
     112      }
     113      name = PyTuple_GET_ITEM(args, 11);
     114      if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 12))) {
     115          _PyArg_BadArgument("code", "argument 13", "str", PyTuple_GET_ITEM(args, 12));
     116          goto exit;
     117      }
     118      if (PyUnicode_READY(PyTuple_GET_ITEM(args, 12)) == -1) {
     119          goto exit;
     120      }
     121      qualname = PyTuple_GET_ITEM(args, 12);
     122      firstlineno = _PyLong_AsInt(PyTuple_GET_ITEM(args, 13));
     123      if (firstlineno == -1 && PyErr_Occurred()) {
     124          goto exit;
     125      }
     126      if (!PyBytes_Check(PyTuple_GET_ITEM(args, 14))) {
     127          _PyArg_BadArgument("code", "argument 15", "bytes", PyTuple_GET_ITEM(args, 14));
     128          goto exit;
     129      }
     130      linetable = PyTuple_GET_ITEM(args, 14);
     131      if (!PyBytes_Check(PyTuple_GET_ITEM(args, 15))) {
     132          _PyArg_BadArgument("code", "argument 16", "bytes", PyTuple_GET_ITEM(args, 15));
     133          goto exit;
     134      }
     135      exceptiontable = PyTuple_GET_ITEM(args, 15);
     136      if (PyTuple_GET_SIZE(args) < 17) {
     137          goto skip_optional;
     138      }
     139      if (!PyTuple_Check(PyTuple_GET_ITEM(args, 16))) {
     140          _PyArg_BadArgument("code", "argument 17", "tuple", PyTuple_GET_ITEM(args, 16));
     141          goto exit;
     142      }
     143      freevars = PyTuple_GET_ITEM(args, 16);
     144      if (PyTuple_GET_SIZE(args) < 18) {
     145          goto skip_optional;
     146      }
     147      if (!PyTuple_Check(PyTuple_GET_ITEM(args, 17))) {
     148          _PyArg_BadArgument("code", "argument 18", "tuple", PyTuple_GET_ITEM(args, 17));
     149          goto exit;
     150      }
     151      cellvars = PyTuple_GET_ITEM(args, 17);
     152  skip_optional:
     153      return_value = code_new_impl(type, argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize, flags, code, consts, names, varnames, filename, name, qualname, firstlineno, linetable, exceptiontable, freevars, cellvars);
     154  
     155  exit:
     156      return return_value;
     157  }
     158  
     159  PyDoc_STRVAR(code_replace__doc__,
     160  "replace($self, /, **changes)\n"
     161  "--\n"
     162  "\n"
     163  "Return a copy of the code object with new values for the specified fields.");
     164  
     165  #define CODE_REPLACE_METHODDEF    \
     166      {"replace", _PyCFunction_CAST(code_replace), METH_FASTCALL|METH_KEYWORDS, code_replace__doc__},
     167  
     168  static PyObject *
     169  code_replace_impl(PyCodeObject *self, int co_argcount,
     170                    int co_posonlyargcount, int co_kwonlyargcount,
     171                    int co_nlocals, int co_stacksize, int co_flags,
     172                    int co_firstlineno, PyObject *co_code, PyObject *co_consts,
     173                    PyObject *co_names, PyObject *co_varnames,
     174                    PyObject *co_freevars, PyObject *co_cellvars,
     175                    PyObject *co_filename, PyObject *co_name,
     176                    PyObject *co_qualname, PyObject *co_linetable,
     177                    PyObject *co_exceptiontable);
     178  
     179  static PyObject *
     180  code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     181  {
     182      PyObject *return_value = NULL;
     183      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};
     184      static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0};
     185      PyObject *argsbuf[18];
     186      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     187      int co_argcount = self->co_argcount;
     188      int co_posonlyargcount = self->co_posonlyargcount;
     189      int co_kwonlyargcount = self->co_kwonlyargcount;
     190      int co_nlocals = self->co_nlocals;
     191      int co_stacksize = self->co_stacksize;
     192      int co_flags = self->co_flags;
     193      int co_firstlineno = self->co_firstlineno;
     194      PyObject *co_code = NULL;
     195      PyObject *co_consts = self->co_consts;
     196      PyObject *co_names = self->co_names;
     197      PyObject *co_varnames = NULL;
     198      PyObject *co_freevars = NULL;
     199      PyObject *co_cellvars = NULL;
     200      PyObject *co_filename = self->co_filename;
     201      PyObject *co_name = self->co_name;
     202      PyObject *co_qualname = self->co_qualname;
     203      PyObject *co_linetable = self->co_linetable;
     204      PyObject *co_exceptiontable = self->co_exceptiontable;
     205  
     206      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
     207      if (!args) {
     208          goto exit;
     209      }
     210      if (!noptargs) {
     211          goto skip_optional_kwonly;
     212      }
     213      if (args[0]) {
     214          co_argcount = _PyLong_AsInt(args[0]);
     215          if (co_argcount == -1 && PyErr_Occurred()) {
     216              goto exit;
     217          }
     218          if (!--noptargs) {
     219              goto skip_optional_kwonly;
     220          }
     221      }
     222      if (args[1]) {
     223          co_posonlyargcount = _PyLong_AsInt(args[1]);
     224          if (co_posonlyargcount == -1 && PyErr_Occurred()) {
     225              goto exit;
     226          }
     227          if (!--noptargs) {
     228              goto skip_optional_kwonly;
     229          }
     230      }
     231      if (args[2]) {
     232          co_kwonlyargcount = _PyLong_AsInt(args[2]);
     233          if (co_kwonlyargcount == -1 && PyErr_Occurred()) {
     234              goto exit;
     235          }
     236          if (!--noptargs) {
     237              goto skip_optional_kwonly;
     238          }
     239      }
     240      if (args[3]) {
     241          co_nlocals = _PyLong_AsInt(args[3]);
     242          if (co_nlocals == -1 && PyErr_Occurred()) {
     243              goto exit;
     244          }
     245          if (!--noptargs) {
     246              goto skip_optional_kwonly;
     247          }
     248      }
     249      if (args[4]) {
     250          co_stacksize = _PyLong_AsInt(args[4]);
     251          if (co_stacksize == -1 && PyErr_Occurred()) {
     252              goto exit;
     253          }
     254          if (!--noptargs) {
     255              goto skip_optional_kwonly;
     256          }
     257      }
     258      if (args[5]) {
     259          co_flags = _PyLong_AsInt(args[5]);
     260          if (co_flags == -1 && PyErr_Occurred()) {
     261              goto exit;
     262          }
     263          if (!--noptargs) {
     264              goto skip_optional_kwonly;
     265          }
     266      }
     267      if (args[6]) {
     268          co_firstlineno = _PyLong_AsInt(args[6]);
     269          if (co_firstlineno == -1 && PyErr_Occurred()) {
     270              goto exit;
     271          }
     272          if (!--noptargs) {
     273              goto skip_optional_kwonly;
     274          }
     275      }
     276      if (args[7]) {
     277          if (!PyBytes_Check(args[7])) {
     278              _PyArg_BadArgument("replace", "argument 'co_code'", "bytes", args[7]);
     279              goto exit;
     280          }
     281          co_code = args[7];
     282          if (!--noptargs) {
     283              goto skip_optional_kwonly;
     284          }
     285      }
     286      if (args[8]) {
     287          if (!PyTuple_Check(args[8])) {
     288              _PyArg_BadArgument("replace", "argument 'co_consts'", "tuple", args[8]);
     289              goto exit;
     290          }
     291          co_consts = args[8];
     292          if (!--noptargs) {
     293              goto skip_optional_kwonly;
     294          }
     295      }
     296      if (args[9]) {
     297          if (!PyTuple_Check(args[9])) {
     298              _PyArg_BadArgument("replace", "argument 'co_names'", "tuple", args[9]);
     299              goto exit;
     300          }
     301          co_names = args[9];
     302          if (!--noptargs) {
     303              goto skip_optional_kwonly;
     304          }
     305      }
     306      if (args[10]) {
     307          if (!PyTuple_Check(args[10])) {
     308              _PyArg_BadArgument("replace", "argument 'co_varnames'", "tuple", args[10]);
     309              goto exit;
     310          }
     311          co_varnames = args[10];
     312          if (!--noptargs) {
     313              goto skip_optional_kwonly;
     314          }
     315      }
     316      if (args[11]) {
     317          if (!PyTuple_Check(args[11])) {
     318              _PyArg_BadArgument("replace", "argument 'co_freevars'", "tuple", args[11]);
     319              goto exit;
     320          }
     321          co_freevars = args[11];
     322          if (!--noptargs) {
     323              goto skip_optional_kwonly;
     324          }
     325      }
     326      if (args[12]) {
     327          if (!PyTuple_Check(args[12])) {
     328              _PyArg_BadArgument("replace", "argument 'co_cellvars'", "tuple", args[12]);
     329              goto exit;
     330          }
     331          co_cellvars = args[12];
     332          if (!--noptargs) {
     333              goto skip_optional_kwonly;
     334          }
     335      }
     336      if (args[13]) {
     337          if (!PyUnicode_Check(args[13])) {
     338              _PyArg_BadArgument("replace", "argument 'co_filename'", "str", args[13]);
     339              goto exit;
     340          }
     341          if (PyUnicode_READY(args[13]) == -1) {
     342              goto exit;
     343          }
     344          co_filename = args[13];
     345          if (!--noptargs) {
     346              goto skip_optional_kwonly;
     347          }
     348      }
     349      if (args[14]) {
     350          if (!PyUnicode_Check(args[14])) {
     351              _PyArg_BadArgument("replace", "argument 'co_name'", "str", args[14]);
     352              goto exit;
     353          }
     354          if (PyUnicode_READY(args[14]) == -1) {
     355              goto exit;
     356          }
     357          co_name = args[14];
     358          if (!--noptargs) {
     359              goto skip_optional_kwonly;
     360          }
     361      }
     362      if (args[15]) {
     363          if (!PyUnicode_Check(args[15])) {
     364              _PyArg_BadArgument("replace", "argument 'co_qualname'", "str", args[15]);
     365              goto exit;
     366          }
     367          if (PyUnicode_READY(args[15]) == -1) {
     368              goto exit;
     369          }
     370          co_qualname = args[15];
     371          if (!--noptargs) {
     372              goto skip_optional_kwonly;
     373          }
     374      }
     375      if (args[16]) {
     376          if (!PyBytes_Check(args[16])) {
     377              _PyArg_BadArgument("replace", "argument 'co_linetable'", "bytes", args[16]);
     378              goto exit;
     379          }
     380          co_linetable = args[16];
     381          if (!--noptargs) {
     382              goto skip_optional_kwonly;
     383          }
     384      }
     385      if (!PyBytes_Check(args[17])) {
     386          _PyArg_BadArgument("replace", "argument 'co_exceptiontable'", "bytes", args[17]);
     387          goto exit;
     388      }
     389      co_exceptiontable = args[17];
     390  skip_optional_kwonly:
     391      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);
     392  
     393  exit:
     394      return return_value;
     395  }
     396  
     397  PyDoc_STRVAR(code__varname_from_oparg__doc__,
     398  "_varname_from_oparg($self, /, oparg)\n"
     399  "--\n"
     400  "\n"
     401  "(internal-only) Return the local variable name for the given oparg.\n"
     402  "\n"
     403  "WARNING: this method is for internal use only and may change or go away.");
     404  
     405  #define CODE__VARNAME_FROM_OPARG_METHODDEF    \
     406      {"_varname_from_oparg", _PyCFunction_CAST(code__varname_from_oparg), METH_FASTCALL|METH_KEYWORDS, code__varname_from_oparg__doc__},
     407  
     408  static PyObject *
     409  code__varname_from_oparg_impl(PyCodeObject *self, int oparg);
     410  
     411  static PyObject *
     412  code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     413  {
     414      PyObject *return_value = NULL;
     415      static const char * const _keywords[] = {"oparg", NULL};
     416      static _PyArg_Parser _parser = {NULL, _keywords, "_varname_from_oparg", 0};
     417      PyObject *argsbuf[1];
     418      int oparg;
     419  
     420      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
     421      if (!args) {
     422          goto exit;
     423      }
     424      oparg = _PyLong_AsInt(args[0]);
     425      if (oparg == -1 && PyErr_Occurred()) {
     426          goto exit;
     427      }
     428      return_value = code__varname_from_oparg_impl(self, oparg);
     429  
     430  exit:
     431      return return_value;
     432  }
     433  /*[clinic end generated code: output=d1bbf51b746ca2d0 input=a9049054013a1b77]*/