From 2e6bce7341a0c8699a3e8860d3ca5386dc049488 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Thu, 29 Jan 2009 18:19:54 +0100 Subject: [PATCH] refnanny --- Cython/Runtime/refnanny.pyx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Cython/Runtime/refnanny.pyx b/Cython/Runtime/refnanny.pyx index bfa7dc4d..b9c3c942 100644 --- a/Cython/Runtime/refnanny.pyx +++ b/Cython/Runtime/refnanny.pyx @@ -45,21 +45,30 @@ class RefnannyContext(object): msg += "\n Acquired on lines: " + ", ".join(["%d" % x for x in linenos]) self.errors.append("References leaked: %s" % msg) if self.errors: - print self.errors -# raise RefnannyException("\n".join(self.errors)) +# print self.errors + raise RefnannyException("\n".join(self.errors)) cdef public void* __Pyx_Refnanny_NewContext(char* funcname, int lineno) except NULL: + if exc.PyErr_Occurred() != NULL: + print "error flag set on newcontext?" + return NULL ctx = RefnannyContext() Py_INCREF(ctx) return ctx cdef public void __Pyx_Refnanny_GOTREF(void* ctx, object obj, int lineno): + cdef exc.PyObject* type, *value, *tb if ctx == NULL: return + exc.PyErr_Fetch(&type, &value, &tb) (ctx).regref(obj, lineno) + exc.PyErr_Restore(type, value, tb) cdef public void __Pyx_Refnanny_GIVEREF(void* ctx, object obj, int lineno): + cdef exc.PyObject* type, *value, *tb if ctx == NULL: return + exc.PyErr_Fetch(&type, &value, &tb) (ctx).delref(obj, lineno) + exc.PyErr_Restore(type, value, tb) cdef public void __Pyx_Refnanny_INCREF(void* ctx, object obj, int lineno): Py_INCREF(obj) @@ -72,17 +81,16 @@ 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_XDECREF(type); Py_XDECREF(value); Py_XDECREF(tb) -## print "cleared!" -## print (exc.PyErr_Occurred() == NULL) + cdef exc.PyObject* type, *value, *tb + if ctx == NULL: + assert False + exc.PyErr_Fetch(&type, &value, &tb) obj = ctx try: obj.end() finally: Py_DECREF(obj) + exc.PyErr_Restore(type, value, tb) return 0 -- 2.26.2