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