1 #include "parts.h"
2 #include "../_testcapi/util.h" // NULLABLE, RETURN_INT
3
4 #include "pycore_critical_section.h"
5 #include "pycore_setobject.h"
6
7
8 static PyObject *
set_update(PyObject * self,PyObject * args)9 set_update(PyObject *self, PyObject *args)
10 {
11 PyObject *set, *iterable;
12 if (!PyArg_ParseTuple(args, "OO", &set, &iterable)) {
13 return NULL;
14 }
15 NULLABLE(set);
16 NULLABLE(iterable);
17 RETURN_INT(_PySet_Update(set, iterable));
18 }
19
20 static PyObject *
set_next_entry(PyObject * self,PyObject * args)21 set_next_entry(PyObject *self, PyObject *args)
22 {
23 int rc;
24 Py_ssize_t pos;
25 Py_hash_t hash = (Py_hash_t)UNINITIALIZED_SIZE;
26 PyObject *set, *item = UNINITIALIZED_PTR;
27 if (!PyArg_ParseTuple(args, "On", &set, &pos)) {
28 return NULL;
29 }
30 NULLABLE(set);
31 Py_BEGIN_CRITICAL_SECTION(set);
32 rc = _PySet_NextEntryRef(set, &pos, &item, &hash);
33 Py_END_CRITICAL_SECTION();
34 if (rc == 1) {
35 PyObject *ret = Py_BuildValue("innO", rc, pos, hash, item);
36 Py_DECREF(item);
37 return ret;
38 }
39 assert(item == UNINITIALIZED_PTR);
40 assert(hash == (Py_hash_t)UNINITIALIZED_SIZE);
41 if (rc == -1) {
42 return NULL;
43 }
44 assert(rc == 0);
45 Py_RETURN_NONE;
46 }
47
48
49 static PyMethodDef TestMethods[] = {
50 {"set_update", set_update, METH_VARARGS},
51 {"set_next_entry", set_next_entry, METH_VARARGS},
52
53 {NULL},
54 };
55
56 int
_PyTestInternalCapi_Init_Set(PyObject * m)57 _PyTestInternalCapi_Init_Set(PyObject *m)
58 {
59 if (PyModule_AddFunctions(m, TestMethods) < 0) {
60 return -1;
61 }
62 return 0;
63 }
64