mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
SF patch 637176: list.sort crasher
Armin Rigo's Draconian but effective fix for SF bug 453523: list.sort crasher slightly fiddled to catch more cases of list mutation. The dreaded internal "immutable list type" is gone! OTOH, if you look at a list *while* it's being sorted now, it will appear to be empty. Better than a core dump.
This commit is contained in:
parent
4b9ed2f346
commit
b9099c3df4
5 changed files with 78 additions and 100 deletions
|
@ -116,6 +116,35 @@ for n in sizes:
|
|||
x = [e for e, i in augmented] # a stable sort of s
|
||||
check("stability", x, s)
|
||||
|
||||
def bug453523():
|
||||
global nerrors
|
||||
from random import random
|
||||
|
||||
# If this fails, the most likely outcome is a core dump.
|
||||
if verbose:
|
||||
print "Testing bug 453523 -- list.sort() crasher."
|
||||
|
||||
class C:
|
||||
def __lt__(self, other):
|
||||
if L and random() < 0.75:
|
||||
pop()
|
||||
else:
|
||||
push(3)
|
||||
return random() < 0.5
|
||||
|
||||
L = [C() for i in range(50)]
|
||||
pop = L.pop
|
||||
push = L.append
|
||||
try:
|
||||
L.sort()
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
print " Mutation during list.sort() wasn't caught."
|
||||
nerrors += 1
|
||||
|
||||
bug453523()
|
||||
|
||||
if nerrors:
|
||||
print "Test failed", nerrors
|
||||
elif verbose:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue