summaryrefslogtreecommitdiff
path: root/src/python/stdlib/test/crashers/mutation_inside_cyclegc.py
diff options
context:
space:
mode:
authorSimon <simon@hardwired.org.uk>2011-03-22 17:58:52 (GMT)
committer Simon <simon@hardwired.org.uk>2011-03-22 17:58:52 (GMT)
commit2e401babb793238564ca640fc802a52ab7f6c293 (patch)
tree87a9b471e82604e76f96d556f5771322fb31818a /src/python/stdlib/test/crashers/mutation_inside_cyclegc.py
parentc096b2b14a200a0cc0a08cfea839c9e7f4edf22e (diff)
parent04a9cbcb8855e64db660a8c6e23d79114b4afd83 (diff)
downloadpowder-2e401babb793238564ca640fc802a52ab7f6c293.zip
powder-2e401babb793238564ca640fc802a52ab7f6c293.tar.gz
Python console
Diffstat (limited to 'src/python/stdlib/test/crashers/mutation_inside_cyclegc.py')
-rw-r--r--src/python/stdlib/test/crashers/mutation_inside_cyclegc.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/python/stdlib/test/crashers/mutation_inside_cyclegc.py b/src/python/stdlib/test/crashers/mutation_inside_cyclegc.py
new file mode 100644
index 0000000..2b67398
--- /dev/null
+++ b/src/python/stdlib/test/crashers/mutation_inside_cyclegc.py
@@ -0,0 +1,31 @@
+
+# The cycle GC collector can be executed when any GC-tracked object is
+# allocated, e.g. during a call to PyList_New(), PyDict_New(), ...
+# Moreover, it can invoke arbitrary Python code via a weakref callback.
+# This means that there are many places in the source where an arbitrary
+# mutation could unexpectedly occur.
+
+# The example below shows list_slice() not expecting the call to
+# PyList_New to mutate the input list. (Of course there are many
+# more examples like this one.)
+
+
+import weakref
+
+class A(object):
+ pass
+
+def callback(x):
+ del lst[:]
+
+
+keepalive = []
+
+for i in range(100):
+ lst = [str(i)]
+ a = A()
+ a.cycle = a
+ keepalive.append(weakref.ref(a, callback))
+ del a
+ while lst:
+ keepalive.append(lst[:])