]> 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:07:59 +0000 (09:07 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 11 Aug 2008 09:07:59 +0000 (09:07 +0000)
  object was stored in the freelist.

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

index b62237d9d6f10f968b249f01f47e9c9222cce01c..f715657d3665bb54ea1ce0ca055aa8948d82a119 100644 (file)
@@ -544,6 +544,17 @@ class DictTest(unittest.TestCase):
         resizing = True
         d[9] = 6
 
+    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 a197efc7a0e74128f9dfdb40b55e04e2090c32f6..1c346545ba0d86e4ae786999a440f36270716234 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6 beta 3?
 Core and Builtins
 -----------------
 
+- Issue #3537: Fix an assertion failure when an empty but presized dict
+  object was stored in the freelist.
+
 - Issue #1481296: Make long(float('nan')) and int(float('nan')) raise
   ValueError consistently across platforms.
 
index 038f3738d654383d23456bf1e1fd01bdaf8ef767..cc083f171674134d713753b81ab9c321c0fee326 100644 (file)
@@ -241,6 +241,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);