[Python-checkins] python/dist/src/Lib/test test_sort.py,1.12,1.13
arigo at users.sourceforge.net
arigo at users.sourceforge.net
Thu Jul 29 14:40:25 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28350/Lib/test
Modified Files:
test_sort.py
Log Message:
* drop the unreasonable list invariant that ob_item should never come back
to NULL during the lifetime of the object.
* listobject.c nevertheless did not conform to the other invariants,
either; fixed.
* listobject.c now uses list_clear() as the obvious internal way to clear
a list, instead of abusing list_ass_slice() for that. It makes it easier
to enforce the invariant about ob_item == NULL.
* listsort() sets allocated to -1 during sort; any mutation will set it
to a value >= 0, so it is a safe way to detect mutation. A negative
value for allocated does not cause a problem elsewhere currently.
test_sort.py has a new test for this fix.
* listsort() leak: if items were added to the list during the sort, AND if
these items had a __del__ that puts still more stuff into the list,
then this more stuff (and the PyObject** array to hold them) were
overridden at the end of listsort() and never released.
Index: test_sort.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_sort.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** test_sort.py 18 Jan 2004 20:29:55 -0000 1.12
--- test_sort.py 29 Jul 2004 12:40:22 -0000 1.13
***************
*** 151,154 ****
--- 151,171 ----
self.assertEqual(L, range(50))
+ def test_undetected_mutation(self):
+ # Python 2.4a1 did not always detect mutation
+ memorywaster = []
+ for i in range(20):
+ def mutating_cmp(x, y):
+ L.append(3)
+ L.pop()
+ return cmp(x, y)
+ L = [1,2]
+ self.assertRaises(ValueError, L.sort, mutating_cmp)
+ def mutating_cmp(x, y):
+ L.append(3)
+ del L[:]
+ return cmp(x, y)
+ self.assertRaises(ValueError, L.sort, mutating_cmp)
+ memorywaster = [memorywaster]
+
#==============================================================================
More information about the Python-checkins
mailing list