LCOV - code coverage report
Current view: top level - Objects/clinic - codeobject.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 173 252 68.7 %
Date: 2022-07-07 18:19:46 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.14