Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(code_replace__doc__, |
| 6 | "replace($self, /, *, co_argcount=-1, co_posonlyargcount=-1,\n" |
| 7 | " co_kwonlyargcount=-1, co_nlocals=-1, co_stacksize=-1,\n" |
| 8 | " co_flags=-1, co_firstlineno=-1, co_code=None, co_consts=None,\n" |
| 9 | " co_names=None, co_varnames=None, co_freevars=None,\n" |
| 10 | " co_cellvars=None, co_filename=None, co_name=None,\n" |
| 11 | " co_lnotab=None)\n" |
| 12 | "--\n" |
| 13 | "\n" |
Anthony Sottile | 22424c0 | 2020-01-01 01:11:16 -0500 | [diff] [blame] | 14 | "Return a copy of the code object with new values for the specified fields."); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 15 | |
| 16 | #define CODE_REPLACE_METHODDEF \ |
| 17 | {"replace", (PyCFunction)(void(*)(void))code_replace, METH_FASTCALL|METH_KEYWORDS, code_replace__doc__}, |
| 18 | |
| 19 | static PyObject * |
| 20 | code_replace_impl(PyCodeObject *self, int co_argcount, |
| 21 | int co_posonlyargcount, int co_kwonlyargcount, |
| 22 | int co_nlocals, int co_stacksize, int co_flags, |
| 23 | int co_firstlineno, PyBytesObject *co_code, |
| 24 | PyObject *co_consts, PyObject *co_names, |
| 25 | PyObject *co_varnames, PyObject *co_freevars, |
| 26 | PyObject *co_cellvars, PyObject *co_filename, |
| 27 | PyObject *co_name, PyBytesObject *co_lnotab); |
| 28 | |
| 29 | static PyObject * |
| 30 | code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 31 | { |
| 32 | PyObject *return_value = NULL; |
| 33 | 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_lnotab", NULL}; |
| 34 | static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0}; |
| 35 | PyObject *argsbuf[16]; |
| 36 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 37 | int co_argcount = self->co_argcount; |
| 38 | int co_posonlyargcount = self->co_posonlyargcount; |
| 39 | int co_kwonlyargcount = self->co_kwonlyargcount; |
| 40 | int co_nlocals = self->co_nlocals; |
| 41 | int co_stacksize = self->co_stacksize; |
| 42 | int co_flags = self->co_flags; |
| 43 | int co_firstlineno = self->co_firstlineno; |
| 44 | PyBytesObject *co_code = (PyBytesObject *)self->co_code; |
| 45 | PyObject *co_consts = self->co_consts; |
| 46 | PyObject *co_names = self->co_names; |
| 47 | PyObject *co_varnames = self->co_varnames; |
| 48 | PyObject *co_freevars = self->co_freevars; |
| 49 | PyObject *co_cellvars = self->co_cellvars; |
| 50 | PyObject *co_filename = self->co_filename; |
| 51 | PyObject *co_name = self->co_name; |
| 52 | PyBytesObject *co_lnotab = (PyBytesObject *)self->co_lnotab; |
| 53 | |
| 54 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 55 | if (!args) { |
| 56 | goto exit; |
| 57 | } |
| 58 | if (!noptargs) { |
| 59 | goto skip_optional_kwonly; |
| 60 | } |
| 61 | if (args[0]) { |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 62 | co_argcount = _PyLong_AsInt(args[0]); |
| 63 | if (co_argcount == -1 && PyErr_Occurred()) { |
| 64 | goto exit; |
| 65 | } |
| 66 | if (!--noptargs) { |
| 67 | goto skip_optional_kwonly; |
| 68 | } |
| 69 | } |
| 70 | if (args[1]) { |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 71 | co_posonlyargcount = _PyLong_AsInt(args[1]); |
| 72 | if (co_posonlyargcount == -1 && PyErr_Occurred()) { |
| 73 | goto exit; |
| 74 | } |
| 75 | if (!--noptargs) { |
| 76 | goto skip_optional_kwonly; |
| 77 | } |
| 78 | } |
| 79 | if (args[2]) { |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 80 | co_kwonlyargcount = _PyLong_AsInt(args[2]); |
| 81 | if (co_kwonlyargcount == -1 && PyErr_Occurred()) { |
| 82 | goto exit; |
| 83 | } |
| 84 | if (!--noptargs) { |
| 85 | goto skip_optional_kwonly; |
| 86 | } |
| 87 | } |
| 88 | if (args[3]) { |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 89 | co_nlocals = _PyLong_AsInt(args[3]); |
| 90 | if (co_nlocals == -1 && PyErr_Occurred()) { |
| 91 | goto exit; |
| 92 | } |
| 93 | if (!--noptargs) { |
| 94 | goto skip_optional_kwonly; |
| 95 | } |
| 96 | } |
| 97 | if (args[4]) { |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 98 | co_stacksize = _PyLong_AsInt(args[4]); |
| 99 | if (co_stacksize == -1 && PyErr_Occurred()) { |
| 100 | goto exit; |
| 101 | } |
| 102 | if (!--noptargs) { |
| 103 | goto skip_optional_kwonly; |
| 104 | } |
| 105 | } |
| 106 | if (args[5]) { |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 107 | co_flags = _PyLong_AsInt(args[5]); |
| 108 | if (co_flags == -1 && PyErr_Occurred()) { |
| 109 | goto exit; |
| 110 | } |
| 111 | if (!--noptargs) { |
| 112 | goto skip_optional_kwonly; |
| 113 | } |
| 114 | } |
| 115 | if (args[6]) { |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 116 | co_firstlineno = _PyLong_AsInt(args[6]); |
| 117 | if (co_firstlineno == -1 && PyErr_Occurred()) { |
| 118 | goto exit; |
| 119 | } |
| 120 | if (!--noptargs) { |
| 121 | goto skip_optional_kwonly; |
| 122 | } |
| 123 | } |
| 124 | if (args[7]) { |
| 125 | if (!PyBytes_Check(args[7])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 126 | _PyArg_BadArgument("replace", "argument 'co_code'", "bytes", args[7]); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 127 | goto exit; |
| 128 | } |
| 129 | co_code = (PyBytesObject *)args[7]; |
| 130 | if (!--noptargs) { |
| 131 | goto skip_optional_kwonly; |
| 132 | } |
| 133 | } |
| 134 | if (args[8]) { |
| 135 | if (!PyTuple_Check(args[8])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 136 | _PyArg_BadArgument("replace", "argument 'co_consts'", "tuple", args[8]); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 137 | goto exit; |
| 138 | } |
| 139 | co_consts = args[8]; |
| 140 | if (!--noptargs) { |
| 141 | goto skip_optional_kwonly; |
| 142 | } |
| 143 | } |
| 144 | if (args[9]) { |
| 145 | if (!PyTuple_Check(args[9])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 146 | _PyArg_BadArgument("replace", "argument 'co_names'", "tuple", args[9]); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 147 | goto exit; |
| 148 | } |
| 149 | co_names = args[9]; |
| 150 | if (!--noptargs) { |
| 151 | goto skip_optional_kwonly; |
| 152 | } |
| 153 | } |
| 154 | if (args[10]) { |
| 155 | if (!PyTuple_Check(args[10])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 156 | _PyArg_BadArgument("replace", "argument 'co_varnames'", "tuple", args[10]); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 157 | goto exit; |
| 158 | } |
| 159 | co_varnames = args[10]; |
| 160 | if (!--noptargs) { |
| 161 | goto skip_optional_kwonly; |
| 162 | } |
| 163 | } |
| 164 | if (args[11]) { |
| 165 | if (!PyTuple_Check(args[11])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 166 | _PyArg_BadArgument("replace", "argument 'co_freevars'", "tuple", args[11]); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 167 | goto exit; |
| 168 | } |
| 169 | co_freevars = args[11]; |
| 170 | if (!--noptargs) { |
| 171 | goto skip_optional_kwonly; |
| 172 | } |
| 173 | } |
| 174 | if (args[12]) { |
| 175 | if (!PyTuple_Check(args[12])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 176 | _PyArg_BadArgument("replace", "argument 'co_cellvars'", "tuple", args[12]); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 177 | goto exit; |
| 178 | } |
| 179 | co_cellvars = args[12]; |
| 180 | if (!--noptargs) { |
| 181 | goto skip_optional_kwonly; |
| 182 | } |
| 183 | } |
| 184 | if (args[13]) { |
| 185 | if (!PyUnicode_Check(args[13])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 186 | _PyArg_BadArgument("replace", "argument 'co_filename'", "str", args[13]); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 187 | goto exit; |
| 188 | } |
| 189 | if (PyUnicode_READY(args[13]) == -1) { |
| 190 | goto exit; |
| 191 | } |
| 192 | co_filename = args[13]; |
| 193 | if (!--noptargs) { |
| 194 | goto skip_optional_kwonly; |
| 195 | } |
| 196 | } |
| 197 | if (args[14]) { |
| 198 | if (!PyUnicode_Check(args[14])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 199 | _PyArg_BadArgument("replace", "argument 'co_name'", "str", args[14]); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 200 | goto exit; |
| 201 | } |
| 202 | if (PyUnicode_READY(args[14]) == -1) { |
| 203 | goto exit; |
| 204 | } |
| 205 | co_name = args[14]; |
| 206 | if (!--noptargs) { |
| 207 | goto skip_optional_kwonly; |
| 208 | } |
| 209 | } |
| 210 | if (!PyBytes_Check(args[15])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 211 | _PyArg_BadArgument("replace", "argument 'co_lnotab'", "bytes", args[15]); |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 212 | goto exit; |
| 213 | } |
| 214 | co_lnotab = (PyBytesObject *)args[15]; |
| 215 | skip_optional_kwonly: |
| 216 | 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_lnotab); |
| 217 | |
| 218 | exit: |
| 219 | return return_value; |
| 220 | } |
Serhiy Storchaka | 578c395 | 2020-05-26 18:43:38 +0300 | [diff] [blame] | 221 | /*[clinic end generated code: output=f9f23e912a3955b9 input=a9049054013a1b77]*/ |