From: William Stein Date: Sun, 22 Oct 2006 04:56:20 +0000 (-0700) Subject: Add correct setting of tp_name to the full module name in Nodes.py. X-Git-Tag: 0.9.6.14~29^2~220 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ae424da011db67648ee481f5051dfd7eb730f4b9;p=cython.git Add correct setting of tp_name to the full module name in Nodes.py. 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). --- diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 39912622..01eb7a13 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -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 diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index e1e7ddd0..3b2caaff 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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: diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 909223de..66154419 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -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) #---------------------------------------------- #