summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-10-10 16:00:05 (GMT)
committerGitHub <noreply@github.com>2023-10-10 16:00:05 (GMT)
commit9cfb4e0d1ebf2900c19ee07697818c621f46cc3d (patch)
treebfec6ce7faa1954718c5e90d6d921ba76c85a997 /Modules
parent66a9b1082049855889854bfde617059499c26dd2 (diff)
downloadcpython-9cfb4e0d1ebf2900c19ee07697818c621f46cc3d.zip
cpython-9cfb4e0d1ebf2900c19ee07697818c621f46cc3d.tar.gz
cpython-9cfb4e0d1ebf2900c19ee07697818c621f46cc3d.tar.bz2
gh-110525: Add tests for internal `set` CAPI (GH-110630)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/Setup.stdlib.in2
-rw-r--r--Modules/_testinternalcapi.c3
-rw-r--r--Modules/_testinternalcapi/parts.h1
-rw-r--r--Modules/_testinternalcapi/set.c59
4 files changed, 64 insertions, 1 deletions
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index 8428142..647f442 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -158,7 +158,7 @@
@MODULE_XXSUBTYPE_TRUE@xxsubtype xxsubtype.c
@MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
-@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c
+@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/pyos.c _testcapi/immortal.c _testcapi/heaptype_relative.c _testcapi/gc.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 05bac09..ddeb389 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -1602,6 +1602,9 @@ module_exec(PyObject *module)
if (_PyTestInternalCapi_Init_PyTime(module) < 0) {
return 1;
}
+ if (_PyTestInternalCapi_Init_Set(module) < 0) {
+ return 1;
+ }
if (PyModule_Add(module, "SIZEOF_PYGC_HEAD",
PyLong_FromSsize_t(sizeof(PyGC_Head))) < 0) {
diff --git a/Modules/_testinternalcapi/parts.h b/Modules/_testinternalcapi/parts.h
index bbb8e62..3d2774e 100644
--- a/Modules/_testinternalcapi/parts.h
+++ b/Modules/_testinternalcapi/parts.h
@@ -12,5 +12,6 @@
int _PyTestInternalCapi_Init_Lock(PyObject *module);
int _PyTestInternalCapi_Init_PyTime(PyObject *module);
+int _PyTestInternalCapi_Init_Set(PyObject *module);
#endif // Py_TESTINTERNALCAPI_PARTS_H
diff --git a/Modules/_testinternalcapi/set.c b/Modules/_testinternalcapi/set.c
new file mode 100644
index 0000000..0305a78
--- /dev/null
+++ b/Modules/_testinternalcapi/set.c
@@ -0,0 +1,59 @@
+#include "parts.h"
+#include "../_testcapi/util.h" // NULLABLE, RETURN_INT
+
+#include "pycore_setobject.h"
+
+
+static PyObject *
+set_update(PyObject *self, PyObject *args)
+{
+ PyObject *set, *iterable;
+ if (!PyArg_ParseTuple(args, "OO", &set, &iterable)) {
+ return NULL;
+ }
+ NULLABLE(set);
+ NULLABLE(iterable);
+ RETURN_INT(_PySet_Update(set, iterable));
+}
+
+static PyObject *
+set_next_entry(PyObject *self, PyObject *args)
+{
+ int rc;
+ Py_ssize_t pos;
+ Py_hash_t hash = (Py_hash_t)UNINITIALIZED_SIZE;
+ PyObject *set, *item = UNINITIALIZED_PTR;
+ if (!PyArg_ParseTuple(args, "On", &set, &pos)) {
+ return NULL;
+ }
+ NULLABLE(set);
+
+ rc = _PySet_NextEntry(set, &pos, &item, &hash);
+ if (rc == 1) {
+ return Py_BuildValue("innO", rc, pos, hash, item);
+ }
+ assert(item == UNINITIALIZED_PTR);
+ assert(hash == (Py_hash_t)UNINITIALIZED_SIZE);
+ if (rc == -1) {
+ return NULL;
+ }
+ assert(rc == 0);
+ Py_RETURN_NONE;
+}
+
+
+static PyMethodDef TestMethods[] = {
+ {"set_update", set_update, METH_VARARGS},
+ {"set_next_entry", set_next_entry, METH_VARARGS},
+
+ {NULL},
+};
+
+int
+_PyTestInternalCapi_Init_Set(PyObject *m)
+{
+ if (PyModule_AddFunctions(m, TestMethods) < 0) {
+ return -1;
+ }
+ return 0;
+}