Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address review
  • Loading branch information
sobolevn committed Oct 10, 2023
commit 21ca91f6fea7d6edbe8ff9765c881d146b8741a1
6 changes: 4 additions & 2 deletions Lib/test/test_capi/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,19 @@ def test_set_next_entry(self):
set_next = _testinternalcapi.set_next_entry
for cls in (set, set_subclass, frozenset, frozenset_subclass):
with self.subTest(cls=cls):
instance = cls([1, 2, 3])
instance = cls('abc')
pos = 0
items = []
while True:
res = set_next(instance, pos)
if res is None:
break
rc, pos, hash_, item = res
items.append(item)
self.assertEqual(rc, 1)
self.assertIsInstance(pos, int)
self.assertIn(item, instance)
Comment thread
sobolevn marked this conversation as resolved.
self.assertEqual(hash(item), hash_)
self.assertEqual(items, list(instance))
with self.assertRaises(SystemError):
set_next(object(), 0)
# CRASHES: set_next(NULL, 0)
5 changes: 3 additions & 2 deletions Modules/_testinternalcapi/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set_next_entry(PyObject *self, PyObject *args)
{
int rc;
Py_ssize_t pos;
Py_hash_t hash;
Py_hash_t hash = (Py_hash_t)UNINITIALIZED_SIZE;
PyObject *set, *item = UNINITIALIZED_PTR;
if (!PyArg_ParseTuple(args, "On", &set, &pos)) {
return NULL;
Expand All @@ -33,7 +33,8 @@ set_next_entry(PyObject *self, PyObject *args)
return Py_BuildValue("innO", rc, pos, hash, item);
}
assert(item == UNINITIALIZED_PTR);
Comment thread
sobolevn marked this conversation as resolved.
if (PyErr_Occurred()) {
assert(hash == (Py_hash_t)UNINITIALIZED_SIZE);
if (rc == -1) {
return NULL;
}
Py_RETURN_NONE;
Expand Down