]> granicus.if.org Git - python/commitdiff
- Issue #3537: Fix an assertion failure when an empty but presized dict
authorGeorg Brandl <georg@python.org>
Mon, 11 Aug 2008 09:13:26 +0000 (09:13 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 11 Aug 2008 09:13:26 +0000 (09:13 +0000)
  object was stored in the freelist. (backport from r65637.)

Lib/test/test_dict.py
Misc/NEWS
Objects/dictobject.c

index 8da0915346c608663295622a100ae5b52cd31d2f..414469252748c94a35a3fc30f6d218cdb2f80255 100644 (file)
@@ -454,6 +454,17 @@ class DictTest(unittest.TestCase):
         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
 
index 273e294097f8fc5e3f37d7e4a53cef655afd3550..c8d45108b1d6200c623305e17749e4cd969f1af9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5.3?
 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
index 412d5f2e3154aec5d5f94ad99d25b84963abdd5c..8c8a2f92e70a8a29a3804132c06e2737da0027de 100644 (file)
@@ -208,6 +208,10 @@ PyDict_New(void)
                _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);