|
| 1 | +#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) |
| 2 | + // Need limited C API for METH_FASTCALL |
| 3 | + #define Py_LIMITED_API 0x030d0000 |
| 4 | +#endif |
| 5 | + |
1 | 6 | #include "parts.h" |
2 | 7 | #include "util.h" |
3 | 8 |
|
| 9 | + |
4 | 10 | static PyObject * |
5 | 11 | set_check(PyObject *self, PyObject *obj) |
6 | 12 | { |
@@ -202,12 +208,15 @@ test_set_contains_does_not_convert_unhashable_key(PyObject *self, PyObject *Py_U |
202 | 208 |
|
203 | 209 | // Interface to PySet_Add, returning the set |
204 | 210 | static PyObject * |
205 | | -pyset_add(PyObject *self, PyObject *args) |
| 211 | +pyset_add(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
206 | 212 | { |
207 | | - PyObject *set, *item; |
208 | | - if (!PyArg_ParseTuple(args, "OO", &set, &item)) { |
| 213 | + if (nargs != 2) { |
| 214 | + PyErr_SetString(PyExc_TypeError, |
| 215 | + "pyset_add requires exactly 2 arguments"); |
209 | 216 | return NULL; |
210 | 217 | } |
| 218 | + PyObject *set = args[0]; |
| 219 | + PyObject *item = args[1]; |
211 | 220 |
|
212 | 221 | int return_value = PySet_Add(set, item); |
213 | 222 | if (return_value < 0) { |
@@ -237,7 +246,7 @@ static PyMethodDef test_methods[] = { |
237 | 246 | {"test_frozenset_add_in_capi", test_frozenset_add_in_capi, METH_NOARGS}, |
238 | 247 | {"test_set_contains_does_not_convert_unhashable_key", |
239 | 248 | test_set_contains_does_not_convert_unhashable_key, METH_NOARGS}, |
240 | | - {"pyset_add", pyset_add, METH_VARARGS}, |
| 249 | + {"pyset_add", _PyCFunction_CAST(pyset_add), METH_FASTCALL}, |
241 | 250 |
|
242 | 251 | {NULL}, |
243 | 252 | }; |
|
0 commit comments