Removed str conversion from SourceDescriptors in order to be more explicit.
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 27 May 2008 11:25:28 +0000 (13:25 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 27 May 2008 11:25:28 +0000 (13:25 +0200)
Cython/Compiler/Code.py
Cython/Compiler/Errors.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Scanning.py

index aead4a0510b1cb1eb80444b45ebd19d06127b513..cc72cf7fb059913162e784df8c1519a1d929d236 100644 (file)
@@ -114,7 +114,7 @@ class CCodeWriter:
                 s = s.rstrip() + '             # <<<<<<<<<<<<<< ' + '\n'
             context += " * " + s
 
-        marker = '"%s":%d\n%s' % (str(source_desc).encode('ASCII', 'replace'), line, context)
+        marker = '"%s":%d\n%s' % (source_desc.get_description().encode('ASCII', 'replace'), line, context)
         if self.last_marker != marker:
             self.marker = marker
 
index f01feef2639fa7abac048aec600046bb9b956f3c..7a074052c4e4365497c3f31360ff6acea371f389 100644 (file)
@@ -29,7 +29,7 @@ class CompileError(PyrexError):
         self.position = position
         self.message = message
         if position:
-            pos_str = "%s:%d:%d: " % position
+            pos_str = "%s:%d:%d: " % (position[0].get_description(), position[1], position[2])
             cont = context(position)
         else:
             pos_str = ""
index e6e09690c513a8488cd23415b18793890e7103c3..181ed6f35a4c508740a9e7cd6c28392d21f41148 100644 (file)
@@ -428,7 +428,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
         code.putln("static char *%s[] = {" % Naming.filenames_cname)
         if code.filename_list:
             for source_desc in code.filename_list:
-                filename = os.path.basename(str(source_desc))
+                filename = os.path.basename(source_desc.get_filenametable_entry())
                 escaped_filename = filename.replace("\\", "\\\\").replace('"', r'\"')
                 code.putln('"%s",' % 
                     escaped_filename)
index 15ab7938c01d463c58f39f974ae2ffd903044ebc..1474f84c895d2fae4bc7c94c9837852ba590b043 100644 (file)
@@ -206,7 +206,8 @@ def initial_compile_time_env():
 #------------------------------------------------------------------
 
 class SourceDescriptor:
-    pass
+    def __str__(self):
+        assert False # To catch all places where a descriptor is used directly as a filename
 
 class FileSourceDescriptor(SourceDescriptor):
     """
@@ -230,7 +231,10 @@ class FileSourceDescriptor(SourceDescriptor):
         else:
             return open(self.filename)
     
-    def __str__(self):
+    def get_description(self):
+        return self.filename
+    
+    def get_filenametable_entry(self):
         return self.filename
     
     def __repr__(self):
@@ -248,9 +252,12 @@ class StringSourceDescriptor(SourceDescriptor):
     def get_lines(self, decode=False):
         return self.codelines
     
-    def __str__(self):
+    def get_description(self):
         return self.name
 
+    def get_filenametable_entry(self):
+        return "stringsource"
+
     def __repr__(self):
         return "<StringSourceDescriptor:%s>" % self