fix reference leak in the capi export function, add testcase
authorLisandro Dalcin <dalcinl@gmail.com>
Wed, 25 Feb 2009 00:31:02 +0000 (21:31 -0300)
committerLisandro Dalcin <dalcinl@gmail.com>
Wed, 25 Feb 2009 00:31:02 +0000 (21:31 -0300)
Cython/Compiler/ModuleNode.py
tests/run/capiimpl.pyx [new file with mode: 0644]

index 0e0bdf7e3540533a62ca24abcdf44740e772369e..d24dc489064cf37fa5b1f69bc535778441e99588 100644 (file)
@@ -2128,6 +2128,7 @@ static int __Pyx_ExportFunction(const char *name, void *f, const char *sig) {
         goto bad;
     if (PyDict_SetItemString(d, name, p) < 0)
         goto bad;
+    Py_DECREF(p);
     Py_DECREF(d);
     return 0;
 bad:
diff --git a/tests/run/capiimpl.pyx b/tests/run/capiimpl.pyx
new file mode 100644 (file)
index 0000000..e7ea7e2
--- /dev/null
@@ -0,0 +1,14 @@
+__doc__ = u"""
+>>> import sys
+>>> sys.getrefcount(Foo.__pyx_vtable__)
+2
+>>> sys.getrefcount(__pyx_capi__['spam'])
+2
+"""
+
+cdef public api class Foo [type FooType, object FooObject]:
+    cdef void bar(self):
+        pass
+
+cdef api void spam():
+    pass