Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39a156c

Browse files
Fix the sizeof test for dicts with shared keys. (#4311)
By accident the size of the empty dict keys object matched the size of values array.
1 parent a935654 commit 39a156c

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

Lib/test/test_sys.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,20 +1074,25 @@ def delx(self): del self.__x
10741074
fmt += '3n2P'
10751075
s = vsize(fmt)
10761076
check(int, s)
1077+
# class
10771078
s = vsize(fmt + # PyTypeObject
10781079
'3P' # PyAsyncMethods
10791080
'36P' # PyNumberMethods
10801081
'3P' # PyMappingMethods
10811082
'10P' # PySequenceMethods
10821083
'2P' # PyBufferProcs
10831084
'4P')
1084-
# Separate block for PyDictKeysObject with 8 keys and 5 entries
1085-
s += calcsize("2nP2n") + 8 + 5*calcsize("n2P")
1086-
# class
10871085
class newstyleclass(object): pass
1088-
check(newstyleclass, s)
1086+
# Separate block for PyDictKeysObject with 8 keys and 5 entries
1087+
check(newstyleclass, s + calcsize("2nP2n0P") + 8 + 5*calcsize("n2P"))
1088+
# dict with shared keys
1089+
check(newstyleclass().__dict__, size('nQ2P') + 5*self.P)
1090+
o = newstyleclass()
1091+
o.a = o.b = o.c = o.d = o.e = o.f = o.g = o.h = 1
1092+
# Separate block for PyDictKeysObject with 16 keys and 10 entries
1093+
check(newstyleclass, s + calcsize("2nP2n0P") + 16 + 10*calcsize("n2P"))
10891094
# dict with shared keys
1090-
check(newstyleclass().__dict__, size('nQ2P' + '2nP2n'))
1095+
check(newstyleclass().__dict__, size('nQ2P') + 10*self.P)
10911096
# unicode
10921097
# each tuple contains a string and its expected character size
10931098
# don't put any static strings here, as they may contain

0 commit comments

Comments
 (0)