cython-devel

changeset 2771:8094c672a0b9

Less strict type checking on non-subclassed extern types.
author Robert Bradshaw <robertwb@math.washington.edu>
date Tue Dec 08 23:10:36 2009 -0800 (2 years ago)
parents 193ded67caa0
children 8328e33eaabc
files Cython/Compiler/ModuleNode.py Cython/Compiler/PyrexTypes.py Cython/Compiler/Symtab.py
line diff
1.1 --- a/Cython/Compiler/ModuleNode.py Tue Dec 08 22:21:37 2009 -0800 1.2 +++ b/Cython/Compiler/ModuleNode.py Tue Dec 08 23:10:36 2009 -0800 1.3 @@ -1986,18 +1986,19 @@ 1.4 module_name = '__Pyx_BUILTIN_MODULE_NAME' 1.5 if type.name in self.py3_type_name_map: 1.6 code.putln("#if PY_MAJOR_VERSION >= 3") 1.7 - code.putln('%s = __Pyx_ImportType(%s, "%s", sizeof(%s)); %s' % ( 1.8 + code.putln('%s = __Pyx_ImportType(%s, "%s", sizeof(%s), 1); %s' % ( 1.9 type.typeptr_cname, 1.10 module_name, 1.11 self.py3_type_name_map[type.name], 1.12 objstruct, 1.13 error_code)) 1.14 code.putln("#else") 1.15 - code.putln('%s = __Pyx_ImportType(%s, "%s", sizeof(%s)); %s' % ( 1.16 + code.putln('%s = __Pyx_ImportType(%s, "%s", sizeof(%s), %i); %s' % ( 1.17 type.typeptr_cname, 1.18 module_name, 1.19 type.name, 1.20 objstruct, 1.21 + not type.is_external or type.is_subclassed, 1.22 error_code)) 1.23 if type.name in self.py3_type_name_map: 1.24 code.putln("#endif") 1.25 @@ -2154,17 +2155,18 @@ 1.26 1.27 type_import_utility_code = UtilityCode( 1.28 proto = """ 1.29 -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size); /*proto*/ 1.30 +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size, int strict); /*proto*/ 1.31 """, 1.32 impl = """ 1.33 #ifndef __PYX_HAVE_RT_ImportType 1.34 #define __PYX_HAVE_RT_ImportType 1.35 static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, 1.36 - long size) 1.37 + long size, int strict) 1.38 { 1.39 PyObject *py_module = 0; 1.40 PyObject *result = 0; 1.41 PyObject *py_name = 0; 1.42 + int size_ok; 1.43 1.44 py_module = __Pyx_ImportModule(module_name); 1.45 if (!py_module) 1.46 @@ -2189,7 +2191,13 @@ 1.47 module_name, class_name); 1.48 goto bad; 1.49 } 1.50 - if (((PyTypeObject *)result)->tp_basicsize != size) { 1.51 + if (strict) { 1.52 + size_ok = ((PyTypeObject *)result)->tp_basicsize == size; 1.53 + } 1.54 + else { 1.55 + size_ok = ((PyTypeObject *)result)->tp_basicsize >= size; 1.56 + } 1.57 + if (!size_ok) { 1.58 PyErr_Format(PyExc_ValueError, 1.59 "%s.%s does not appear to be the correct type object", 1.60 module_name, class_name);
2.1 --- a/Cython/Compiler/PyrexTypes.py Tue Dec 08 22:21:37 2009 -0800 2.2 +++ b/Cython/Compiler/PyrexTypes.py Tue Dec 08 23:10:36 2009 -0800 2.3 @@ -345,6 +345,8 @@ 2.4 default_value = "0" 2.5 pymemberdef_typecode = "T_OBJECT" 2.6 buffer_defaults = None 2.7 + is_extern = False 2.8 + is_subclassed = False 2.9 2.10 def __str__(self): 2.11 return "Python object" 2.12 @@ -472,10 +474,12 @@ 2.13 2.14 objtypedef_cname = None 2.15 2.16 - def __init__(self, name, typedef_flag, base_type): 2.17 + def __init__(self, name, typedef_flag, base_type, is_external=0): 2.18 self.name = name 2.19 self.scope = None 2.20 self.typedef_flag = typedef_flag 2.21 + if base_type is not None: 2.22 + base_type.is_subclassed = True 2.23 self.base_type = base_type 2.24 self.module_name = None 2.25 self.objstruct_cname = None 2.26 @@ -485,6 +489,7 @@ 2.27 self.vtabstruct_cname = None 2.28 self.vtabptr_cname = None 2.29 self.vtable_cname = None 2.30 + self.is_external = is_external 2.31 2.32 def set_scope(self, scope): 2.33 self.scope = scope
3.1 --- a/Cython/Compiler/Symtab.py Tue Dec 08 22:21:37 2009 -0800 3.2 +++ b/Cython/Compiler/Symtab.py Tue Dec 08 23:10:36 2009 -0800 3.3 @@ -887,7 +887,7 @@ 3.4 # Make a new entry if needed 3.5 # 3.6 if not entry: 3.7 - type = PyrexTypes.PyExtensionType(name, typedef_flag, base_type) 3.8 + type = PyrexTypes.PyExtensionType(name, typedef_flag, base_type, visibility == 'extern') 3.9 type.pos = pos 3.10 type.buffer_defaults = buffer_defaults 3.11 if objtypedef_cname is not None: