From bddf62c2ff0718947a71a995e8b11c39a36c40ee Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Tue, 27 May 2008 13:25:28 +0200 Subject: [PATCH] Removed str conversion from SourceDescriptors in order to be more explicit. --- Cython/Compiler/Code.py | 2 +- Cython/Compiler/Errors.py | 2 +- Cython/Compiler/ModuleNode.py | 2 +- Cython/Compiler/Scanning.py | 13 ++++++++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index aead4a05..cc72cf7f 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -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 diff --git a/Cython/Compiler/Errors.py b/Cython/Compiler/Errors.py index f01feef2..7a074052 100644 --- a/Cython/Compiler/Errors.py +++ b/Cython/Compiler/Errors.py @@ -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 = "" diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index e6e09690..181ed6f3 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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) diff --git a/Cython/Compiler/Scanning.py b/Cython/Compiler/Scanning.py index 15ab7938..1474f84c 100644 --- a/Cython/Compiler/Scanning.py +++ b/Cython/Compiler/Scanning.py @@ -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 "" % self -- 2.26.2