[Python-checkins] r78886 - in python/trunk: Lib/test/test_set.py Objects/setobject.c

victor.stinner python-checkins at python.org
Sat Mar 13 01:13:22 CET 2010


Author: victor.stinner
Date: Sat Mar 13 01:13:22 2010
New Revision: 78886
Log:
Issue #7818: set().test_c_api() doesn't expect a set('abc'), modify the set.
Modified:
 python/trunk/Lib/test/test_set.py
 python/trunk/Objects/setobject.c
Modified: python/trunk/Lib/test/test_set.py
==============================================================================
--- python/trunk/Lib/test/test_set.py	(original)
+++ python/trunk/Lib/test/test_set.py	Sat Mar 13 01:13:22 2010
@@ -562,7 +562,7 @@
 # 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
Modified: python/trunk/Objects/setobject.c
==============================================================================
--- python/trunk/Objects/setobject.c	(original)
+++ python/trunk/Objects/setobject.c	Sat Mar 13 01:13:22 2010
@@ -2387,11 +2387,25 @@
 	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);
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /