fix mixed declarations and code in function code generation
authorLisandro Dalcin <dalcinl@gmail.com>
Tue, 10 Nov 2009 23:48:19 +0000 (21:48 -0200)
committerLisandro Dalcin <dalcinl@gmail.com>
Tue, 10 Nov 2009 23:48:19 +0000 (21:48 -0200)
Cython/Compiler/Nodes.py

index dd9036566306045fb37c8551470edf8d3884aac8..8ee5b6c6df071b0eb8ab6f055a064f0897850237 100644 (file)
@@ -1087,10 +1087,10 @@ class FuncDefNode(StatNode, BlockNode):
             env.use_utility_code(force_init_threads_utility_code)
             code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
         # ----- Automatic lead-ins for certain special functions
-        if profile:
-            code.put_trace_call(self.entry.name, self.pos)
         if not lenv.nogil:
             code.put_setup_refcount_context(self.entry.name)
+        if profile:
+            code.put_trace_call(self.entry.name, self.pos)
         if is_getbuffer_slot:
             self.getbuffer_init(code)
         # ----- Fetch arguments
@@ -1211,18 +1211,19 @@ class FuncDefNode(StatNode, BlockNode):
             if self.return_type.is_pyobject:
                 code.put_xgiveref(self.return_type.as_pyobject(Naming.retval_cname))
 
-            code.put_finish_refcount_context()
-
         if self.entry.is_special and self.entry.name == "__hash__":
             # Returning -1 for __hash__ is supposed to signal an error
             # We do as Python instances and coerce -1 into -2. 
-            code.putln("if (unlikely(%s == -1) && !PyErr_Occurred()) %s = -2;" % (Naming.retval_cname, Naming.retval_cname))
+            code.putln("if (unlikely(%s == -1) && !PyErr_Occurred()) %s = -2;" % (
+                    Naming.retval_cname, Naming.retval_cname))
 
         if profile:
             if self.return_type.is_pyobject:
                 code.put_trace_return(Naming.retval_cname)
             else:
                 code.put_trace_return("Py_None")
+        if not lenv.nogil:
+            code.put_finish_refcount_context()
         
         if acquire_gil:
             code.putln("PyGILState_Release(_save);")
@@ -5042,7 +5043,7 @@ raise_error:
     return;
 }
 
-#else // Python 3+
+#else /* Python 3+ */
 
 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
     if (tb == Py_None) {