cython

changeset 1586:4a96e1aff2d4

Fix error in buffer typestring checking
author Dag Sverre Seljebotn <dagss@student.matnat.uio.no>
date Tue Dec 16 10:02:51 2008 +0100 (3 years ago)
parents 66ce58e9ff83
children cdf889c30e7a
files Cython/Compiler/Buffer.py Cython/Compiler/PyrexTypes.py tests/run/bufaccess.pyx
line diff
1.1 --- a/Cython/Compiler/Buffer.py Sun Dec 14 02:58:32 2008 -0800 1.2 +++ b/Cython/Compiler/Buffer.py Tue Dec 16 10:02:51 2008 +0100 1.3 @@ -500,7 +500,7 @@ 1.4 elif dtype.is_ptr: 1.5 return "ptr" 1.6 else: 1.7 - if dtype.typestring is None: 1.8 + if dtype.is_typedef or dtype.is_struct_or_union: 1.9 prefix = "nn_" 1.10 else: 1.11 prefix = "" 1.12 @@ -552,10 +552,8 @@ 1.13 defcode.putln("int ok;") 1.14 defcode.putln("ts = __Pyx_ConsumeWhitespace(ts); if (!ts) return NULL;") 1.15 defcode.putln("if (*ts == '1') ++ts;") 1.16 - if dtype.typestring is not None: 1.17 - assert len(dtype.typestring) == 1 1.18 - # Can use direct comparison 1.19 - defcode.putln("ok = (*ts == '%s');" % dtype.typestring) 1.20 + if dtype.is_pyobject: 1.21 + defcode.putln("ok = (*ts == 'O');") 1.22 else: 1.23 # Cannot trust declared size; but rely on int vs float and 1.24 # signed/unsigned to be correctly declared. Use a switch statement
2.1 --- a/Cython/Compiler/PyrexTypes.py Sun Dec 14 02:58:32 2008 -0800 2.2 +++ b/Cython/Compiler/PyrexTypes.py Tue Dec 16 10:02:51 2008 +0100 2.3 @@ -49,7 +49,6 @@ 2.4 # default_value string Initial value 2.5 # parsetuple_format string Format char for PyArg_ParseTuple 2.6 # pymemberdef_typecode string Type code for PyMemberDef struct 2.7 - # typestring string String char defining the type (see Python struct module) 2.8 # 2.9 # declaration_code(entity_code, 2.10 # for_display = 0, dll_linkage = None, pyrex = 0) 2.11 @@ -101,7 +100,6 @@ 2.12 default_value = "" 2.13 parsetuple_format = "" 2.14 pymemberdef_typecode = None 2.15 - typestring = None 2.16 2.17 def resolve(self): 2.18 # If a typedef, returns the base type. 2.19 @@ -157,7 +155,6 @@ 2.20 # typedef_base_type PyrexType 2.21 2.22 is_typedef = 1 2.23 - typestring = None # Because typedefs are not known exactly 2.24 2.25 def __init__(self, cname, base_type): 2.26 self.typedef_cname = cname 2.27 @@ -243,7 +240,6 @@ 2.28 parsetuple_format = "O" 2.29 pymemberdef_typecode = "T_OBJECT" 2.30 buffer_defaults = None 2.31 - typestring = "O" 2.32 2.33 def __str__(self): 2.34 return "Python object" 2.35 @@ -469,10 +465,9 @@ 2.36 2.37 sign_words = ("unsigned ", "", "signed ") 2.38 2.39 - def __init__(self, rank, signed = 1, pymemberdef_typecode = None, typestring = None): 2.40 + def __init__(self, rank, signed = 1, pymemberdef_typecode = None): 2.41 self.rank = rank 2.42 self.signed = signed 2.43 - self.typestring = typestring 2.44 ptf = self.parsetuple_formats[signed][rank] 2.45 if ptf == '?': 2.46 ptf = None 2.47 @@ -507,9 +502,8 @@ 2.48 from_py_function = "__pyx_PyInt_AsLong" 2.49 exception_value = -1 2.50 2.51 - def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0, 2.52 - typestring=None): 2.53 - CNumericType.__init__(self, rank, signed, pymemberdef_typecode, typestring=typestring) 2.54 + def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0): 2.55 + CNumericType.__init__(self, rank, signed, pymemberdef_typecode) 2.56 self.is_returncode = is_returncode 2.57 if self.from_py_function == '__pyx_PyInt_AsLong': 2.58 self.from_py_function = self.get_type_conversion() 2.59 @@ -602,8 +596,8 @@ 2.60 to_py_function = "PyFloat_FromDouble" 2.61 from_py_function = "__pyx_PyFloat_AsDouble" 2.62 2.63 - def __init__(self, rank, pymemberdef_typecode = None, typestring=None): 2.64 - CNumericType.__init__(self, rank, 1, pymemberdef_typecode, typestring = typestring) 2.65 + def __init__(self, rank, pymemberdef_typecode = None): 2.66 + CNumericType.__init__(self, rank, 1, pymemberdef_typecode) 2.67 2.68 def assignable_from_resolved_type(self, src_type): 2.69 return src_type.is_numeric or src_type is error_type 2.70 @@ -1133,7 +1127,6 @@ 2.71 exception_check = 0 2.72 to_py_function = "dummy" 2.73 from_py_function = "dummy" 2.74 - typestring = None 2.75 2.76 def create_convert_utility_code(self, env): 2.77 return True 2.78 @@ -1167,29 +1160,29 @@ 2.79 c_void_ptr_type = CPtrType(c_void_type) 2.80 c_void_ptr_ptr_type = CPtrType(c_void_ptr_type) 2.81 2.82 -c_uchar_type = CIntType(0, 0, "T_UBYTE", typestring="B") 2.83 -c_ushort_type = CIntType(1, 0, "T_USHORT", typestring="H") 2.84 -c_uint_type = CUIntType(2, 0, "T_UINT", typestring="I") 2.85 -c_ulong_type = CULongType(3, 0, "T_ULONG", typestring="L") 2.86 -c_ulonglong_type = CULongLongType(4, 0, "T_ULONGLONG", typestring="Q") 2.87 +c_uchar_type = CIntType(0, 0, "T_UBYTE") 2.88 +c_ushort_type = CIntType(1, 0, "T_USHORT") 2.89 +c_uint_type = CUIntType(2, 0, "T_UINT") 2.90 +c_ulong_type = CULongType(3, 0, "T_ULONG") 2.91 +c_ulonglong_type = CULongLongType(4, 0, "T_ULONGLONG") 2.92 2.93 -c_char_type = CIntType(0, 1, "T_CHAR", typestring="b") 2.94 -c_short_type = CIntType(1, 1, "T_SHORT", typestring="h") 2.95 -c_int_type = CIntType(2, 1, "T_INT", typestring="i") 2.96 -c_long_type = CIntType(3, 1, "T_LONG", typestring="l") 2.97 -c_longlong_type = CLongLongType(4, 1, "T_LONGLONG", typestring="q") 2.98 +c_char_type = CIntType(0, 1, "T_CHAR") 2.99 +c_short_type = CIntType(1, 1, "T_SHORT") 2.100 +c_int_type = CIntType(2, 1, "T_INT") 2.101 +c_long_type = CIntType(3, 1, "T_LONG") 2.102 +c_longlong_type = CLongLongType(4, 1, "T_LONGLONG") 2.103 c_py_ssize_t_type = CPySSizeTType(5, 1) 2.104 -c_bint_type = CBIntType(2, 1, "T_INT", typestring="i") 2.105 +c_bint_type = CBIntType(2, 1, "T_INT") 2.106 2.107 -c_schar_type = CIntType(0, 2, "T_CHAR", typestring="b") 2.108 -c_sshort_type = CIntType(1, 2, "T_SHORT", typestring="h") 2.109 -c_sint_type = CIntType(2, 2, "T_INT", typestring="i") 2.110 -c_slong_type = CIntType(3, 2, "T_LONG", typestring="l") 2.111 -c_slonglong_type = CLongLongType(4, 2, "T_LONGLONG", typestring="q") 2.112 +c_schar_type = CIntType(0, 2, "T_CHAR") 2.113 +c_sshort_type = CIntType(1, 2, "T_SHORT") 2.114 +c_sint_type = CIntType(2, 2, "T_INT") 2.115 +c_slong_type = CIntType(3, 2, "T_LONG") 2.116 +c_slonglong_type = CLongLongType(4, 2, "T_LONGLONG") 2.117 2.118 -c_float_type = CFloatType(6, "T_FLOAT", typestring="f") 2.119 -c_double_type = CFloatType(7, "T_DOUBLE", typestring="d") 2.120 -c_longdouble_type = CFloatType(8, typestring="g") 2.121 +c_float_type = CFloatType(6, "T_FLOAT") 2.122 +c_double_type = CFloatType(7, "T_DOUBLE") 2.123 +c_longdouble_type = CFloatType(8) 2.124 2.125 c_null_ptr_type = CNullPtrType(c_void_type) 2.126 c_char_array_type = CCharArrayType(None)
3.1 --- a/tests/run/bufaccess.pyx Sun Dec 14 02:58:32 2008 -0800 3.2 +++ b/tests/run/bufaccess.pyx Tue Dec 16 10:02:51 2008 +0100 3.3 @@ -384,6 +384,17 @@ 3.4 """ 3.5 print buf[1] 3.6 3.7 +@testcase 3.8 +def int_and_long_are_same(): 3.9 + """ 3.10 + >>> int_and_long_are_same() 3.11 + """ 3.12 + cdef object[int] intarr 3.13 + cdef object[long] longarr 3.14 + if sizeof(int) == sizeof(long): 3.15 + intarr = IntMockBuffer(None, [1,2], format='l') 3.16 + longarr = IntMockBuffer(None, [1,2]) 3.17 + 3.18 # 3.19 # Getting items and index bounds checking 3.20 #