Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[3.12] gh-110525: Cover PySet_Add corner case with frozenset objects (GH-110544) #110554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all 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
gh-110525: Cover PySet_Add corner case with frozenset objects (GH-110544
)

(cherry picked from commit ea39c87)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
  • Loading branch information
sobolevn authored and miss-islington committed Oct 9, 2023
commit de6f38f9b9d4328260faa6d6833c3db9868d23ef
37 changes: 37 additions & 0 deletions 37 Modules/_testcapi/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,41 @@ 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) {
goto error;
}
if (PySet_Add(fs, num) < 0) {
goto error;
}
int contains = PySet_Contains(fs, num);
if (contains < 0) {
goto error;
}
else if (contains == 0) {
goto unexpected;
}
Py_DECREF(fs);
Py_DECREF(num);
Py_RETURN_NONE;

unexpected:
PyErr_SetString(PyExc_ValueError, "set does not contain expected value");
error:
Py_DECREF(fs);
Py_XDECREF(num);
return NULL;
}

static PyMethodDef test_methods[] = {
{"set_check", set_check, METH_O},
{"set_checkexact", set_checkexact, METH_O},
Expand All @@ -148,6 +183,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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.