/src/cpython/Objects/clinic/structseq.c.h
Line | Count | Source |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6 | | # include "pycore_gc.h" // PyGC_Head |
7 | | # include "pycore_runtime.h" // _Py_ID() |
8 | | #endif |
9 | | #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
10 | | |
11 | | static PyObject * |
12 | | structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict); |
13 | | |
14 | | static PyObject * |
15 | | structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
16 | 8.74k | { |
17 | 8.74k | PyObject *return_value = NULL; |
18 | 8.74k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
19 | | |
20 | 8.74k | #define NUM_KEYWORDS 2 |
21 | 8.74k | static struct { |
22 | 8.74k | PyGC_Head _this_is_not_used; |
23 | 8.74k | PyObject_VAR_HEAD |
24 | 8.74k | Py_hash_t ob_hash; |
25 | 8.74k | PyObject *ob_item[NUM_KEYWORDS]; |
26 | 8.74k | } _kwtuple = { |
27 | 8.74k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
28 | 8.74k | .ob_hash = -1, |
29 | 8.74k | .ob_item = { &_Py_ID(sequence), &_Py_ID(dict), }, |
30 | 8.74k | }; |
31 | 8.74k | #undef NUM_KEYWORDS |
32 | 8.74k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
33 | | |
34 | | #else // !Py_BUILD_CORE |
35 | | # define KWTUPLE NULL |
36 | | #endif // !Py_BUILD_CORE |
37 | | |
38 | 8.74k | static const char * const _keywords[] = {"sequence", "dict", NULL}; |
39 | 8.74k | static _PyArg_Parser _parser = { |
40 | 8.74k | .keywords = _keywords, |
41 | 8.74k | .fname = "structseq", |
42 | 8.74k | .kwtuple = KWTUPLE, |
43 | 8.74k | }; |
44 | 8.74k | #undef KWTUPLE |
45 | 8.74k | PyObject *argsbuf[2]; |
46 | 8.74k | PyObject * const *fastargs; |
47 | 8.74k | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
48 | 8.74k | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; |
49 | 8.74k | PyObject *arg; |
50 | 8.74k | PyObject *dict = NULL; |
51 | | |
52 | 8.74k | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
53 | 8.74k | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
54 | 8.74k | if (!fastargs) { |
55 | 0 | goto exit; |
56 | 0 | } |
57 | 8.74k | arg = fastargs[0]; |
58 | 8.74k | if (!noptargs) { |
59 | 8.74k | goto skip_optional_pos; |
60 | 8.74k | } |
61 | 0 | dict = fastargs[1]; |
62 | 8.74k | skip_optional_pos: |
63 | 8.74k | return_value = structseq_new_impl(type, arg, dict); |
64 | | |
65 | 8.74k | exit: |
66 | 8.74k | return return_value; |
67 | 8.74k | } |
68 | | |
69 | | PyDoc_STRVAR(structseq___replace____doc__, |
70 | | "__replace__($self, /, **changes)\n" |
71 | | "--\n" |
72 | | "\n" |
73 | | "Return a copy with new values for the specified fields."); |
74 | | |
75 | | #define STRUCTSEQ___REPLACE___METHODDEF \ |
76 | | {"__replace__", _PyCFunction_CAST(structseq___replace__), METH_VARARGS|METH_KEYWORDS, structseq___replace____doc__}, |
77 | | |
78 | | static PyObject * |
79 | | structseq___replace___impl(PyStructSequence *self, PyObject *changes); |
80 | | |
81 | | static PyObject * |
82 | | structseq___replace__(PyObject *self, PyObject *args, PyObject *kwargs) |
83 | 0 | { |
84 | 0 | PyObject *return_value = NULL; |
85 | 0 | PyObject *changes = NULL; |
86 | |
|
87 | 0 | if (!_PyArg_NoPositional("__replace__", args)) { |
88 | 0 | goto exit; |
89 | 0 | } |
90 | 0 | if (kwargs == NULL) { |
91 | 0 | changes = PyDict_New(); |
92 | 0 | if (changes == NULL) { |
93 | 0 | goto exit; |
94 | 0 | } |
95 | 0 | } |
96 | 0 | else { |
97 | 0 | changes = Py_NewRef(kwargs); |
98 | 0 | } |
99 | 0 | return_value = structseq___replace___impl((PyStructSequence *)self, changes); |
100 | |
|
101 | 0 | exit: |
102 | | /* Cleanup for changes */ |
103 | 0 | Py_XDECREF(changes); |
104 | |
|
105 | 0 | return return_value; |
106 | 0 | } |
107 | | /*[clinic end generated code: output=18fcf88e5df26774 input=a9049054013a1b77]*/ |