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"
14 "Return a copy of the code object with new values for the specified fields.");
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 *
code_replace(PyCodeObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)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]) {
62 if (PyFloat_Check(args[0])) {
63 PyErr_SetString(PyExc_TypeError,
64 "integer argument expected, got float" );
65 goto exit;
66 }
67 co_argcount = _PyLong_AsInt(args[0]);
68 if (co_argcount == -1 && PyErr_Occurred()) {
69 goto exit;
70 }
71 if (!--noptargs) {
72 goto skip_optional_kwonly;
73 }
74 }
75 if (args[1]) {
76 if (PyFloat_Check(args[1])) {
77 PyErr_SetString(PyExc_TypeError,
78 "integer argument expected, got float" );
79 goto exit;
80 }
81 co_posonlyargcount = _PyLong_AsInt(args[1]);
82 if (co_posonlyargcount == -1 && PyErr_Occurred()) {
83 goto exit;
84 }
85 if (!--noptargs) {
86 goto skip_optional_kwonly;
87 }
88 }
89 if (args[2]) {
90 if (PyFloat_Check(args[2])) {
91 PyErr_SetString(PyExc_TypeError,
92 "integer argument expected, got float" );
93 goto exit;
94 }
95 co_kwonlyargcount = _PyLong_AsInt(args[2]);
96 if (co_kwonlyargcount == -1 && PyErr_Occurred()) {
97 goto exit;
98 }
99 if (!--noptargs) {
100 goto skip_optional_kwonly;
101 }
102 }
103 if (args[3]) {
104 if (PyFloat_Check(args[3])) {
105 PyErr_SetString(PyExc_TypeError,
106 "integer argument expected, got float" );
107 goto exit;
108 }
109 co_nlocals = _PyLong_AsInt(args[3]);
110 if (co_nlocals == -1 && PyErr_Occurred()) {
111 goto exit;
112 }
113 if (!--noptargs) {
114 goto skip_optional_kwonly;
115 }
116 }
117 if (args[4]) {
118 if (PyFloat_Check(args[4])) {
119 PyErr_SetString(PyExc_TypeError,
120 "integer argument expected, got float" );
121 goto exit;
122 }
123 co_stacksize = _PyLong_AsInt(args[4]);
124 if (co_stacksize == -1 && PyErr_Occurred()) {
125 goto exit;
126 }
127 if (!--noptargs) {
128 goto skip_optional_kwonly;
129 }
130 }
131 if (args[5]) {
132 if (PyFloat_Check(args[5])) {
133 PyErr_SetString(PyExc_TypeError,
134 "integer argument expected, got float" );
135 goto exit;
136 }
137 co_flags = _PyLong_AsInt(args[5]);
138 if (co_flags == -1 && PyErr_Occurred()) {
139 goto exit;
140 }
141 if (!--noptargs) {
142 goto skip_optional_kwonly;
143 }
144 }
145 if (args[6]) {
146 if (PyFloat_Check(args[6])) {
147 PyErr_SetString(PyExc_TypeError,
148 "integer argument expected, got float" );
149 goto exit;
150 }
151 co_firstlineno = _PyLong_AsInt(args[6]);
152 if (co_firstlineno == -1 && PyErr_Occurred()) {
153 goto exit;
154 }
155 if (!--noptargs) {
156 goto skip_optional_kwonly;
157 }
158 }
159 if (args[7]) {
160 if (!PyBytes_Check(args[7])) {
161 _PyArg_BadArgument("replace", "argument 'co_code'", "bytes", args[7]);
162 goto exit;
163 }
164 co_code = (PyBytesObject *)args[7];
165 if (!--noptargs) {
166 goto skip_optional_kwonly;
167 }
168 }
169 if (args[8]) {
170 if (!PyTuple_Check(args[8])) {
171 _PyArg_BadArgument("replace", "argument 'co_consts'", "tuple", args[8]);
172 goto exit;
173 }
174 co_consts = args[8];
175 if (!--noptargs) {
176 goto skip_optional_kwonly;
177 }
178 }
179 if (args[9]) {
180 if (!PyTuple_Check(args[9])) {
181 _PyArg_BadArgument("replace", "argument 'co_names'", "tuple", args[9]);
182 goto exit;
183 }
184 co_names = args[9];
185 if (!--noptargs) {
186 goto skip_optional_kwonly;
187 }
188 }
189 if (args[10]) {
190 if (!PyTuple_Check(args[10])) {
191 _PyArg_BadArgument("replace", "argument 'co_varnames'", "tuple", args[10]);
192 goto exit;
193 }
194 co_varnames = args[10];
195 if (!--noptargs) {
196 goto skip_optional_kwonly;
197 }
198 }
199 if (args[11]) {
200 if (!PyTuple_Check(args[11])) {
201 _PyArg_BadArgument("replace", "argument 'co_freevars'", "tuple", args[11]);
202 goto exit;
203 }
204 co_freevars = args[11];
205 if (!--noptargs) {
206 goto skip_optional_kwonly;
207 }
208 }
209 if (args[12]) {
210 if (!PyTuple_Check(args[12])) {
211 _PyArg_BadArgument("replace", "argument 'co_cellvars'", "tuple", args[12]);
212 goto exit;
213 }
214 co_cellvars = args[12];
215 if (!--noptargs) {
216 goto skip_optional_kwonly;
217 }
218 }
219 if (args[13]) {
220 if (!PyUnicode_Check(args[13])) {
221 _PyArg_BadArgument("replace", "argument 'co_filename'", "str", args[13]);
222 goto exit;
223 }
224 if (PyUnicode_READY(args[13]) == -1) {
225 goto exit;
226 }
227 co_filename = args[13];
228 if (!--noptargs) {
229 goto skip_optional_kwonly;
230 }
231 }
232 if (args[14]) {
233 if (!PyUnicode_Check(args[14])) {
234 _PyArg_BadArgument("replace", "argument 'co_name'", "str", args[14]);
235 goto exit;
236 }
237 if (PyUnicode_READY(args[14]) == -1) {
238 goto exit;
239 }
240 co_name = args[14];
241 if (!--noptargs) {
242 goto skip_optional_kwonly;
243 }
244 }
245 if (!PyBytes_Check(args[15])) {
246 _PyArg_BadArgument("replace", "argument 'co_lnotab'", "bytes", args[15]);
247 goto exit;
248 }
249 co_lnotab = (PyBytesObject *)args[15];
250 skip_optional_kwonly:
251 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);
252
253 exit:
254 return return_value;
255 }
256 /*[clinic end generated code: output=27fe34e82106b220 input=a9049054013a1b77]*/
257