refnanny: Disable in nogil functions
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Sun, 18 Jan 2009 12:12:12 +0000 (13:12 +0100)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Sun, 18 Jan 2009 12:12:12 +0000 (13:12 +0100)
Cython/Compiler/Nodes.py
Cython/Runtime/build.sh
Cython/Runtime/refnanny.pyx

index 3693203200582677e7de97b3c540f1c6333f336e..923da89b46d6c8e073bcc05842cb1f85090e341e 100644 (file)
@@ -1068,7 +1068,8 @@ class FuncDefNode(StatNode, BlockNode):
         # ----- Automatic lead-ins for certain special functions
         if is_getbuffer_slot:
             self.getbuffer_init(code)
-        code.put_setup_refcount_context(self.entry.name)
+        if not lenv.nogil:
+            code.put_setup_refcount_context(self.entry.name)
         # ----- Fetch arguments
         self.generate_argument_parsing_code(env, code)
         # If an argument is assigned to in the body, we must 
@@ -1183,17 +1184,18 @@ class FuncDefNode(StatNode, BlockNode):
         # code.putln("/* TODO: decref scope object */")
         # ----- Return
         # This code is duplicated in ModuleNode.generate_module_init_func
-        default_retval = self.return_type.default_value
-        err_val = self.error_value()
-        if err_val is None and default_retval:
-            err_val = default_retval
-        if self.return_type.is_pyobject:
-            code.put_xgiveref(self.return_type.as_pyobject(Naming.retval_cname))
+        if not lenv.nogil:
+            default_retval = self.return_type.default_value
+            err_val = self.error_value()
+            if err_val is None and default_retval:
+                err_val = default_retval
+            if self.return_type.is_pyobject:
+                code.put_xgiveref(self.return_type.as_pyobject(Naming.retval_cname))
 
-        code.put_finish_refcount_context(self.pos,
-                                         self.entry.qualified_name,
-                                         Naming.retval_cname,
-                                         err_val)
+            code.put_finish_refcount_context(self.pos,
+                                             self.entry.qualified_name,
+                                             Naming.retval_cname,
+                                             err_val)
 
         if not self.return_type.is_void:
             code.putln("return %s;" % Naming.retval_cname)
index 7fbea4200f60877c02a6b94bcc177c6de9948f41..93a53099eeb4a1d7ab783d367823852ff97ab235 100755 (executable)
@@ -1,7 +1,8 @@
 # Temporary hacky script, should be replaced
 # with distutils-based solution.
 
-PYTHONINC=/local/include/python2.5
+#PYTHONINC=/local/include/python2.5
+PYTHONINC=/usr/include/python2.5
 
 python ../../cython.py refnanny.pyx
 gcc -shared -pthread -fPIC -fwrapv -O2 -Wall \
index a56823cd7154ed5cbd35bf168f29cbe2d7f85db7..7a045b33e8731c8f6a9d0149dca2d33e6ab7448d 100644 (file)
@@ -1,4 +1,6 @@
 from python_ref cimport Py_INCREF, Py_DECREF
+cimport python_exc as exc
+
 
 loglevel = 0
 reflog = []
@@ -69,6 +71,12 @@ cdef public void __Pyx_Refnanny_DECREF(void* ctx, object obj, int lineno):
     Py_DECREF(obj)
     
 cdef public int __Pyx_Refnanny_FinishContext(void* ctx) except -1:
+    cdef exc.PyObject* type, *value, *tb
+    if exc.PyErr_Occurred():
+        exc.PyErr_Fetch(&type, &value, &tb)
+        Py_DECREF(<object>type); Py_DECREF(<object>value); Py_DECREF(<object>tb)
+        print "cleared!"
+        print (exc.PyErr_Occurred() == NULL)
     obj = <object>ctx
     try:
         obj.end()