[Python-checkins] r65638 - in python/branches/release25-maint: Lib/test/test_dict.py Misc/NEWS Objects/dictobject.c

georg.brandl python-checkins at python.org
Mon Aug 11 11:13:26 CEST 2008


Author: georg.brandl
Date: Mon Aug 11 11:13:26 2008
New Revision: 65638

Log:
- Issue #3537: Fix an assertion failure when an empty but presized dict
  object was stored in the freelist. (backport from r65637.)


Modified:
   python/branches/release25-maint/Lib/test/test_dict.py
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Objects/dictobject.c

Modified: python/branches/release25-maint/Lib/test/test_dict.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_dict.py	(original)
+++ python/branches/release25-maint/Lib/test/test_dict.py	Mon Aug 11 11:13:26 2008
@@ -454,6 +454,17 @@
         else:
             self.fail("missing KeyError")
 
+    def test_empty_presized_dict_in_freelist(self):
+        # Bug #3537: if an empty but presized dict with a size larger
+        # than 7 was in the freelist, it triggered an assertion failure
+        try:
+            d = {'a': 1/0,  'b': None, 'c': None, 'd': None, 'e': None,
+                 'f': None, 'g': None, 'h': None}
+        except ZeroDivisionError:
+            pass
+        d = {}
+
+
 
 from test import mapping_tests
 

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Mon Aug 11 11:13:26 2008
@@ -12,6 +12,9 @@
 Core and builtins
 -----------------
 
+- Issue #3537: Fix an assertion failure when an empty but presized dict
+  object was stored in the freelist.
+
 - Apply security patches from Apple.
 
 - Issue #2620: Overflow checking when allocating or reallocating memory

Modified: python/branches/release25-maint/Objects/dictobject.c
==============================================================================
--- python/branches/release25-maint/Objects/dictobject.c	(original)
+++ python/branches/release25-maint/Objects/dictobject.c	Mon Aug 11 11:13:26 2008
@@ -208,6 +208,10 @@
 		_Py_NewReference((PyObject *)mp);
 		if (mp->ma_fill) {
 			EMPTY_TO_MINSIZE(mp);
+		} else {
+			/* At least set ma_table and ma_mask; these are wrong
+			   if an empty but presized dict is added to freelist */
+			INIT_NONZERO_DICT_SLOTS(mp);
 		}
 		assert (mp->ma_used == 0);
 		assert (mp->ma_table == mp->ma_smalltable);


More information about the Python-checkins mailing list