[Python-checkins] Fix the sizeof test for dicts with shared keys. (GH-4311) (#4312)

Serhiy Storchaka webhook-mailer at python.org
Tue Nov 7 08:59:38 EST 2017


https://github.com/python/cpython/commit/a5dca7d173f9f1d98b13939498269ce3e35b3a07
commit: a5dca7d173f9f1d98b13939498269ce3e35b3a07
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2017-11-07T15:59:33+02:00
summary:

Fix the sizeof test for dicts with shared keys. (GH-4311) (#4312)

By accident the size of the empty dict keys object matched the
size of values array.
(cherry picked from commit 39a156c505b7dc431a0a4cffcbefca577848db38)

files:
M Lib/test/test_sys.py

diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index e151f493d4e..d49e4ab6519 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -1092,6 +1092,7 @@ def delx(self): del self.__x
             fmt += '3n2P'
         s = vsize(fmt)
         check(int, s)
+        # class
         s = vsize(fmt +                 # PyTypeObject
                   '3P'                  # PyAsyncMethods
                   '36P'                 # PyNumberMethods
@@ -1099,13 +1100,17 @@ def delx(self): del self.__x
                   '10P'                 # PySequenceMethods
                   '2P'                  # PyBufferProcs
                   '4P')
-        # Separate block for PyDictKeysObject with 8 keys and 5 entries
-        s += calcsize("2nP2n") + 8 + 5*calcsize("n2P")
-        # class
         class newstyleclass(object): pass
-        check(newstyleclass, s)
+        # Separate block for PyDictKeysObject with 8 keys and 5 entries
+        check(newstyleclass, s + calcsize("2nP2n0P") + 8 + 5*calcsize("n2P"))
+        # dict with shared keys
+        check(newstyleclass().__dict__, size('nQ2P') + 5*self.P)
+        o = newstyleclass()
+        o.a = o.b = o.c = o.d = o.e = o.f = o.g = o.h = 1
+        # Separate block for PyDictKeysObject with 16 keys and 10 entries
+        check(newstyleclass, s + calcsize("2nP2n0P") + 16 + 10*calcsize("n2P"))
         # dict with shared keys
-        check(newstyleclass().__dict__, size('nQ2P' + '2nP2n'))
+        check(newstyleclass().__dict__, size('nQ2P') + 10*self.P)
         # unicode
         # each tuple contains a string and its expected character size
         # don't put any static strings here, as they may contain



More information about the Python-checkins mailing list