Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Modules/_testcapi/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,34 @@ set_clear(PyObject *self, PyObject *obj)
RETURN_INT(PySet_Clear(obj));
}

static PyObject *
test_frozenset_add_in_capi(PyObject *self, PyObject *Py_UNUSED(obj))
{
// Test that `frozenset` can be used with `PySet_Add`,
// when frozenset is just created in CAPI.
PyObject *fs = PyFrozenSet_New(NULL);
if (fs == NULL) {
return NULL;
}
PyObject *num = PyLong_FromLong(1);
if (num == NULL) {
return NULL;
}
if (PySet_Add(fs, num) < 0) {
return NULL;
}
int contains = PySet_Contains(fs, num);
Py_DECREF(num);
if (contains < 0) {
return NULL;
}
else if (contains == 0) {
PyErr_SetString(PyExc_ValueError, "set does not contain expected value");
return NULL;
}
Py_RETURN_NONE;
}

static PyMethodDef test_methods[] = {
{"set_check", set_check, METH_O},
{"set_checkexact", set_checkexact, METH_O},
Expand All @@ -148,6 +176,8 @@ static PyMethodDef test_methods[] = {
{"set_pop", set_pop, METH_O},
{"set_clear", set_clear, METH_O},

{"test_frozenset_add_in_capi", test_frozenset_add_in_capi, METH_NOARGS},

{NULL},
};

Expand Down