added a test to check that the object refcount is not incremented in C-
authorbryancole <none@none>
Mon, 8 Mar 2010 21:39:06 +0000 (21:39 +0000)
committerbryancole <none@none>
Mon, 8 Mar 2010 21:39:06 +0000 (21:39 +0000)
methods.
Also exercises the nogil label.

tests/run/refcount_in_meth.pyx [new file with mode: 0644]

diff --git a/tests/run/refcount_in_meth.pyx b/tests/run/refcount_in_meth.pyx
new file mode 100644 (file)
index 0000000..88c7d89
--- /dev/null
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+__doc__=u"""
+>>> t = RefCountInMeth()
+>>> t.chk_meth()
+True
+>>> t.chk_nogil()
+True
+>>> t.chk_meth_if()
+True
+>>> t.chk_nogil_if()
+True
+"""
+
+import sys
+
+cdef class RefCountInMeth(object):
+    cdef double value
+
+    def __cinit__(self):
+        self.value = 1.5
+
+    cdef double c_get_value(self) nogil:
+        return self.value
+
+    cdef double c_get_value_if(self) nogil:
+        cdef double v
+        if 9>4:
+            v = 2.3
+        return self.value
+
+    cdef int c_meth(self):
+        cdef int v
+
+        v = sys.getrefcount(self)
+        return v
+
+    cdef int c_meth_if(self):
+        cdef int v
+        if 5>6:
+            v = 7
+        v = sys.getrefcount(self)
+        return v
+
+    def chk_meth(self):
+        cdef int a,b
+
+        a = sys.getrefcount(self)
+        b = self.c_meth()
+        return a==b
+
+    def chk_meth_if(self):
+        cdef int a,b
+
+        a = sys.getrefcount(self)
+        b = self.c_meth_if()
+        return a==b
+
+    def chk_nogil(self):
+        cdef double v
+        v = self.c_get_value()
+        return v==self.value
+
+    def chk_nogil_if(self):
+        cdef double v
+        v = self.c_get_value_if()
+        return v==self.value
+