diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2012-03-06 00:03:13 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2012-03-06 00:03:13 (GMT) |
commit | 198b291df7ae66d507849d92ddb6588a630fb71c (patch) | |
tree | 9f168ad6e96b6bc9c372dedddafe1f07973c0999 /Lib/test/crashers | |
parent | b2c7cca0cfda2836ff4ef222bb23ff07a79600fd (diff) | |
download | cpython-198b291df7ae66d507849d92ddb6588a630fb71c.zip cpython-198b291df7ae66d507849d92ddb6588a630fb71c.tar.gz cpython-198b291df7ae66d507849d92ddb6588a630fb71c.tar.bz2 |
Close #14205: dict lookup raises a RuntimeError if the dict is modified during
a lookup.
"if you want to make a sandbox on top of CPython, you have to fix segfaults"
so let's fix segfaults!
Diffstat (limited to 'Lib/test/crashers')
-rw-r--r-- | Lib/test/crashers/nasty_eq_vs_dict.py | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/Lib/test/crashers/nasty_eq_vs_dict.py b/Lib/test/crashers/nasty_eq_vs_dict.py deleted file mode 100644 index 85f7caf..0000000 --- a/Lib/test/crashers/nasty_eq_vs_dict.py +++ /dev/null @@ -1,47 +0,0 @@ -# from http://mail.python.org/pipermail/python-dev/2001-June/015239.html - -# if you keep changing a dictionary while looking up a key, you can -# provoke an infinite recursion in C - -# At the time neither Tim nor Michael could be bothered to think of a -# way to fix it. - -class Yuck: - def __init__(self): - self.i = 0 - - def make_dangerous(self): - self.i = 1 - - def __hash__(self): - # direct to slot 4 in table of size 8; slot 12 when size 16 - return 4 + 8 - - def __eq__(self, other): - if self.i == 0: - # leave dict alone - pass - elif self.i == 1: - # fiddle to 16 slots - self.__fill_dict(6) - self.i = 2 - else: - # fiddle to 8 slots - self.__fill_dict(4) - self.i = 1 - - return 1 - - def __fill_dict(self, n): - self.i = 0 - dict.clear() - for i in range(n): - dict[i] = i - dict[self] = "OK!" - -y = Yuck() -dict = {y: "OK!"} - -z = Yuck() -y.make_dangerous() -print(dict[z]) |