1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
6 #include "pycore_modsupport.h" // _PyArg_CheckPositional()
7
8 PyDoc_STRVAR(set_pop__doc__,
9 "pop($self, /)\n"
10 "--\n"
11 "\n"
12 "Remove and return an arbitrary set element.\n"
13 "\n"
14 "Raises KeyError if the set is empty.");
15
16 #define SET_POP_METHODDEF \
17 {"pop", (PyCFunction)set_pop, METH_NOARGS, set_pop__doc__},
18
19 static PyObject *
20 set_pop_impl(PySetObject *so);
21
22 static PyObject *
set_pop(PySetObject * so,PyObject * Py_UNUSED (ignored))23 set_pop(PySetObject *so, PyObject *Py_UNUSED(ignored))
24 {
25 PyObject *return_value = NULL;
26
27 Py_BEGIN_CRITICAL_SECTION(so);
28 return_value = set_pop_impl(so);
29 Py_END_CRITICAL_SECTION();
30
31 return return_value;
32 }
33
34 PyDoc_STRVAR(set_update__doc__,
35 "update($self, /, *others)\n"
36 "--\n"
37 "\n"
38 "Update the set, adding elements from all others.");
39
40 #define SET_UPDATE_METHODDEF \
41 {"update", _PyCFunction_CAST(set_update), METH_FASTCALL, set_update__doc__},
42
43 static PyObject *
44 set_update_impl(PySetObject *so, PyObject *args);
45
46 static PyObject *
set_update(PySetObject * so,PyObject * const * args,Py_ssize_t nargs)47 set_update(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
48 {
49 PyObject *return_value = NULL;
50 PyObject *__clinic_args = NULL;
51
52 if (!_PyArg_CheckPositional("update", nargs, 0, PY_SSIZE_T_MAX)) {
53 goto exit;
54 }
55 __clinic_args = PyTuple_New(nargs - 0);
56 if (!__clinic_args) {
57 goto exit;
58 }
59 for (Py_ssize_t i = 0; i < nargs - 0; ++i) {
60 PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i]));
61 }
62 return_value = set_update_impl(so, __clinic_args);
63
64 exit:
65 Py_XDECREF(__clinic_args);
66 return return_value;
67 }
68
69 PyDoc_STRVAR(set_copy__doc__,
70 "copy($self, /)\n"
71 "--\n"
72 "\n"
73 "Return a shallow copy of a set.");
74
75 #define SET_COPY_METHODDEF \
76 {"copy", (PyCFunction)set_copy, METH_NOARGS, set_copy__doc__},
77
78 static PyObject *
79 set_copy_impl(PySetObject *so);
80
81 static PyObject *
set_copy(PySetObject * so,PyObject * Py_UNUSED (ignored))82 set_copy(PySetObject *so, PyObject *Py_UNUSED(ignored))
83 {
84 PyObject *return_value = NULL;
85
86 Py_BEGIN_CRITICAL_SECTION(so);
87 return_value = set_copy_impl(so);
88 Py_END_CRITICAL_SECTION();
89
90 return return_value;
91 }
92
93 PyDoc_STRVAR(frozenset_copy__doc__,
94 "copy($self, /)\n"
95 "--\n"
96 "\n"
97 "Return a shallow copy of a set.");
98
99 #define FROZENSET_COPY_METHODDEF \
100 {"copy", (PyCFunction)frozenset_copy, METH_NOARGS, frozenset_copy__doc__},
101
102 static PyObject *
103 frozenset_copy_impl(PySetObject *so);
104
105 static PyObject *
frozenset_copy(PySetObject * so,PyObject * Py_UNUSED (ignored))106 frozenset_copy(PySetObject *so, PyObject *Py_UNUSED(ignored))
107 {
108 PyObject *return_value = NULL;
109
110 Py_BEGIN_CRITICAL_SECTION(so);
111 return_value = frozenset_copy_impl(so);
112 Py_END_CRITICAL_SECTION();
113
114 return return_value;
115 }
116
117 PyDoc_STRVAR(set_clear__doc__,
118 "clear($self, /)\n"
119 "--\n"
120 "\n"
121 "Remove all elements from this set.");
122
123 #define SET_CLEAR_METHODDEF \
124 {"clear", (PyCFunction)set_clear, METH_NOARGS, set_clear__doc__},
125
126 static PyObject *
127 set_clear_impl(PySetObject *so);
128
129 static PyObject *
set_clear(PySetObject * so,PyObject * Py_UNUSED (ignored))130 set_clear(PySetObject *so, PyObject *Py_UNUSED(ignored))
131 {
132 PyObject *return_value = NULL;
133
134 Py_BEGIN_CRITICAL_SECTION(so);
135 return_value = set_clear_impl(so);
136 Py_END_CRITICAL_SECTION();
137
138 return return_value;
139 }
140
141 PyDoc_STRVAR(set_union__doc__,
142 "union($self, /, *others)\n"
143 "--\n"
144 "\n"
145 "Return a new set with elements from the set and all others.");
146
147 #define SET_UNION_METHODDEF \
148 {"union", _PyCFunction_CAST(set_union), METH_FASTCALL, set_union__doc__},
149
150 static PyObject *
151 set_union_impl(PySetObject *so, PyObject *args);
152
153 static PyObject *
set_union(PySetObject * so,PyObject * const * args,Py_ssize_t nargs)154 set_union(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
155 {
156 PyObject *return_value = NULL;
157 PyObject *__clinic_args = NULL;
158
159 if (!_PyArg_CheckPositional("union", nargs, 0, PY_SSIZE_T_MAX)) {
160 goto exit;
161 }
162 __clinic_args = PyTuple_New(nargs - 0);
163 if (!__clinic_args) {
164 goto exit;
165 }
166 for (Py_ssize_t i = 0; i < nargs - 0; ++i) {
167 PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i]));
168 }
169 return_value = set_union_impl(so, __clinic_args);
170
171 exit:
172 Py_XDECREF(__clinic_args);
173 return return_value;
174 }
175
176 PyDoc_STRVAR(set_intersection_multi__doc__,
177 "intersection($self, /, *others)\n"
178 "--\n"
179 "\n"
180 "Return a new set with elements common to the set and all others.");
181
182 #define SET_INTERSECTION_MULTI_METHODDEF \
183 {"intersection", _PyCFunction_CAST(set_intersection_multi), METH_FASTCALL, set_intersection_multi__doc__},
184
185 static PyObject *
186 set_intersection_multi_impl(PySetObject *so, PyObject *args);
187
188 static PyObject *
set_intersection_multi(PySetObject * so,PyObject * const * args,Py_ssize_t nargs)189 set_intersection_multi(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
190 {
191 PyObject *return_value = NULL;
192 PyObject *__clinic_args = NULL;
193
194 if (!_PyArg_CheckPositional("intersection", nargs, 0, PY_SSIZE_T_MAX)) {
195 goto exit;
196 }
197 __clinic_args = PyTuple_New(nargs - 0);
198 if (!__clinic_args) {
199 goto exit;
200 }
201 for (Py_ssize_t i = 0; i < nargs - 0; ++i) {
202 PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i]));
203 }
204 return_value = set_intersection_multi_impl(so, __clinic_args);
205
206 exit:
207 Py_XDECREF(__clinic_args);
208 return return_value;
209 }
210
211 PyDoc_STRVAR(set_intersection_update_multi__doc__,
212 "intersection_update($self, /, *others)\n"
213 "--\n"
214 "\n"
215 "Update the set, keeping only elements found in it and all others.");
216
217 #define SET_INTERSECTION_UPDATE_MULTI_METHODDEF \
218 {"intersection_update", _PyCFunction_CAST(set_intersection_update_multi), METH_FASTCALL, set_intersection_update_multi__doc__},
219
220 static PyObject *
221 set_intersection_update_multi_impl(PySetObject *so, PyObject *args);
222
223 static PyObject *
set_intersection_update_multi(PySetObject * so,PyObject * const * args,Py_ssize_t nargs)224 set_intersection_update_multi(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
225 {
226 PyObject *return_value = NULL;
227 PyObject *__clinic_args = NULL;
228
229 if (!_PyArg_CheckPositional("intersection_update", nargs, 0, PY_SSIZE_T_MAX)) {
230 goto exit;
231 }
232 __clinic_args = PyTuple_New(nargs - 0);
233 if (!__clinic_args) {
234 goto exit;
235 }
236 for (Py_ssize_t i = 0; i < nargs - 0; ++i) {
237 PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i]));
238 }
239 return_value = set_intersection_update_multi_impl(so, __clinic_args);
240
241 exit:
242 Py_XDECREF(__clinic_args);
243 return return_value;
244 }
245
246 PyDoc_STRVAR(set_isdisjoint__doc__,
247 "isdisjoint($self, other, /)\n"
248 "--\n"
249 "\n"
250 "Return True if two sets have a null intersection.");
251
252 #define SET_ISDISJOINT_METHODDEF \
253 {"isdisjoint", (PyCFunction)set_isdisjoint, METH_O, set_isdisjoint__doc__},
254
255 static PyObject *
256 set_isdisjoint_impl(PySetObject *so, PyObject *other);
257
258 static PyObject *
set_isdisjoint(PySetObject * so,PyObject * other)259 set_isdisjoint(PySetObject *so, PyObject *other)
260 {
261 PyObject *return_value = NULL;
262
263 Py_BEGIN_CRITICAL_SECTION2(so, other);
264 return_value = set_isdisjoint_impl(so, other);
265 Py_END_CRITICAL_SECTION2();
266
267 return return_value;
268 }
269
270 PyDoc_STRVAR(set_difference_update__doc__,
271 "difference_update($self, /, *others)\n"
272 "--\n"
273 "\n"
274 "Update the set, removing elements found in others.");
275
276 #define SET_DIFFERENCE_UPDATE_METHODDEF \
277 {"difference_update", _PyCFunction_CAST(set_difference_update), METH_FASTCALL, set_difference_update__doc__},
278
279 static PyObject *
280 set_difference_update_impl(PySetObject *so, PyObject *args);
281
282 static PyObject *
set_difference_update(PySetObject * so,PyObject * const * args,Py_ssize_t nargs)283 set_difference_update(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
284 {
285 PyObject *return_value = NULL;
286 PyObject *__clinic_args = NULL;
287
288 if (!_PyArg_CheckPositional("difference_update", nargs, 0, PY_SSIZE_T_MAX)) {
289 goto exit;
290 }
291 __clinic_args = PyTuple_New(nargs - 0);
292 if (!__clinic_args) {
293 goto exit;
294 }
295 for (Py_ssize_t i = 0; i < nargs - 0; ++i) {
296 PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i]));
297 }
298 return_value = set_difference_update_impl(so, __clinic_args);
299
300 exit:
301 Py_XDECREF(__clinic_args);
302 return return_value;
303 }
304
305 PyDoc_STRVAR(set_difference_multi__doc__,
306 "difference($self, /, *others)\n"
307 "--\n"
308 "\n"
309 "Return a new set with elements in the set that are not in the others.");
310
311 #define SET_DIFFERENCE_MULTI_METHODDEF \
312 {"difference", _PyCFunction_CAST(set_difference_multi), METH_FASTCALL, set_difference_multi__doc__},
313
314 static PyObject *
315 set_difference_multi_impl(PySetObject *so, PyObject *args);
316
317 static PyObject *
set_difference_multi(PySetObject * so,PyObject * const * args,Py_ssize_t nargs)318 set_difference_multi(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
319 {
320 PyObject *return_value = NULL;
321 PyObject *__clinic_args = NULL;
322
323 if (!_PyArg_CheckPositional("difference", nargs, 0, PY_SSIZE_T_MAX)) {
324 goto exit;
325 }
326 __clinic_args = PyTuple_New(nargs - 0);
327 if (!__clinic_args) {
328 goto exit;
329 }
330 for (Py_ssize_t i = 0; i < nargs - 0; ++i) {
331 PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[0 + i]));
332 }
333 return_value = set_difference_multi_impl(so, __clinic_args);
334
335 exit:
336 Py_XDECREF(__clinic_args);
337 return return_value;
338 }
339
340 PyDoc_STRVAR(set_symmetric_difference_update__doc__,
341 "symmetric_difference_update($self, other, /)\n"
342 "--\n"
343 "\n"
344 "Update the set, keeping only elements found in either set, but not in both.");
345
346 #define SET_SYMMETRIC_DIFFERENCE_UPDATE_METHODDEF \
347 {"symmetric_difference_update", (PyCFunction)set_symmetric_difference_update, METH_O, set_symmetric_difference_update__doc__},
348
349 PyDoc_STRVAR(set_symmetric_difference__doc__,
350 "symmetric_difference($self, other, /)\n"
351 "--\n"
352 "\n"
353 "Return a new set with elements in either the set or other but not both.");
354
355 #define SET_SYMMETRIC_DIFFERENCE_METHODDEF \
356 {"symmetric_difference", (PyCFunction)set_symmetric_difference, METH_O, set_symmetric_difference__doc__},
357
358 static PyObject *
359 set_symmetric_difference_impl(PySetObject *so, PyObject *other);
360
361 static PyObject *
set_symmetric_difference(PySetObject * so,PyObject * other)362 set_symmetric_difference(PySetObject *so, PyObject *other)
363 {
364 PyObject *return_value = NULL;
365
366 Py_BEGIN_CRITICAL_SECTION2(so, other);
367 return_value = set_symmetric_difference_impl(so, other);
368 Py_END_CRITICAL_SECTION2();
369
370 return return_value;
371 }
372
373 PyDoc_STRVAR(set_issubset__doc__,
374 "issubset($self, other, /)\n"
375 "--\n"
376 "\n"
377 "Report whether another set contains this set.");
378
379 #define SET_ISSUBSET_METHODDEF \
380 {"issubset", (PyCFunction)set_issubset, METH_O, set_issubset__doc__},
381
382 static PyObject *
383 set_issubset_impl(PySetObject *so, PyObject *other);
384
385 static PyObject *
set_issubset(PySetObject * so,PyObject * other)386 set_issubset(PySetObject *so, PyObject *other)
387 {
388 PyObject *return_value = NULL;
389
390 Py_BEGIN_CRITICAL_SECTION2(so, other);
391 return_value = set_issubset_impl(so, other);
392 Py_END_CRITICAL_SECTION2();
393
394 return return_value;
395 }
396
397 PyDoc_STRVAR(set_issuperset__doc__,
398 "issuperset($self, other, /)\n"
399 "--\n"
400 "\n"
401 "Report whether this set contains another set.");
402
403 #define SET_ISSUPERSET_METHODDEF \
404 {"issuperset", (PyCFunction)set_issuperset, METH_O, set_issuperset__doc__},
405
406 static PyObject *
407 set_issuperset_impl(PySetObject *so, PyObject *other);
408
409 static PyObject *
set_issuperset(PySetObject * so,PyObject * other)410 set_issuperset(PySetObject *so, PyObject *other)
411 {
412 PyObject *return_value = NULL;
413
414 Py_BEGIN_CRITICAL_SECTION2(so, other);
415 return_value = set_issuperset_impl(so, other);
416 Py_END_CRITICAL_SECTION2();
417
418 return return_value;
419 }
420
421 PyDoc_STRVAR(set_add__doc__,
422 "add($self, object, /)\n"
423 "--\n"
424 "\n"
425 "Add an element to a set.\n"
426 "\n"
427 "This has no effect if the element is already present.");
428
429 #define SET_ADD_METHODDEF \
430 {"add", (PyCFunction)set_add, METH_O, set_add__doc__},
431
432 static PyObject *
433 set_add_impl(PySetObject *so, PyObject *key);
434
435 static PyObject *
set_add(PySetObject * so,PyObject * key)436 set_add(PySetObject *so, PyObject *key)
437 {
438 PyObject *return_value = NULL;
439
440 Py_BEGIN_CRITICAL_SECTION(so);
441 return_value = set_add_impl(so, key);
442 Py_END_CRITICAL_SECTION();
443
444 return return_value;
445 }
446
447 PyDoc_STRVAR(set___contains____doc__,
448 "__contains__($self, object, /)\n"
449 "--\n"
450 "\n"
451 "x.__contains__(y) <==> y in x.");
452
453 #define SET___CONTAINS___METHODDEF \
454 {"__contains__", (PyCFunction)set___contains__, METH_O|METH_COEXIST, set___contains____doc__},
455
456 static PyObject *
457 set___contains___impl(PySetObject *so, PyObject *key);
458
459 static PyObject *
set___contains__(PySetObject * so,PyObject * key)460 set___contains__(PySetObject *so, PyObject *key)
461 {
462 PyObject *return_value = NULL;
463
464 Py_BEGIN_CRITICAL_SECTION(so);
465 return_value = set___contains___impl(so, key);
466 Py_END_CRITICAL_SECTION();
467
468 return return_value;
469 }
470
471 PyDoc_STRVAR(set_remove__doc__,
472 "remove($self, object, /)\n"
473 "--\n"
474 "\n"
475 "Remove an element from a set; it must be a member.\n"
476 "\n"
477 "If the element is not a member, raise a KeyError.");
478
479 #define SET_REMOVE_METHODDEF \
480 {"remove", (PyCFunction)set_remove, METH_O, set_remove__doc__},
481
482 static PyObject *
483 set_remove_impl(PySetObject *so, PyObject *key);
484
485 static PyObject *
set_remove(PySetObject * so,PyObject * key)486 set_remove(PySetObject *so, PyObject *key)
487 {
488 PyObject *return_value = NULL;
489
490 Py_BEGIN_CRITICAL_SECTION(so);
491 return_value = set_remove_impl(so, key);
492 Py_END_CRITICAL_SECTION();
493
494 return return_value;
495 }
496
497 PyDoc_STRVAR(set_discard__doc__,
498 "discard($self, object, /)\n"
499 "--\n"
500 "\n"
501 "Remove an element from a set if it is a member.\n"
502 "\n"
503 "Unlike set.remove(), the discard() method does not raise\n"
504 "an exception when an element is missing from the set.");
505
506 #define SET_DISCARD_METHODDEF \
507 {"discard", (PyCFunction)set_discard, METH_O, set_discard__doc__},
508
509 static PyObject *
510 set_discard_impl(PySetObject *so, PyObject *key);
511
512 static PyObject *
set_discard(PySetObject * so,PyObject * key)513 set_discard(PySetObject *so, PyObject *key)
514 {
515 PyObject *return_value = NULL;
516
517 Py_BEGIN_CRITICAL_SECTION(so);
518 return_value = set_discard_impl(so, key);
519 Py_END_CRITICAL_SECTION();
520
521 return return_value;
522 }
523
524 PyDoc_STRVAR(set___reduce____doc__,
525 "__reduce__($self, /)\n"
526 "--\n"
527 "\n"
528 "Return state information for pickling.");
529
530 #define SET___REDUCE___METHODDEF \
531 {"__reduce__", (PyCFunction)set___reduce__, METH_NOARGS, set___reduce____doc__},
532
533 static PyObject *
534 set___reduce___impl(PySetObject *so);
535
536 static PyObject *
set___reduce__(PySetObject * so,PyObject * Py_UNUSED (ignored))537 set___reduce__(PySetObject *so, PyObject *Py_UNUSED(ignored))
538 {
539 PyObject *return_value = NULL;
540
541 Py_BEGIN_CRITICAL_SECTION(so);
542 return_value = set___reduce___impl(so);
543 Py_END_CRITICAL_SECTION();
544
545 return return_value;
546 }
547
548 PyDoc_STRVAR(set___sizeof____doc__,
549 "__sizeof__($self, /)\n"
550 "--\n"
551 "\n"
552 "S.__sizeof__() -> size of S in memory, in bytes.");
553
554 #define SET___SIZEOF___METHODDEF \
555 {"__sizeof__", (PyCFunction)set___sizeof__, METH_NOARGS, set___sizeof____doc__},
556
557 static PyObject *
558 set___sizeof___impl(PySetObject *so);
559
560 static PyObject *
set___sizeof__(PySetObject * so,PyObject * Py_UNUSED (ignored))561 set___sizeof__(PySetObject *so, PyObject *Py_UNUSED(ignored))
562 {
563 PyObject *return_value = NULL;
564
565 Py_BEGIN_CRITICAL_SECTION(so);
566 return_value = set___sizeof___impl(so);
567 Py_END_CRITICAL_SECTION();
568
569 return return_value;
570 }
571 /*[clinic end generated code: output=de4ee725bd29f758 input=a9049054013a1b77]*/
572