summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@gmail.com>2013-01-02 14:16:19 -0800
committerRobert Bradshaw <robertwb@gmail.com>2013-01-02 14:16:19 -0800
commitb69124e057aa27d8bd90a875a5f1f366cc2d1751 (patch)
tree374f52c4172235fd3714593dc58ccbbe7205ea99
parent9a08ff23544ac9afd8392715c660898e1f3a762f (diff)
downloadcython-b69124e057aa27d8bd90a875a5f1f366cc2d1751.tar.gz
Test for trac #796.
-rw-r--r--tests/run/double_dealloc_T796.pyx43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/run/double_dealloc_T796.pyx b/tests/run/double_dealloc_T796.pyx
new file mode 100644
index 000000000..c0904aeda
--- /dev/null
+++ b/tests/run/double_dealloc_T796.pyx
@@ -0,0 +1,43 @@
+"""
+>>> x = SimpleGarbage()
+SimpleGarbage(1) __cinit__
+>>> del x
+SimpleGarbage(1) __dealloc__
+Collector.__dealloc__
+collect 0
+"""
+
+import gc, sys, weakref
+
+cdef int counter = 0
+cdef int next_counter():
+ global counter
+ counter += 1
+ return counter
+
+cdef class Collector:
+ # Indirectly trigger garbage collection in SimpleGarbage deallocation.
+ # The __dealloc__ method of SimpleGarbage won't trigger the bug as the
+ # refcount is artifitially inflated for the durration of that function.
+ def __dealloc__(self):
+ print "Collector.__dealloc__"
+ print "collect", gc.collect()
+
+cdef class SimpleGarbage:
+ cdef Collector c # to particpate in garbage collection
+ cdef int index
+ cdef bint deallocated
+ def __cinit__(self):
+ self.index = next_counter()
+ self.c = Collector()
+ print self, "__cinit__"
+ def __dealloc__(self):
+ print self, "__dealloc__"
+ if self.deallocated:
+ print "Double dealloc!"
+ self.deallocated = True
+ gc.collect()
+ def __str__(self):
+ return "SimpleGarbage(%s)" % self.index
+ def __repr__(self):
+ return "SimpleGarbage(%s)" % self.index