Commit ae424da0 authored by William Stein's avatar William Stein

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).
parent 42074163
...@@ -82,7 +82,8 @@ class Context: ...@@ -82,7 +82,8 @@ class Context:
try: try:
if debug_find_module: if debug_find_module:
print "Context.find_module: Parsing", pxd_pathname 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) pxd_tree.analyse_declarations(scope)
except CompileError: except CompileError:
pass pass
...@@ -133,20 +134,20 @@ class Context: ...@@ -133,20 +134,20 @@ class Context:
self.modules[name] = scope self.modules[name] = scope
return 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. # Parse the given source file and return a parse tree.
f = open(source_filename, "rU") f = open(source_filename, "rU")
s = PyrexScanner(f, source_filename, s = PyrexScanner(f, source_filename,
type_names = type_names, context = self) type_names = type_names, context = self)
try: try:
tree = Parsing.p_module(s, pxd) tree = Parsing.p_module(s, pxd, full_module_name)
finally: finally:
f.close() f.close()
if Errors.num_errors > 0: if Errors.num_errors > 0:
raise CompileError raise CompileError
return tree 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. # Get the module name out of a source file pathname.
_, tail = os.path.split(path) _, tail = os.path.split(path)
name, _ = os.path.splitext(tail) name, _ = os.path.splitext(tail)
...@@ -159,7 +160,11 @@ class Context: ...@@ -159,7 +160,11 @@ class Context:
options = default_options options = default_options
result = CompilationResult() result = CompilationResult()
cwd = os.getcwd() cwd = os.getcwd()
full_module_name, _ = os.path.splitext(source.replace('/', '.'))
source = os.path.join(cwd, source) source = os.path.join(cwd, source)
if options.use_listing_file: if options.use_listing_file:
result.listing_file = replace_suffix(source, ".lis") result.listing_file = replace_suffix(source, ".lis")
Errors.open_listing_file(result.listing_file, Errors.open_listing_file(result.listing_file,
...@@ -174,12 +179,12 @@ class Context: ...@@ -174,12 +179,12 @@ class Context:
else: else:
c_suffix = ".c" c_suffix = ".c"
result.c_file = replace_suffix(source, c_suffix) 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) initial_pos = (source, 1, 0)
scope = self.find_module(module_name, pos = initial_pos, need_pxd = 0) scope = self.find_module(module_name, pos = initial_pos, need_pxd = 0)
errors_occurred = False errors_occurred = False
try: 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) tree.process_implementation(scope, result)
except CompileError: except CompileError:
errors_occurred = True errors_occurred = True
......
...@@ -962,6 +962,7 @@ class ModuleNode(Node, BlockNode): ...@@ -962,6 +962,7 @@ class ModuleNode(Node, BlockNode):
"}") "}")
def generate_typeobj_definition(self, modname, entry, code): def generate_typeobj_definition(self, modname, entry, code):
print modname
type = entry.type type = entry.type
scope = type.scope scope = type.scope
for suite in TypeSlots.substructures: for suite in TypeSlots.substructures:
...@@ -980,7 +981,7 @@ class ModuleNode(Node, BlockNode): ...@@ -980,7 +981,7 @@ class ModuleNode(Node, BlockNode):
"0, /*ob_size*/") "0, /*ob_size*/")
code.putln( code.putln(
'"%s.%s", /*tp_name*/' % ( '"%s.%s", /*tp_name*/' % (
modname, scope.class_name)) self.full_module_name, scope.class_name))
if type.typedef_flag: if type.typedef_flag:
objstruct = type.objstruct_cname objstruct = type.objstruct_cname
else: else:
......
...@@ -1768,7 +1768,7 @@ def p_doc_string(s): ...@@ -1768,7 +1768,7 @@ def p_doc_string(s):
else: else:
return None return None
def p_module(s, pxd): def p_module(s, pxd, full_module_name):
s.add_type_name("object") s.add_type_name("object")
pos = s.position() pos = s.position()
doc = p_doc_string(s) doc = p_doc_string(s)
...@@ -1780,7 +1780,7 @@ def p_module(s, pxd): ...@@ -1780,7 +1780,7 @@ def p_module(s, pxd):
if s.sy <> 'EOF': if s.sy <> 'EOF':
s.error("Syntax error in statement [%s,%s]" % ( s.error("Syntax error in statement [%s,%s]" % (
repr(s.sy), repr(s.systring))) 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)
#---------------------------------------------- #----------------------------------------------
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment