From ae36f3b10f5f46c821e7abdc8556751938c1d73f Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sun, 21 Oct 2007 01:01:15 -0700 Subject: [PATCH] ctypedef casting, more cdef extern class work --- Cython/Compiler/ModuleNode.py | 5 ++--- Cython/Compiler/Nodes.py | 7 ++----- Cython/Compiler/PyrexTypes.py | 8 ++++++++ Cython/Compiler/Symtab.py | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 6d533d40..83c159c9 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -1225,7 +1225,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): return Naming.modules_prefix + module_name.replace("_", "__").replace(".", "_") def generate_imported_module(self, module, code): - import_module = 0 + import_module = module.has_extern_class for entry in module.cfunc_entries: if entry.defined_in_pxd: import_module = 1 @@ -1384,14 +1384,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_module_import_code(self, module, env, code): - import_module = 0 + import_module = module.has_extern_class for entry in module.cfunc_entries: if entry.defined_in_pxd: import_module = 1 for entry in module.c_class_entries: if entry.defined_in_pxd: import_module = 1 - print "generate_module_import_code", module, import_module if import_module: env.use_utility_code(import_module_utility_code) name = self.build_module_var_name(module.qualified_name) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index b6634144..ba54027b 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1509,8 +1509,9 @@ class CClassDefNode(StatNode): self.module = module if self.module is None: self.module = ModuleScope(self.module_name, None, env.context) + self.module.has_extern_class = 1 env.cimported_modules.append(self.module) - print [e.name for e in env.cimported_modules] + if self.base_class_name: if self.base_class_module: base_class_scope = env.find_module(self.base_class_module, self.pos) @@ -1542,10 +1543,6 @@ class CClassDefNode(StatNode): api = self.api) 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 Options.embed_pos_in_docstring: scope.doc = 'File: %s (starting at line %s)'%relative_position(self.pos) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index b7474288..f5067241 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -163,6 +163,14 @@ class CTypedefType(BaseType): def as_argument_type(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): return "" % self.typedef_cname diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index a35cce4f..65f9a11c 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -700,6 +700,7 @@ class ModuleScope(Scope): self.all_pystring_entries = [] self.types_imported = {} self.pynum_entries = [] + self.has_extern_class = 0 def qualifying_scope(self): return self.parent_module -- 2.26.2