From: Robert Bradshaw Date: Sun, 30 Mar 2008 11:04:13 +0000 (-0700) Subject: c line numbers optional X-Git-Tag: 0.9.6.14~29^2~7 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fc3173808012d168d476033fc6547e183d6aaae4;p=cython.git c line numbers optional --- diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index ad4c22c1..557a6043 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -329,14 +329,17 @@ class CCodeWriter: def error_goto(self, pos): lbl = self.error_label self.use_label(lbl) - return "{%s = %s[%s]; %s = %s; %s = %s; goto %s;}" % ( + if Options.c_line_in_traceback: + cinfo = "%s = %s;" % (Naming.clineno_cname, Naming.line_c_macro) + else: + cinfo = "" + return "{%s = %s[%s]; %s = %s; %s goto %s;}" % ( Naming.filename_cname, Naming.filetable_cname, self.lookup_filename(pos[0]), Naming.lineno_cname, pos[1], - Naming.clineno_cname, - Naming.line_c_macro, + cinfo, lbl) def error_goto_if(self, cond, pos): diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 29e2343b..fa35df5d 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -1428,7 +1428,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("return;") code.put_label(code.error_label) code.put_var_xdecrefs(env.temp_entries) - code.putln('__Pyx_AddTraceback("%s",%s,%s);' % (env.qualified_name,Naming.cfilenm_cname,Naming.clineno_cname)) + code.putln('__Pyx_AddTraceback("%s");' % env.qualified_name) env.use_utility_code(Nodes.traceback_utility_code) code.putln('}') @@ -1449,7 +1449,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("return;") code.put_label(code.error_label) code.put_var_xdecrefs(env.temp_entries) - code.putln('__Pyx_AddTraceback("%s",%s,%s);' % (env.qualified_name,Naming.cfilenm_cname,Naming.clineno_cname)) + code.putln('__Pyx_AddTraceback("%s");' % env.qualified_name) env.use_utility_code(Nodes.traceback_utility_code) code.putln('}') diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index fb1b9845..0ff2983b 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -884,9 +884,7 @@ class FuncDefNode(StatNode, BlockNode): err_val = self.error_value() exc_check = self.caller_will_check_exceptions() if err_val is not None or exc_check: - code.putln( - '__Pyx_AddTraceback("%s",%s,%s);' % - (self.entry.qualified_name,Naming.cfilenm_cname,Naming.clineno_cname)) + code.putln('__Pyx_AddTraceback("%s");' % self.entry.qualified_name) if err_val is not None: code.putln( "%s = %s;" % ( @@ -3276,8 +3274,7 @@ class ExceptClauseNode(Node): else: code.putln( "/*except:*/ {") - code.putln( - '__Pyx_AddTraceback("%s",%s,%s);' % (self.function_name, Naming.cfilenm_cname,Naming.clineno_cname)) + code.putln('__Pyx_AddTraceback("%s");' % self.function_name) # We always have to fetch the exception value even if # there is no target, because this also normalises the # exception and stores it in the thread state. @@ -4095,13 +4092,13 @@ static void __Pyx_WriteUnraisable(char *name) { traceback_utility_code = [ """ -static void __Pyx_AddTraceback(char *funcname, char* cfilename, unsigned int cfileline); /*proto*/ +static void __Pyx_AddTraceback(char *funcname); /*proto*/ """,""" #include "compile.h" #include "frameobject.h" #include "traceback.h" -static void __Pyx_AddTraceback(char *funcname, char* cfilename, unsigned int cfileline) { +static void __Pyx_AddTraceback(char *funcname) { PyObject *py_srcfile = 0; PyObject *py_funcname = 0; PyObject *py_globals = 0; @@ -4111,7 +4108,12 @@ static void __Pyx_AddTraceback(char *funcname, char* cfilename, unsigned int cfi py_srcfile = PyString_FromString(%(FILENAME)s); if (!py_srcfile) goto bad; - py_funcname = PyString_FromFormat( "%%s, %%s, %%u", funcname, cfilename, cfileline); + if (%(CLINENO)s) { + py_funcname = PyString_FromFormat( "%%s (%%s:%%u)", funcname, %(CFILENAME)s, %(CLINENO)s); + } + else { + py_funcname = PyString_FromString(funcname); + } if (!py_funcname) goto bad; py_globals = PyModule_GetDict(%(GLOBALS)s); if (!py_globals) goto bad; @@ -4153,6 +4155,8 @@ bad: """ % { 'FILENAME': Naming.filename_cname, 'LINENO': Naming.lineno_cname, + 'CFILENAME': Naming.cfilenm_cname, + 'CLINENO': Naming.clineno_cname, 'GLOBALS': Naming.module_cname, 'EMPTY_TUPLE' : Naming.empty_tuple, }] diff --git a/Cython/Compiler/Options.py b/Cython/Compiler/Options.py index 0b029f90..3a999d5d 100644 --- a/Cython/Compiler/Options.py +++ b/Cython/Compiler/Options.py @@ -50,3 +50,6 @@ init_local_none = 1 # calling conventions. These are faster calling conventions, but disallow the use of # keywords (which, admittedly, are of little use in these cases). optimize_simple_methods = 1 + +# Append the c file and line number to the traceback for exceptions. +c_line_in_traceback = 1