Add correct setting of tp_name to the full module name in Nodes.py.
authorWilliam Stein <wstein@gmail.com>
Sun, 22 Oct 2006 04:56:20 +0000 (21:56 -0700)
committerWilliam Stein <wstein@gmail.com>
Sun, 22 Oct 2006 04:56:20 +0000 (21:56 -0700)
  This required a number of changes to a few files.  Basically, the
  full module name is determined in Main.py. It is then passed around
  a bit until it is used when generating tp_name.

  This change was needed because otherwise pickling of extension classes
  with full module names like sage.rings.integer.Integer would fail
  (since Python would look for integer.Integer instead).  NOTE: This is
  pickling of the extension class itself, not of instances (which could
  also fail, because the class doesn't pickle).

Cython/Compiler/Main.py
Cython/Compiler/Nodes.py
Cython/Compiler/Parsing.py

index 39912622caa1b59057f4cf0a8c84e99f5da4bda6..01eb7a1303a6399a39bd80f3c85a70d9dd2c2fb5 100644 (file)
@@ -82,7 +82,8 @@ class Context:
                 try:
                     if debug_find_module:
                         print "Context.find_module: Parsing", pxd_pathname
-                    pxd_tree = self.parse(pxd_pathname, scope.type_names, pxd = 1)
+                    pxd_tree = self.parse(pxd_pathname, scope.type_names, pxd = 1,
+                                          full_module_name = module_name)
                     pxd_tree.analyse_declarations(scope)
                 except CompileError:
                     pass
@@ -133,20 +134,20 @@ class Context:
             self.modules[name] = scope
         return scope
 
-    def parse(self, source_filename, type_names, pxd):
+    def parse(self, source_filename, type_names, pxd, full_module_name):
         # Parse the given source file and return a parse tree.
         f = open(source_filename, "rU")
         s = PyrexScanner(f, source_filename, 
             type_names = type_names, context = self)
         try:
-            tree = Parsing.p_module(s, pxd)
+            tree = Parsing.p_module(s, pxd, full_module_name)
         finally:
             f.close()
         if Errors.num_errors > 0:
             raise CompileError
         return tree
 
-    def extract_module_name(self, path):
+    def extract_module_name(self, path, options):
         # Get the module name out of a source file pathname.
         _, tail = os.path.split(path)
         name, _ = os.path.splitext(tail)
@@ -159,7 +160,11 @@ class Context:
             options = default_options
         result = CompilationResult()
         cwd = os.getcwd()
+
+        full_module_name, _ = os.path.splitext(source.replace('/', '.'))
+
         source = os.path.join(cwd, source)
+        
         if options.use_listing_file:
             result.listing_file = replace_suffix(source, ".lis")
             Errors.open_listing_file(result.listing_file,
@@ -174,12 +179,12 @@ class Context:
             else:
                 c_suffix = ".c"
             result.c_file = replace_suffix(source, c_suffix)
-        module_name = self.extract_module_name(source)
+        module_name = self.extract_module_name(source, options)
         initial_pos = (source, 1, 0)
         scope = self.find_module(module_name, pos = initial_pos, need_pxd = 0)
         errors_occurred = False
         try:
-            tree = self.parse(source, scope.type_names, pxd = 0)
+            tree = self.parse(source, scope.type_names, pxd = 0, full_module_name = full_module_name)
             tree.process_implementation(scope, result)
         except CompileError:
             errors_occurred = True
index e1e7ddd089d9eb1df67c8a7899cda16845825f76..3b2caaffd8d87fd5f65e13faaed0d57fe78ee957 100644 (file)
@@ -962,6 +962,7 @@ class ModuleNode(Node, BlockNode):
             "}")
 
     def generate_typeobj_definition(self, modname, entry, code):
+        print modname
         type = entry.type
         scope = type.scope
         for suite in TypeSlots.substructures:
@@ -980,7 +981,7 @@ class ModuleNode(Node, BlockNode):
             "0, /*ob_size*/")
         code.putln(
             '"%s.%s", /*tp_name*/' % (
-                modname, scope.class_name))
+            self.full_module_name, scope.class_name))
         if type.typedef_flag:
             objstruct = type.objstruct_cname
         else:
index 909223de0459e2a8a54fc138baa38612b507357f..66154419057bc5c4ef04ead429587f6149123237 100644 (file)
@@ -1768,7 +1768,7 @@ def p_doc_string(s):
     else:
         return None
 
-def p_module(s, pxd):
+def p_module(s, pxd, full_module_name):
     s.add_type_name("object")
     pos = s.position()
     doc = p_doc_string(s)
@@ -1780,7 +1780,7 @@ def p_module(s, pxd):
     if s.sy <> 'EOF':
         s.error("Syntax error in statement [%s,%s]" % (
             repr(s.sy), repr(s.systring)))
-    return Nodes.ModuleNode(pos, doc = doc, body = body)
+    return Nodes.ModuleNode(pos, doc = doc, body = body, full_module_name = full_module_name)
 
 #----------------------------------------------
 #