From: Dag Sverre Seljebotn Date: Sun, 18 Jan 2009 12:12:12 +0000 (+0100) Subject: refnanny: Disable in nogil functions X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fcac928210d2dea1e86f8c8636a57d56a132d4e2;p=cython.git refnanny: Disable in nogil functions --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 36932032..923da89b 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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) diff --git a/Cython/Runtime/build.sh b/Cython/Runtime/build.sh index 7fbea420..93a53099 100755 --- a/Cython/Runtime/build.sh +++ b/Cython/Runtime/build.sh @@ -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 \ diff --git a/Cython/Runtime/refnanny.pyx b/Cython/Runtime/refnanny.pyx index a56823cd..7a045b33 100644 --- a/Cython/Runtime/refnanny.pyx +++ b/Cython/Runtime/refnanny.pyx @@ -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(type); Py_DECREF(value); Py_DECREF(tb) + print "cleared!" + print (exc.PyErr_Occurred() == NULL) obj = ctx try: obj.end()