summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-03-13 00:13:22 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-03-13 00:13:22 (GMT)
commit17d905449d485c12268ce659f0c2542cd5386e05 (patch)
treefae0c10a036300c9ffb034aa834db23a155d49d7
parentf1539bd4fc32e757e1f3bf1c7afd334dcc867628 (diff)
downloadcpython-17d905449d485c12268ce659f0c2542cd5386e05.zip
cpython-17d905449d485c12268ce659f0c2542cd5386e05.tar.gz
cpython-17d905449d485c12268ce659f0c2542cd5386e05.tar.bz2
Issue #7818: set().test_c_api() doesn't expect a set('abc'), modify the set.
-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 32f2803..808cf27 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -562,7 +562,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 af5d576..ab281af 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -2387,11 +2387,25 @@ test_c_api(PySetObject *so)
Py_ssize_t i;
PyObject *elem=NULL, *dup=NULL, *t, *f, *dup2, *x;
PyObject *ob = (PyObject *)so;
+ 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 = PyString_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);