Martin, I've been getting very annoyed with Pyrex because if you put a "cdef extern" in one file (say a pxi file), e.g., to define size_t, and put the same in another pxi file, then you can't import both pxi files. Sometimes you might want just one, sometimes just the other, and sometimes both (e.g., with cdefs.pxi and stdsage.pxi). So I've modified Pyrex to only emit a warning instead of an error if you multiply declare something. This is necessary because Pyrex has no analogue of "#ifndef".
To keep track of what's happening with Syrex = (SAGE Pyrex), I've created an hg repository in the Pyrex subdirectory of the pyrex spkg. The repository starts with the plain vanilla Pyrex from April. Then it has all the Python 2.5 stuff. And there's a patch for this multiple include stuff. At least by putting everything under HG we'll very easily be able to keep track of what we've added to Pyrex, and also we'll be able to more easily merge our version with whatever the next version is (that Greg releases). William # HG changeset patch # User William Stein <[EMAIL PROTECTED]> # Date 1161482014 25200 # Node ID bc0cd828b4cd6c523779baf927a797c808bf69e1 # Parent 3d8ba7d930b9f3c94c14c136fbe867254dd5147a Added a "Warning" class, and changed it so redeclaring or re-importing is a warning rather than an error. Because Pyrex has no #ifndef macro, it is impossibly painful to use pxi files for declarations in a large project. SAGE is a large project. Also, in Python it is not an error to import a module twice. Thus more in line with Python's behavior, multiple declarations of the same symbol is no longer an error. diff -r 3d8ba7d930b9 -r bc0cd828b4cd Compiler/Errors.py --- a/Compiler/Errors.py Thu Oct 19 21:30:50 2006 -0700 +++ b/Compiler/Errors.py Sat Oct 21 18:53:34 2006 -0700 @@ -9,8 +9,21 @@ class PyrexError(Exception): class PyrexError(Exception): pass +class PyrexWarning(Exception): + pass class CompileError(PyrexError): + + def __init__(self, position = None, message = ""): + self.position = position + self.message = message + if position: + pos_str = "%s:%d:%d: " % position + else: + pos_str = "" + Exception.__init__(self, pos_str + message) + +class CompileWarning(PyrexWarning): def __init__(self, position = None, message = ""): self.position = position @@ -65,3 +78,12 @@ def error(position, message): echo_file.write(line) num_errors = num_errors + 1 return err + +def warning(position, message): + warn = CompileWarning(position, message) + line = "%s\n" % warn + if listing_file: + listing_file.write(line) + if echo_file: + echo_file.write(line) + return warn diff -r 3d8ba7d930b9 -r bc0cd828b4cd Compiler/Symtab.py --- a/Compiler/Symtab.py Thu Oct 19 21:30:50 2006 -0700 +++ b/Compiler/Symtab.py Sat Oct 21 18:53:34 2006 -0700 @@ -3,7 +3,7 @@ # import re -from Errors import error, InternalError +from Errors import error, InternalError, warning import Options import Naming from PyrexTypes import c_int_type, \ @@ -195,7 +195,7 @@ class Scope: # declared. dict = self.entries if name and dict.has_key(name): - error(pos, "'%s' redeclared" % name) + warning(pos, "'%s' redeclared (ignoring second declaration)" % name) entry = Entry(name, cname, type, pos = pos) entry.in_cinclude = self.in_cinclude if name: @@ -243,9 +243,9 @@ class Scope: self.sue_entries.append(entry) else: if not (entry.is_type and entry.type.is_struct_or_union): - error(pos, "'%s' redeclared" % name) + warning(pos, "'%s' redeclared (ignoring second declaration)" % name) elif scope and entry.type.scope: - error(pos, "'%s' already defined" % name) + warning(pos, "'%s' already defined (ignoring second definition)" % name) else: self.check_previous_typedef_flag(entry, typedef_flag, pos) if scope: @@ -556,7 +556,7 @@ class ModuleScope(Scope): if entry not in self.entries: self.entries[name] = entry else: - error(pos, "'%s' redeclared" % name) + warning(pos, "'%s' redeclared (ignoring second declaration)" % name) def declare_module(self, name, scope, pos): # Declare a cimported module. This is represented as a @@ -574,7 +574,7 @@ class ModuleScope(Scope): # name to appear again, and indeed the generated # code compiles fine. return entry - error(pos, "'%s' redeclared" % name) + warning(pos, "'%s' redeclared (ignoring second declaration)" % name) return None else: entry = self.declare_var(name, py_object_type, pos) @@ -822,7 +822,7 @@ class LocalScope(Scope): def declare_global(self, name, pos): # Pull entry from global scope into local scope. if self.lookup_here(name): - error(pos, "'%s' redeclared") + warning(pos, "'%s' redeclared (ignoring second declaration)") else: entry = self.global_scope().lookup_target(name) self.entries[name] = entry @@ -996,7 +996,7 @@ class CClassScope(ClassScope): entry = self.lookup_here(name) if entry: if not entry.is_cfunction: - error(pos, "'%s' redeclared" % name) + warning(pos, "'%s' redeclared (ignoring second declaration)" % name) else: if defining and entry.func_cname: error(pos, "'%s' already defined" % name) --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---