patch for ticket #646 by klepa: provide dedicated switches for 'c_line_in_traceback...
authorStefan Behnel <scoder@users.berlios.de>
Mon, 17 Jan 2011 16:11:55 +0000 (17:11 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 17 Jan 2011 16:11:55 +0000 (17:11 +0100)
Cython/Compiler/CmdLine.py
Cython/Compiler/Code.py
Cython/Compiler/Main.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Options.py
Cython/Distutils/build_ext.py
Cython/Distutils/extension.py

index 4cc3a971d9062bc30bfdccfee6ec9341d9e8e6f2..7b0bc390fa2de382553864fd422335fea7ef9864 100644 (file)
@@ -116,6 +116,8 @@ def parse_command_line(args):
                 Options.convert_range = True
             elif option == "--line-directives":
                 options.emit_linenums = True
+            elif option == "--no-c-in-traceback":
+                options.c_line_in_traceback = False
             elif option == "--gdb":
                 options.gdb_debug = True
                 options.output_dir = os.curdir
index 47ca0e5830f16ae69877503bd3cb1c4fe3ddb26b..41221cf8833979a76cbb6083d0cd77a278026488 100644 (file)
@@ -860,24 +860,26 @@ class CCodeWriter(object):
       coming from the same root share the same instances simultaneously.
     """
 
-    # f                file            output file
-    # buffer           StringIOTree
-
-    # level            int             indentation level
-    # bol              bool            beginning of line?
-    # marker           string          comment to emit before next line
-    # funcstate        FunctionState   contains state local to a C function used for code
-    #                                  generation (labels and temps state etc.)
-    # globalstate      GlobalState     contains state global for a C file (input file info,
-    #                                  utility code, declared constants etc.)
-    # emit_linenums    boolean         whether or not to write #line pragmas
+    # f                   file            output file
+    # buffer              StringIOTree
+
+    # level               int             indentation level
+    # bol                 bool            beginning of line?
+    # marker              string          comment to emit before next line
+    # funcstate           FunctionState   contains state local to a C function used for code
+    #                                     generation (labels and temps state etc.)
+    # globalstate         GlobalState     contains state global for a C file (input file info,
+    #                                     utility code, declared constants etc.)
+    # emit_linenums       boolean         whether or not to write #line pragmas
     #
-    # pyclass_stack    list            used during recursive code generation to pass information
-    #                                  about the current class one is in
+    # c_line_in_traceback boolean         append the c file and line number to the traceback for exceptions
+    #
+    # pyclass_stack       list            used during recursive code generation to pass information
+    #                                     about the current class one is in
 
     globalstate = None
 
-    def __init__(self, create_from=None, buffer=None, copy_formatting=False, emit_linenums=None):
+    def __init__(self, create_from=None, buffer=None, copy_formatting=False, emit_linenums=None, c_line_in_traceback=True):
         if buffer is None: buffer = StringIOTree()
         self.buffer = buffer
         self.marker = None
@@ -902,11 +904,12 @@ class CCodeWriter(object):
             self.emit_linenums = self.globalstate.emit_linenums
         else:
             self.emit_linenums = emit_linenums
+        self.c_line_in_traceback = c_line_in_traceback
 
     def create_new(self, create_from, buffer, copy_formatting):
         # polymorphic constructor -- very slightly more versatile
         # than using __class__
-        result = CCodeWriter(create_from, buffer, copy_formatting)
+        result = CCodeWriter(create_from, buffer, copy_formatting, c_line_in_traceback=self.c_line_in_traceback)
         return result
 
     def copyto(self, f):
@@ -935,7 +938,7 @@ class CCodeWriter(object):
         Creates a new CCodeWriter connected to the same global state, which
         can later be inserted using insert.
         """
-        return CCodeWriter(create_from=self)
+        return CCodeWriter(create_from=self, c_line_in_traceback=self.c_line_in_traceback)
 
     def insert(self, writer):
         """
@@ -1319,7 +1322,7 @@ class CCodeWriter(object):
         return self.putln("if (%s < 0) %s" % (value, self.error_goto(pos)))
 
     def set_error_info(self, pos):
-        if Options.c_line_in_traceback:
+        if self.c_line_in_traceback:
             cinfo = " %s = %s;" % (Naming.clineno_cname, Naming.line_c_macro)
         else:
             cinfo = ""
index 539d2ef9241fc46b3d490e42550525639848fbda..c20d7a7c5af931c0177545d47e5aa11d6ab8ec3c 100644 (file)
@@ -837,6 +837,7 @@ default_options = dict(
     evaluate_tree_assertions = False,
     emit_linenums = False,
     relative_path_in_code_position_comments = True,
+    c_line_in_traceback = True,
     language_level = 2,
     gdb_debug = False,
 )
index ceb618822404ef1d57a2ab73ca2eda72f1f2bc06..7d90bc8aeaff8830b74580cd8850fd3a768fa8a4 100644 (file)
@@ -258,7 +258,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
             rootwriter = Annotate.AnnotationCCodeWriter()
         else:
             emit_linenums = options.emit_linenums
-            rootwriter = Code.CCodeWriter(emit_linenums=emit_linenums)
+            rootwriter = Code.CCodeWriter(emit_linenums=emit_linenums, c_line_in_traceback=options.c_line_in_traceback)
         globalstate = Code.GlobalState(rootwriter, emit_linenums)
         globalstate.initialize_main_c_code()
         h_code = globalstate['h_code']
index 5ed89b85640b03874e0a620784bec16309866abe..4068db7d1d593aa5a95a3c95d0fe8ce16cdcb1aa 100644 (file)
@@ -43,9 +43,6 @@ lookup_module_cpdef = 0
 # WARNING: This is a work in progress, may currently segfault.
 init_local_none = 1
 
-# Append the c file and line number to the traceback for exceptions.
-c_line_in_traceback = 1
-
 # Whether or not to embed the Python interpreter, for use in making a
 # standalone executable. This will provide a main() method which simply
 # executes the body of this module.
index 94673633a87a78f87b4bfe39b2b8e91954fe6530..4b07fbdfaf9edbf09163de78f01a4b240d8e295e 100644 (file)
@@ -110,6 +110,7 @@ class build_ext(_build_ext.build_ext):
         self.pyrex_c_in_temp = 0
         self.pyrex_gen_pxi = 0
         self.pyrex_gdb = False
+        self.no_c_in_traceback = 0
 
     def finalize_options (self):
         _build_ext.build_ext.finalize_options(self)
@@ -185,6 +186,8 @@ class build_ext(_build_ext.build_ext):
             getattr(extension, 'pyrex_create_listing', 0)
         line_directives = self.pyrex_line_directives or \
             getattr(extension, 'pyrex_line_directives', 0)
+        no_c_in_traceback = self.no_c_in_traceback or \
+            getattr(extension, 'no_c_in_traceback', 0)
         cplus = self.pyrex_cplus or getattr(extension, 'pyrex_cplus', 0) or \
                 (extension.language and extension.language.lower() == 'c++')
         pyrex_gen_pxi = self.pyrex_gen_pxi or getattr(extension, 'pyrex_gen_pxi', 0)
@@ -274,6 +277,7 @@ class build_ext(_build_ext.build_ext):
                     output_file = target,
                     cplus = cplus,
                     emit_linenums = line_directives,
+                    c_line_in_traceback = not no_c_in_traceback,
                     generate_pxi = pyrex_gen_pxi,
                     output_dir = output_dir,
                     gdb_debug = pyrex_gdb)
index 05528917e571ae7dc7227df8728ad4e5032e25c4..52beb8ff2a8a25c4456e365981ae27a583989933 100644 (file)
@@ -33,6 +33,8 @@ class Extension(_Extension.Extension):
         generate .pxi file for public declarations
     pyrex_gdb : boolean
         generate Cython debug information for this extension for cygdb
+    no_c_in_traceback : boolean
+        emit the c file and line number from the traceback for exceptions
     """
 
     # When adding arguments to this constructor, be sure to update
@@ -59,6 +61,7 @@ class Extension(_Extension.Extension):
             pyrex_c_in_temp = 0,
             pyrex_gen_pxi = 0,
             pyrex_gdb = False,
+            no_c_in_traceback = False,
             **kw):
 
         _Extension.Extension.__init__(self, name, sources,
@@ -85,6 +88,7 @@ class Extension(_Extension.Extension):
         self.pyrex_c_in_temp = pyrex_c_in_temp
         self.pyrex_gen_pxi = pyrex_gen_pxi
         self.pyrex_gdb = pyrex_gdb
+        self.no_c_in_traceback = no_c_in_traceback
 
 # class Extension