summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2006-04-18 13:52:32 (GMT)
committerMichael W. Hudson <mwh@python.net>2006-04-18 13:52:32 (GMT)
commit15b1f146bc2d62ac1bfb8924cf799672ac3a61fe (patch)
tree8c2c70fa4be77e7493e205d7cddca11e1468e4c5 /Lib/test
parent952f196ae7d65ce53c6f36d4be2becc5bbfa8766 (diff)
downloadcpython-15b1f146bc2d62ac1bfb8924cf799672ac3a61fe.zip
cpython-15b1f146bc2d62ac1bfb8924cf799672ac3a61fe.tar.gz
cpython-15b1f146bc2d62ac1bfb8924cf799672ac3a61fe.tar.bz2
add a very old crasher from the 2.1 -> 2.2 round of dictionary fixes.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/crashers/nasty_eq_vs_dict.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/crashers/nasty_eq_vs_dict.py b/Lib/test/crashers/nasty_eq_vs_dict.py
new file mode 100644
index 0000000..3f3083d
--- /dev/null
+++ b/Lib/test/crashers/nasty_eq_vs_dict.py
@@ -0,0 +1,47 @@
+# 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]