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:
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
......
......@@ -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:
......
......@@ -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)
#----------------------------------------------
#
......
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