cython-devel

changeset 2052:dcc78ab6a498

Fix #303 as per Lisandro's idea
author Dag Sverre Seljebotn <dagss@student.matnat.uio.no>
date Thu May 14 16:49:54 2009 +0200 (2 years ago)
parents 4c2aca336673
children b8ba8ad3379d
files Cython/Compiler/Nodes.py Cython/Compiler/PyrexTypes.py Cython/Compiler/Symtab.py
line diff
1.1 --- a/Cython/Compiler/Nodes.py Thu May 14 15:28:13 2009 +0200 1.2 +++ b/Cython/Compiler/Nodes.py Thu May 14 16:49:54 2009 +0200 1.3 @@ -793,10 +793,17 @@ 1.4 dest_scope = env 1.5 self.dest_scope = dest_scope 1.6 base_type = self.base_type.analyse(env) 1.7 - if (dest_scope.is_c_class_scope 1.8 - and self.visibility == 'public' 1.9 - and base_type.is_pyobject 1.10 - and (base_type.is_builtin_type or base_type.is_extension_type)): 1.11 + 1.12 + # If the field is an external typedef, we cannot be sure about the type, 1.13 + # so do conversion ourself rather than rely on the CPython mechanism (through 1.14 + # a property; made in AnalyseDeclarationsTransform). 1.15 + # Also, if the type is an extension type, then the CPython mechanism does 1.16 + # not do enough type-checking for us. 1.17 + if (dest_scope.is_c_class_scope and 1.18 + ((self.visibility == 'public' 1.19 + and base_type.is_pyobject 1.20 + and (base_type.is_builtin_type or base_type.is_extension_type) 1.21 + or (base_type.is_typedef and base_type.typedef_is_external)))): 1.22 self.need_properties = [] 1.23 need_property = True 1.24 visibility = 'private'
2.1 --- a/Cython/Compiler/PyrexTypes.py Thu May 14 15:28:13 2009 +0200 2.2 +++ b/Cython/Compiler/PyrexTypes.py Thu May 14 16:49:54 2009 +0200 2.3 @@ -161,12 +161,15 @@ 2.4 # qualified_name string 2.5 # typedef_cname string 2.6 # typedef_base_type PyrexType 2.7 + # typedef_is_external bool 2.8 2.9 is_typedef = 1 2.10 + typedef_is_external = 0 2.11 2.12 - def __init__(self, cname, base_type): 2.13 + def __init__(self, cname, base_type, is_external=0): 2.14 self.typedef_cname = cname 2.15 self.typedef_base_type = base_type 2.16 + self.typedef_is_external = is_external 2.17 2.18 def resolve(self): 2.19 return self.typedef_base_type.resolve()
3.1 --- a/Cython/Compiler/Symtab.py Thu May 14 15:28:13 2009 +0200 3.2 +++ b/Cython/Compiler/Symtab.py Thu May 14 16:49:54 2009 +0200 3.3 @@ -347,7 +347,7 @@ 3.4 cname = name 3.5 else: 3.6 cname = self.mangle(Naming.type_prefix, name) 3.7 - type = PyrexTypes.CTypedefType(cname, base_type) 3.8 + type = PyrexTypes.CTypedefType(cname, base_type, (visibility == 'extern')) 3.9 entry = self.declare_type(name, type, pos, cname, visibility) 3.10 type.qualified_name = entry.qualified_name 3.11 return entry