From: Dag Sverre Seljebotn Date: Tue, 16 Dec 2008 09:02:51 +0000 (+0100) Subject: Fix error in buffer typestring checking X-Git-Tag: 0.10.3~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bb83b2f9559d8c9c98116c45ce2fd0165741a1d3;p=cython.git Fix error in buffer typestring checking --- diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py index ad1bce58..ac1e5401 100644 --- a/Cython/Compiler/Buffer.py +++ b/Cython/Compiler/Buffer.py @@ -500,7 +500,7 @@ def mangle_dtype_name(dtype): elif dtype.is_ptr: return "ptr" else: - if dtype.typestring is None: + if dtype.is_typedef or dtype.is_struct_or_union: prefix = "nn_" else: prefix = "" @@ -552,10 +552,8 @@ def create_typestringchecker(protocode, defcode, name, dtype): defcode.putln("int ok;") defcode.putln("ts = __Pyx_ConsumeWhitespace(ts); if (!ts) return NULL;") defcode.putln("if (*ts == '1') ++ts;") - if dtype.typestring is not None: - assert len(dtype.typestring) == 1 - # Can use direct comparison - defcode.putln("ok = (*ts == '%s');" % dtype.typestring) + if dtype.is_pyobject: + defcode.putln("ok = (*ts == 'O');") else: # Cannot trust declared size; but rely on int vs float and # signed/unsigned to be correctly declared. Use a switch statement diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 70330959..1b693633 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -49,7 +49,6 @@ class PyrexType(BaseType): # default_value string Initial value # parsetuple_format string Format char for PyArg_ParseTuple # pymemberdef_typecode string Type code for PyMemberDef struct - # typestring string String char defining the type (see Python struct module) # # declaration_code(entity_code, # for_display = 0, dll_linkage = None, pyrex = 0) @@ -101,7 +100,6 @@ class PyrexType(BaseType): default_value = "" parsetuple_format = "" pymemberdef_typecode = None - typestring = None def resolve(self): # If a typedef, returns the base type. @@ -157,7 +155,6 @@ class CTypedefType(BaseType): # typedef_base_type PyrexType is_typedef = 1 - typestring = None # Because typedefs are not known exactly def __init__(self, cname, base_type): self.typedef_cname = cname @@ -243,7 +240,6 @@ class PyObjectType(PyrexType): parsetuple_format = "O" pymemberdef_typecode = "T_OBJECT" buffer_defaults = None - typestring = "O" def __str__(self): return "Python object" @@ -469,10 +465,9 @@ class CNumericType(CType): sign_words = ("unsigned ", "", "signed ") - def __init__(self, rank, signed = 1, pymemberdef_typecode = None, typestring = None): + def __init__(self, rank, signed = 1, pymemberdef_typecode = None): self.rank = rank self.signed = signed - self.typestring = typestring ptf = self.parsetuple_formats[signed][rank] if ptf == '?': ptf = None @@ -507,9 +502,8 @@ class CIntType(CNumericType): from_py_function = "__pyx_PyInt_AsLong" exception_value = -1 - def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0, - typestring=None): - CNumericType.__init__(self, rank, signed, pymemberdef_typecode, typestring=typestring) + def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0): + CNumericType.__init__(self, rank, signed, pymemberdef_typecode) self.is_returncode = is_returncode if self.from_py_function == '__pyx_PyInt_AsLong': self.from_py_function = self.get_type_conversion() @@ -602,8 +596,8 @@ class CFloatType(CNumericType): to_py_function = "PyFloat_FromDouble" from_py_function = "__pyx_PyFloat_AsDouble" - def __init__(self, rank, pymemberdef_typecode = None, typestring=None): - CNumericType.__init__(self, rank, 1, pymemberdef_typecode, typestring = typestring) + def __init__(self, rank, pymemberdef_typecode = None): + CNumericType.__init__(self, rank, 1, pymemberdef_typecode) def assignable_from_resolved_type(self, src_type): return src_type.is_numeric or src_type is error_type @@ -1133,7 +1127,6 @@ class ErrorType(PyrexType): exception_check = 0 to_py_function = "dummy" from_py_function = "dummy" - typestring = None def create_convert_utility_code(self, env): return True @@ -1167,29 +1160,29 @@ c_void_type = CVoidType() c_void_ptr_type = CPtrType(c_void_type) c_void_ptr_ptr_type = CPtrType(c_void_ptr_type) -c_uchar_type = CIntType(0, 0, "T_UBYTE", typestring="B") -c_ushort_type = CIntType(1, 0, "T_USHORT", typestring="H") -c_uint_type = CUIntType(2, 0, "T_UINT", typestring="I") -c_ulong_type = CULongType(3, 0, "T_ULONG", typestring="L") -c_ulonglong_type = CULongLongType(4, 0, "T_ULONGLONG", typestring="Q") - -c_char_type = CIntType(0, 1, "T_CHAR", typestring="b") -c_short_type = CIntType(1, 1, "T_SHORT", typestring="h") -c_int_type = CIntType(2, 1, "T_INT", typestring="i") -c_long_type = CIntType(3, 1, "T_LONG", typestring="l") -c_longlong_type = CLongLongType(4, 1, "T_LONGLONG", typestring="q") +c_uchar_type = CIntType(0, 0, "T_UBYTE") +c_ushort_type = CIntType(1, 0, "T_USHORT") +c_uint_type = CUIntType(2, 0, "T_UINT") +c_ulong_type = CULongType(3, 0, "T_ULONG") +c_ulonglong_type = CULongLongType(4, 0, "T_ULONGLONG") + +c_char_type = CIntType(0, 1, "T_CHAR") +c_short_type = CIntType(1, 1, "T_SHORT") +c_int_type = CIntType(2, 1, "T_INT") +c_long_type = CIntType(3, 1, "T_LONG") +c_longlong_type = CLongLongType(4, 1, "T_LONGLONG") c_py_ssize_t_type = CPySSizeTType(5, 1) -c_bint_type = CBIntType(2, 1, "T_INT", typestring="i") +c_bint_type = CBIntType(2, 1, "T_INT") -c_schar_type = CIntType(0, 2, "T_CHAR", typestring="b") -c_sshort_type = CIntType(1, 2, "T_SHORT", typestring="h") -c_sint_type = CIntType(2, 2, "T_INT", typestring="i") -c_slong_type = CIntType(3, 2, "T_LONG", typestring="l") -c_slonglong_type = CLongLongType(4, 2, "T_LONGLONG", typestring="q") +c_schar_type = CIntType(0, 2, "T_CHAR") +c_sshort_type = CIntType(1, 2, "T_SHORT") +c_sint_type = CIntType(2, 2, "T_INT") +c_slong_type = CIntType(3, 2, "T_LONG") +c_slonglong_type = CLongLongType(4, 2, "T_LONGLONG") -c_float_type = CFloatType(6, "T_FLOAT", typestring="f") -c_double_type = CFloatType(7, "T_DOUBLE", typestring="d") -c_longdouble_type = CFloatType(8, typestring="g") +c_float_type = CFloatType(6, "T_FLOAT") +c_double_type = CFloatType(7, "T_DOUBLE") +c_longdouble_type = CFloatType(8) c_null_ptr_type = CNullPtrType(c_void_type) c_char_array_type = CCharArrayType(None) diff --git a/tests/run/bufaccess.pyx b/tests/run/bufaccess.pyx index ce228cf4..4ede61e0 100644 --- a/tests/run/bufaccess.pyx +++ b/tests/run/bufaccess.pyx @@ -384,6 +384,17 @@ def wrong_string(object[int] buf): """ print buf[1] +@testcase +def int_and_long_are_same(): + """ + >>> int_and_long_are_same() + """ + cdef object[int] intarr + cdef object[long] longarr + if sizeof(int) == sizeof(long): + intarr = IntMockBuffer(None, [1,2], format='l') + longarr = IntMockBuffer(None, [1,2]) + # # Getting items and index bounds checking #