Branch data Line data Source code
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 : :
10 : :
11 : : PyDoc_STRVAR(OrderedDict_fromkeys__doc__,
12 : : "fromkeys($type, /, iterable, value=None)\n"
13 : : "--\n"
14 : : "\n"
15 : : "Create a new ordered dictionary with keys from iterable and values set to value.");
16 : :
17 : : #define ORDEREDDICT_FROMKEYS_METHODDEF \
18 : : {"fromkeys", _PyCFunction_CAST(OrderedDict_fromkeys), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, OrderedDict_fromkeys__doc__},
19 : :
20 : : static PyObject *
21 : : OrderedDict_fromkeys_impl(PyTypeObject *type, PyObject *seq, PyObject *value);
22 : :
23 : : static PyObject *
24 : 0 : OrderedDict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
25 : : {
26 : 0 : PyObject *return_value = NULL;
27 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
28 : :
29 : : #define NUM_KEYWORDS 2
30 : : static struct {
31 : : PyGC_Head _this_is_not_used;
32 : : PyObject_VAR_HEAD
33 : : PyObject *ob_item[NUM_KEYWORDS];
34 : : } _kwtuple = {
35 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
36 : : .ob_item = { &_Py_ID(iterable), &_Py_ID(value), },
37 : : };
38 : : #undef NUM_KEYWORDS
39 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
40 : :
41 : : #else // !Py_BUILD_CORE
42 : : # define KWTUPLE NULL
43 : : #endif // !Py_BUILD_CORE
44 : :
45 : : static const char * const _keywords[] = {"iterable", "value", NULL};
46 : : static _PyArg_Parser _parser = {
47 : : .keywords = _keywords,
48 : : .fname = "fromkeys",
49 : : .kwtuple = KWTUPLE,
50 : : };
51 : : #undef KWTUPLE
52 : : PyObject *argsbuf[2];
53 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
54 : : PyObject *seq;
55 : 0 : PyObject *value = Py_None;
56 : :
57 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
58 [ # # ]: 0 : if (!args) {
59 : 0 : goto exit;
60 : : }
61 : 0 : seq = args[0];
62 [ # # ]: 0 : if (!noptargs) {
63 : 0 : goto skip_optional_pos;
64 : : }
65 : 0 : value = args[1];
66 : 0 : skip_optional_pos:
67 : 0 : return_value = OrderedDict_fromkeys_impl(type, seq, value);
68 : :
69 : 0 : exit:
70 : 0 : return return_value;
71 : : }
72 : :
73 : : PyDoc_STRVAR(OrderedDict_setdefault__doc__,
74 : : "setdefault($self, /, key, default=None)\n"
75 : : "--\n"
76 : : "\n"
77 : : "Insert key with a value of default if key is not in the dictionary.\n"
78 : : "\n"
79 : : "Return the value for key if key is in the dictionary, else default.");
80 : :
81 : : #define ORDEREDDICT_SETDEFAULT_METHODDEF \
82 : : {"setdefault", _PyCFunction_CAST(OrderedDict_setdefault), METH_FASTCALL|METH_KEYWORDS, OrderedDict_setdefault__doc__},
83 : :
84 : : static PyObject *
85 : : OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
86 : : PyObject *default_value);
87 : :
88 : : static PyObject *
89 : 0 : OrderedDict_setdefault(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
90 : : {
91 : 0 : PyObject *return_value = NULL;
92 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
93 : :
94 : : #define NUM_KEYWORDS 2
95 : : static struct {
96 : : PyGC_Head _this_is_not_used;
97 : : PyObject_VAR_HEAD
98 : : PyObject *ob_item[NUM_KEYWORDS];
99 : : } _kwtuple = {
100 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
101 : : .ob_item = { &_Py_ID(key), &_Py_ID(default), },
102 : : };
103 : : #undef NUM_KEYWORDS
104 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
105 : :
106 : : #else // !Py_BUILD_CORE
107 : : # define KWTUPLE NULL
108 : : #endif // !Py_BUILD_CORE
109 : :
110 : : static const char * const _keywords[] = {"key", "default", NULL};
111 : : static _PyArg_Parser _parser = {
112 : : .keywords = _keywords,
113 : : .fname = "setdefault",
114 : : .kwtuple = KWTUPLE,
115 : : };
116 : : #undef KWTUPLE
117 : : PyObject *argsbuf[2];
118 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
119 : : PyObject *key;
120 : 0 : PyObject *default_value = Py_None;
121 : :
122 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
123 [ # # ]: 0 : if (!args) {
124 : 0 : goto exit;
125 : : }
126 : 0 : key = args[0];
127 [ # # ]: 0 : if (!noptargs) {
128 : 0 : goto skip_optional_pos;
129 : : }
130 : 0 : default_value = args[1];
131 : 0 : skip_optional_pos:
132 : 0 : return_value = OrderedDict_setdefault_impl(self, key, default_value);
133 : :
134 : 0 : exit:
135 : 0 : return return_value;
136 : : }
137 : :
138 : : PyDoc_STRVAR(OrderedDict_pop__doc__,
139 : : "pop($self, /, key, default=<unrepresentable>)\n"
140 : : "--\n"
141 : : "\n"
142 : : "od.pop(key[,default]) -> v, remove specified key and return the corresponding value.\n"
143 : : "\n"
144 : : "If the key is not found, return the default if given; otherwise,\n"
145 : : "raise a KeyError.");
146 : :
147 : : #define ORDEREDDICT_POP_METHODDEF \
148 : : {"pop", _PyCFunction_CAST(OrderedDict_pop), METH_FASTCALL|METH_KEYWORDS, OrderedDict_pop__doc__},
149 : :
150 : : static PyObject *
151 : : OrderedDict_pop_impl(PyODictObject *self, PyObject *key,
152 : : PyObject *default_value);
153 : :
154 : : static PyObject *
155 : 0 : OrderedDict_pop(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
156 : : {
157 : 0 : PyObject *return_value = NULL;
158 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
159 : :
160 : : #define NUM_KEYWORDS 2
161 : : static struct {
162 : : PyGC_Head _this_is_not_used;
163 : : PyObject_VAR_HEAD
164 : : PyObject *ob_item[NUM_KEYWORDS];
165 : : } _kwtuple = {
166 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
167 : : .ob_item = { &_Py_ID(key), &_Py_ID(default), },
168 : : };
169 : : #undef NUM_KEYWORDS
170 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
171 : :
172 : : #else // !Py_BUILD_CORE
173 : : # define KWTUPLE NULL
174 : : #endif // !Py_BUILD_CORE
175 : :
176 : : static const char * const _keywords[] = {"key", "default", NULL};
177 : : static _PyArg_Parser _parser = {
178 : : .keywords = _keywords,
179 : : .fname = "pop",
180 : : .kwtuple = KWTUPLE,
181 : : };
182 : : #undef KWTUPLE
183 : : PyObject *argsbuf[2];
184 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
185 : : PyObject *key;
186 : 0 : PyObject *default_value = NULL;
187 : :
188 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
189 [ # # ]: 0 : if (!args) {
190 : 0 : goto exit;
191 : : }
192 : 0 : key = args[0];
193 [ # # ]: 0 : if (!noptargs) {
194 : 0 : goto skip_optional_pos;
195 : : }
196 : 0 : default_value = args[1];
197 : 0 : skip_optional_pos:
198 : 0 : return_value = OrderedDict_pop_impl(self, key, default_value);
199 : :
200 : 0 : exit:
201 : 0 : return return_value;
202 : : }
203 : :
204 : : PyDoc_STRVAR(OrderedDict_popitem__doc__,
205 : : "popitem($self, /, last=True)\n"
206 : : "--\n"
207 : : "\n"
208 : : "Remove and return a (key, value) pair from the dictionary.\n"
209 : : "\n"
210 : : "Pairs are returned in LIFO order if last is true or FIFO order if false.");
211 : :
212 : : #define ORDEREDDICT_POPITEM_METHODDEF \
213 : : {"popitem", _PyCFunction_CAST(OrderedDict_popitem), METH_FASTCALL|METH_KEYWORDS, OrderedDict_popitem__doc__},
214 : :
215 : : static PyObject *
216 : : OrderedDict_popitem_impl(PyODictObject *self, int last);
217 : :
218 : : static PyObject *
219 : 0 : OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
220 : : {
221 : 0 : PyObject *return_value = NULL;
222 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
223 : :
224 : : #define NUM_KEYWORDS 1
225 : : static struct {
226 : : PyGC_Head _this_is_not_used;
227 : : PyObject_VAR_HEAD
228 : : PyObject *ob_item[NUM_KEYWORDS];
229 : : } _kwtuple = {
230 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
231 : : .ob_item = { &_Py_ID(last), },
232 : : };
233 : : #undef NUM_KEYWORDS
234 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
235 : :
236 : : #else // !Py_BUILD_CORE
237 : : # define KWTUPLE NULL
238 : : #endif // !Py_BUILD_CORE
239 : :
240 : : static const char * const _keywords[] = {"last", NULL};
241 : : static _PyArg_Parser _parser = {
242 : : .keywords = _keywords,
243 : : .fname = "popitem",
244 : : .kwtuple = KWTUPLE,
245 : : };
246 : : #undef KWTUPLE
247 : : PyObject *argsbuf[1];
248 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
249 : 0 : int last = 1;
250 : :
251 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
252 [ # # ]: 0 : if (!args) {
253 : 0 : goto exit;
254 : : }
255 [ # # ]: 0 : if (!noptargs) {
256 : 0 : goto skip_optional_pos;
257 : : }
258 : 0 : last = PyObject_IsTrue(args[0]);
259 [ # # ]: 0 : if (last < 0) {
260 : 0 : goto exit;
261 : : }
262 : 0 : skip_optional_pos:
263 : 0 : return_value = OrderedDict_popitem_impl(self, last);
264 : :
265 : 0 : exit:
266 : 0 : return return_value;
267 : : }
268 : :
269 : : PyDoc_STRVAR(OrderedDict_move_to_end__doc__,
270 : : "move_to_end($self, /, key, last=True)\n"
271 : : "--\n"
272 : : "\n"
273 : : "Move an existing element to the end (or beginning if last is false).\n"
274 : : "\n"
275 : : "Raise KeyError if the element does not exist.");
276 : :
277 : : #define ORDEREDDICT_MOVE_TO_END_METHODDEF \
278 : : {"move_to_end", _PyCFunction_CAST(OrderedDict_move_to_end), METH_FASTCALL|METH_KEYWORDS, OrderedDict_move_to_end__doc__},
279 : :
280 : : static PyObject *
281 : : OrderedDict_move_to_end_impl(PyODictObject *self, PyObject *key, int last);
282 : :
283 : : static PyObject *
284 : 0 : OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
285 : : {
286 : 0 : PyObject *return_value = NULL;
287 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
288 : :
289 : : #define NUM_KEYWORDS 2
290 : : static struct {
291 : : PyGC_Head _this_is_not_used;
292 : : PyObject_VAR_HEAD
293 : : PyObject *ob_item[NUM_KEYWORDS];
294 : : } _kwtuple = {
295 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
296 : : .ob_item = { &_Py_ID(key), &_Py_ID(last), },
297 : : };
298 : : #undef NUM_KEYWORDS
299 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
300 : :
301 : : #else // !Py_BUILD_CORE
302 : : # define KWTUPLE NULL
303 : : #endif // !Py_BUILD_CORE
304 : :
305 : : static const char * const _keywords[] = {"key", "last", NULL};
306 : : static _PyArg_Parser _parser = {
307 : : .keywords = _keywords,
308 : : .fname = "move_to_end",
309 : : .kwtuple = KWTUPLE,
310 : : };
311 : : #undef KWTUPLE
312 : : PyObject *argsbuf[2];
313 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
314 : : PyObject *key;
315 : 0 : int last = 1;
316 : :
317 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
318 [ # # ]: 0 : if (!args) {
319 : 0 : goto exit;
320 : : }
321 : 0 : key = args[0];
322 [ # # ]: 0 : if (!noptargs) {
323 : 0 : goto skip_optional_pos;
324 : : }
325 : 0 : last = PyObject_IsTrue(args[1]);
326 [ # # ]: 0 : if (last < 0) {
327 : 0 : goto exit;
328 : : }
329 : 0 : skip_optional_pos:
330 : 0 : return_value = OrderedDict_move_to_end_impl(self, key, last);
331 : :
332 : 0 : exit:
333 : 0 : return return_value;
334 : : }
335 : : /*[clinic end generated code: output=76d85a9162d62ca8 input=a9049054013a1b77]*/
|