Commit ae36f3b1 authored by Robert Bradshaw's avatar Robert Bradshaw

ctypedef casting, more cdef extern class work

parent efaf3aea
...@@ -1225,7 +1225,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1225,7 +1225,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
return Naming.modules_prefix + module_name.replace("_", "__").replace(".", "_") return Naming.modules_prefix + module_name.replace("_", "__").replace(".", "_")
def generate_imported_module(self, module, code): def generate_imported_module(self, module, code):
import_module = 0 import_module = module.has_extern_class
for entry in module.cfunc_entries: for entry in module.cfunc_entries:
if entry.defined_in_pxd: if entry.defined_in_pxd:
import_module = 1 import_module = 1
...@@ -1384,14 +1384,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1384,14 +1384,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_module_import_code(self, module, env, code): def generate_module_import_code(self, module, env, code):
import_module = 0 import_module = module.has_extern_class
for entry in module.cfunc_entries: for entry in module.cfunc_entries:
if entry.defined_in_pxd: if entry.defined_in_pxd:
import_module = 1 import_module = 1
for entry in module.c_class_entries: for entry in module.c_class_entries:
if entry.defined_in_pxd: if entry.defined_in_pxd:
import_module = 1 import_module = 1
print "generate_module_import_code", module, import_module
if import_module: if import_module:
env.use_utility_code(import_module_utility_code) env.use_utility_code(import_module_utility_code)
name = self.build_module_var_name(module.qualified_name) name = self.build_module_var_name(module.qualified_name)
......
...@@ -1509,8 +1509,9 @@ class CClassDefNode(StatNode): ...@@ -1509,8 +1509,9 @@ class CClassDefNode(StatNode):
self.module = module self.module = module
if self.module is None: if self.module is None:
self.module = ModuleScope(self.module_name, None, env.context) self.module = ModuleScope(self.module_name, None, env.context)
self.module.has_extern_class = 1
env.cimported_modules.append(self.module) env.cimported_modules.append(self.module)
print [e.name for e in env.cimported_modules]
if self.base_class_name: if self.base_class_name:
if self.base_class_module: if self.base_class_module:
base_class_scope = env.find_module(self.base_class_module, self.pos) base_class_scope = env.find_module(self.base_class_module, self.pos)
...@@ -1542,10 +1543,6 @@ class CClassDefNode(StatNode): ...@@ -1542,10 +1543,6 @@ class CClassDefNode(StatNode):
api = self.api) api = self.api)
scope = self.entry.type.scope scope = self.entry.type.scope
if self.module_name:
self.entry.defined_in_pxd = 1
self.module.c_class_entries.append(self.entry)
if self.doc: if self.doc:
if Options.embed_pos_in_docstring: if Options.embed_pos_in_docstring:
scope.doc = 'File: %s (starting at line %s)'%relative_position(self.pos) scope.doc = 'File: %s (starting at line %s)'%relative_position(self.pos)
......
...@@ -163,6 +163,14 @@ class CTypedefType(BaseType): ...@@ -163,6 +163,14 @@ class CTypedefType(BaseType):
def as_argument_type(self): def as_argument_type(self):
return self return self
def cast_code(self, expr_code):
# If self is really an array (rather than pointer), we can't cast.
# For example, the gmp mpz_t.
if self.typedef_base_type.is_ptr:
return self.typedef_base_type.cast_code(expr_code)
else:
return BaseType.cast_code(self, expr_code)
def __repr__(self): def __repr__(self):
return "<CTypedefType %s>" % self.typedef_cname return "<CTypedefType %s>" % self.typedef_cname
......
...@@ -700,6 +700,7 @@ class ModuleScope(Scope): ...@@ -700,6 +700,7 @@ class ModuleScope(Scope):
self.all_pystring_entries = [] self.all_pystring_entries = []
self.types_imported = {} self.types_imported = {}
self.pynum_entries = [] self.pynum_entries = []
self.has_extern_class = 0
def qualifying_scope(self): def qualifying_scope(self):
return self.parent_module return self.parent_module
......
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