Commit fc317380 authored by Robert Bradshaw's avatar Robert Bradshaw

c line numbers optional

parent 9f9b8b4c
......@@ -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):
......
......@@ -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('}')
......
......@@ -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,
}]
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment