From: Robert Bradshaw Date: Fri, 20 Feb 2009 11:33:18 +0000 (-0800) Subject: Print refnanny errors rather than raise them. X-Git-Tag: 0.11.rc~77 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=85d7fe69bc642251991031fe0e34c6e88ec16326;p=cython.git Print refnanny errors rather than raise them. --- diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index d60de603..5caeb4c2 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -1594,7 +1594,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln(" if (!__Pyx_Refnanny)") code.putln(" Py_FatalError(\"failed to import refnanny module\");") code.putln("}") - code.putln("__pyx_refchk = __Pyx_Refnanny->NewContext(\"%s\", __LINE__);"% header3) + code.putln("__pyx_refchk = __Pyx_Refnanny->NewContext(\"%s\", __LINE__, __FILE__);"% header3) code.putln("#endif") code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos))); @@ -2338,7 +2338,7 @@ typedef struct { void (*DECREF)(void*, PyObject*, int); void (*GOTREF)(void*, PyObject*, int); void (*GIVEREF)(void*, PyObject*, int); - void* (*NewContext)(const char*, int); + void* (*NewContext)(const char*, int, char*); int (*FinishContext)(void**); } __Pyx_RefnannyAPIStruct; static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL; @@ -2350,7 +2350,7 @@ static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL; #define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__) #define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r) #define __Pyx_SetupRefcountContext(name) \ - void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__) + void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__) #define __Pyx_FinishRefcountContext() \ __Pyx_Refnanny->FinishContext(&__pyx_refchk) #else diff --git a/Cython/Runtime/refnanny.pyx b/Cython/Runtime/refnanny.pyx index f02d96b0..9f5ac62e 100644 --- a/Cython/Runtime/refnanny.pyx +++ b/Cython/Runtime/refnanny.pyx @@ -15,7 +15,10 @@ class Error(Exception): pass class Context(object): - def __init__(self): + def __init__(self, name, line=0, filename=None): + self.name = name + self.start = line + self.filename = filename self.refs = {} # id -> (count, [lineno]) self.errors = [] @@ -57,11 +60,11 @@ class Context(object): -cdef PyObject* NewContext(char* funcname, int lineno) except NULL: +cdef PyObject* NewContext(char* funcname, int lineno, char* filename) except NULL: cdef PyObject* type = NULL, *value = NULL, *tb = NULL PyErr_Fetch(&type, &value, &tb) try: - ctx = Context() + ctx = Context(funcname, lineno, filename) PyErr_Restore(type, value, tb) Py_INCREF(ctx) return ctx @@ -120,6 +123,7 @@ cdef int FinishContext(PyObject** ctx) except -1: PyErr_Fetch(&type, &value, &tb) try: errors = (ctx[0]).end() + pos = (ctx[0]).filename, (ctx[0]).name PyErr_Restore(type, value, tb) except: Py_XDECREF(type) @@ -130,7 +134,8 @@ cdef int FinishContext(PyObject** ctx) except -1: Py_XDECREF(ctx[0]) ctx[0] = NULL if errors: - raise Error(errors) + print "%s: %s()" % pos + print errors # raise Error(errors) return 0 @@ -144,7 +149,7 @@ ctypedef struct RefnannyAPIStruct: void (*DECREF)(PyObject*, PyObject*, int) void (*GOTREF)(PyObject*, PyObject*, int) void (*GIVEREF)(PyObject*, PyObject*, int) - PyObject* (*NewContext)(char*, int) except NULL + PyObject* (*NewContext)(char*, int, char*) except NULL int (*FinishContext)(PyObject**) except -1 cdef RefnannyAPIStruct api