mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00

dictresize() was too aggressive about never ever resizing small dicts. If a small dict is entirely full, it needs to rebuild it despite that it won't actually resize it, in order to purge old dummy entries thus creating at least one virgin slot (lookdict assumes at least one such exists). Also took the opportunity to add some high-level comments to dictresize.
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
# Python test set -- part 3, built-in operations.
|
|
|
|
|
|
print '3. Operations'
|
|
print 'XXX Mostly not yet implemented'
|
|
|
|
|
|
print '3.1 Dictionary lookups succeed even if __cmp__() raises an exception'
|
|
|
|
# SourceForge bug #112558:
|
|
# http://sourceforge.net/bugs/?func=detailbug&bug_id=112558&group_id=5470
|
|
|
|
class BadDictKey:
|
|
def __hash__(self):
|
|
return hash(self.__class__)
|
|
|
|
def __cmp__(self, other):
|
|
if isinstance(other, self.__class__):
|
|
print "raising error"
|
|
raise RuntimeError, "gotcha"
|
|
return other
|
|
|
|
d = {}
|
|
x1 = BadDictKey()
|
|
x2 = BadDictKey()
|
|
d[x1] = 1
|
|
d[x2] = 2
|
|
print "No exception passed through."
|
|
|
|
# Dict resizing bug, found by Jack Jansen in 2.2 CVS development.
|
|
# This version got an assert failure in debug build, infinite loop in
|
|
# release build. Unfortunately, provoking this kind of stuff requires
|
|
# a mix of inserts and deletes hitting exactly the right hash codes in
|
|
# exactly the right order, and I can't think of a randomized approach
|
|
# that would be *likely* to hit a failing case in reasonable time.
|
|
|
|
d = {}
|
|
for i in range(5):
|
|
d[i] = i
|
|
for i in range(5):
|
|
del d[i]
|
|
for i in range(5, 9): # i==8 was the problem
|
|
d[i] = i
|