@@ -718,41 +718,48 @@ set_merge_dict(PySetObject *so, PyObject *other)
718
718
return rv ;
719
719
}
720
720
721
+ /*[clinic input]
722
+ @critical_section
723
+ set.pop
724
+
725
+ Remove and return an arbitrary set element.
726
+
727
+ Raises KeyError if the set is empty.
728
+ [clinic start generated code]*/
729
+
721
730
static PyObject *
722
- set_pop (PySetObject * so , PyObject * Py_UNUSED (ignored ))
731
+ set_pop_impl (PySetObject * self )
732
+ /*[clinic end generated code: output=bf7ef01d2a364703 input=ac7a961b15e913b9]*/
723
733
{
724
734
setentry * entry ;
725
735
setentry * limit ;
726
736
PyObject * key = NULL ;
727
737
728
738
Py_BEGIN_CRITICAL_SECTION (so );
729
739
/* Make sure the search finger is in bounds */
730
- entry = so -> table + (so -> finger & so -> mask );
731
- limit = so -> table + so -> mask ;
740
+ entry = self -> table + (self -> finger & self -> mask );
741
+ limit = self -> table + self -> mask ;
732
742
733
- if (so -> used == 0 ) {
743
+ if (self -> used == 0 ) {
734
744
PyErr_SetString (PyExc_KeyError , "pop from an empty set" );
735
745
goto exit ;
736
746
}
737
747
while (entry -> key == NULL || entry -> key == dummy ) {
738
748
entry ++ ;
739
749
if (entry > limit )
740
- entry = so -> table ;
750
+ entry = self -> table ;
741
751
}
742
752
key = entry -> key ;
743
753
entry -> key = dummy ;
744
754
entry -> hash = -1 ;
745
- so -> used -- ;
746
- so -> finger = entry - so -> table + 1 ; /* next place to start */
755
+ self -> used -- ;
756
+ self -> finger = entry - self -> table + 1 ; /* next place to start */
747
757
748
758
exit :
749
759
Py_END_CRITICAL_SECTION ();
750
760
return key ;
751
761
}
752
762
753
- PyDoc_STRVAR (pop_doc , "Remove and return an arbitrary set element.\n\
754
- Raises KeyError if the set is empty." );
755
-
756
763
static int
757
764
set_traverse (PySetObject * so , visitproc visit , void * arg )
758
765
{
@@ -2223,22 +2230,29 @@ set_discard_impl(PySetObject *self, PyObject *key)
2223
2230
Py_RETURN_NONE ;
2224
2231
}
2225
2232
2233
+ /*[clinic input]
2234
+ @critical_section
2235
+ set.__reduce__
2236
+
2237
+ [clinic start generated code]*/
2238
+
2226
2239
static PyObject *
2227
- set_reduce (PySetObject * so , PyObject * Py_UNUSED (ignored ))
2240
+ set___reduce___impl (PySetObject * self )
2241
+ /*[clinic end generated code: output=aa78615d54922c94 input=27fbb72e6ebfc2b8]*/
2228
2242
{
2229
2243
PyObject * keys = NULL , * args = NULL , * result = NULL , * state = NULL ;
2230
2244
2231
- Py_BEGIN_CRITICAL_SECTION (so );
2232
- keys = PySequence_List ((PyObject * )so );
2245
+ Py_BEGIN_CRITICAL_SECTION (self );
2246
+ keys = PySequence_List ((PyObject * )self );
2233
2247
if (keys == NULL )
2234
2248
goto done ;
2235
2249
args = PyTuple_Pack (1 , keys );
2236
2250
if (args == NULL )
2237
2251
goto done ;
2238
- state = _PyObject_GetState ((PyObject * )so );
2252
+ state = _PyObject_GetState ((PyObject * )self );
2239
2253
if (state == NULL )
2240
2254
goto done ;
2241
- result = PyTuple_Pack (3 , Py_TYPE (so ), args , state );
2255
+ result = PyTuple_Pack (3 , Py_TYPE (self ), args , state );
2242
2256
done :
2243
2257
Py_END_CRITICAL_SECTION ();
2244
2258
Py_XDECREF (args );
@@ -2334,10 +2348,8 @@ static PyMethodDef set_methods[] = {
2334
2348
issubset_doc },
2335
2349
{"issuperset" , (PyCFunction )set_issuperset , METH_O ,
2336
2350
issuperset_doc },
2337
- {"pop" , (PyCFunction )set_pop , METH_NOARGS ,
2338
- pop_doc },
2339
- {"__reduce__" , (PyCFunction )set_reduce , METH_NOARGS ,
2340
- reduce_doc },
2351
+ SET_POP_METHODDEF
2352
+ SET___REDUCE___METHODDEF
2341
2353
SET_REMOVE_METHODDEF
2342
2354
{"__sizeof__" , (PyCFunction )set_sizeof , METH_NOARGS ,
2343
2355
sizeof_doc },
@@ -2453,8 +2465,7 @@ static PyMethodDef frozenset_methods[] = {
2453
2465
issubset_doc },
2454
2466
{"issuperset" , (PyCFunction )set_issuperset , METH_O ,
2455
2467
issuperset_doc },
2456
- {"__reduce__" , (PyCFunction )set_reduce , METH_NOARGS ,
2457
- reduce_doc },
2468
+ SET___REDUCE___METHODDEF
2458
2469
{"__sizeof__" , (PyCFunction )set_sizeof , METH_NOARGS ,
2459
2470
sizeof_doc },
2460
2471
{"symmetric_difference" ,(PyCFunction )set_symmetric_difference , METH_O ,
0 commit comments