summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_set.py2
-rw-r--r--Objects/setobject.c16
2 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 26977d9..194bbff 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -607,7 +607,7 @@ class TestSet(TestJointOps):
# C API test only available in a debug build
if hasattr(set, "test_c_api"):
def test_c_api(self):
- self.assertEqual(set('abc').test_c_api(), True)
+ self.assertEqual(set().test_c_api(), True)
class SetSubclass(set):
pass
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 7ea8e32..c3eabf5 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -2360,11 +2360,25 @@ test_c_api(PySetObject *so)
PyObject *elem=NULL, *dup=NULL, *t, *f, *dup2, *x;
PyObject *ob = (PyObject *)so;
long hash;
+ PyObject *str;
- /* Verify preconditions and exercise type/size checks */
+ /* Verify preconditions */
assert(PyAnySet_Check(ob));
assert(PyAnySet_CheckExact(ob));
assert(!PyFrozenSet_CheckExact(ob));
+
+ /* so.clear(); so |= set("abc"); */
+ str = PyUnicode_FromString("abc");
+ if (str == NULL)
+ return NULL;
+ set_clear_internal(so);
+ if (set_update_internal(so, str) == -1) {
+ Py_DECREF(str);
+ return NULL;
+ }
+ Py_DECREF(str);
+
+ /* Exercise type/size checks */
assert(PySet_Size(ob) == 3);
assert(PySet_GET_SIZE(ob) == 3);