From: Dag Sverre Seljebotn Date: Thu, 14 May 2009 14:49:54 +0000 (+0200) Subject: Fix #303 as per Lisandro's idea X-Git-Tag: 0.11.2.rc1~10^2~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=140313e2942088028b272f3f2574e330cdb7fadd;p=cython.git Fix #303 as per Lisandro's idea --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 2ff86dba..fabb3832 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -793,10 +793,17 @@ class CVarDefNode(StatNode): dest_scope = env self.dest_scope = dest_scope base_type = self.base_type.analyse(env) - if (dest_scope.is_c_class_scope - and self.visibility == 'public' - and base_type.is_pyobject - and (base_type.is_builtin_type or base_type.is_extension_type)): + + # If the field is an external typedef, we cannot be sure about the type, + # so do conversion ourself rather than rely on the CPython mechanism (through + # a property; made in AnalyseDeclarationsTransform). + # Also, if the type is an extension type, then the CPython mechanism does + # not do enough type-checking for us. + if (dest_scope.is_c_class_scope and + ((self.visibility == 'public' + and base_type.is_pyobject + and (base_type.is_builtin_type or base_type.is_extension_type) + or (base_type.is_typedef and base_type.typedef_is_external)))): self.need_properties = [] need_property = True visibility = 'private' diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index a106c386..57c20341 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -161,12 +161,15 @@ class CTypedefType(BaseType): # qualified_name string # typedef_cname string # typedef_base_type PyrexType + # typedef_is_external bool is_typedef = 1 + typedef_is_external = 0 - def __init__(self, cname, base_type): + def __init__(self, cname, base_type, is_external=0): self.typedef_cname = cname self.typedef_base_type = base_type + self.typedef_is_external = is_external def resolve(self): return self.typedef_base_type.resolve() diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index d972309f..2e5415ef 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -347,7 +347,7 @@ class Scope(object): cname = name else: cname = self.mangle(Naming.type_prefix, name) - type = PyrexTypes.CTypedefType(cname, base_type) + type = PyrexTypes.CTypedefType(cname, base_type, (visibility == 'extern')) entry = self.declare_type(name, type, pos, cname, visibility) type.qualified_name = entry.qualified_name return entry