Ticket #207: SIZE_T.diff

File SIZE_T.diff, 8.1 KB (added by dalcinl, 3 years ago)
  • Cython/Compiler/ExprNodes.py

    diff -r e898a5663681 Cython/Compiler/ExprNodes.py
    a b  
    38923892class SizeofNode(ExprNode): 
    38933893    #  Abstract base class for sizeof(x) expression nodes. 
    38943894     
    3895     type = PyrexTypes.c_int_type 
     3895    type = PyrexTypes.c_size_t_type 
    38963896 
    38973897    def check_const(self): 
    38983898        pass 
  • Cython/Compiler/Parsing.py

    diff -r e898a5663681 Cython/Compiler/Parsing.py
    a b  
    18101810        return result 
    18111811    else: 
    18121812        return 0 
    1813          
    1814 basic_c_type_names = ("void", "char", "int", "float", "double", "Py_ssize_t", "bint") 
     1813 
     1814basic_c_type_names = ("void", "char", "int", "float", "double", "Py_ssize_t", "size_t", "bint") 
    18151815 
    18161816sign_and_longness_words = ("short", "long", "signed", "unsigned") 
    18171817 
  • Cython/Compiler/PyrexTypes.py

    diff -r e898a5663681 Cython/Compiler/PyrexTypes.py
    a b  
    462462    default_value = "0" 
    463463     
    464464    parsetuple_formats = ( # rank -> format 
    465         "BHIkK????", # unsigned 
    466         "bhilL?fd?", # assumed signed 
    467         "bhilL?fd?", # explicitly signed 
     465        "BHIkK?????", # unsigned 
     466        "bhilL??fd?", # assumed signed 
     467        "bhilL??fd?", # explicitly signed 
    468468    ) 
    469469     
    470470    sign_words = ("unsigned ", "", "signed ") 
     
    594594    from_py_function = "__pyx_PyIndex_AsSsize_t" 
    595595 
    596596 
     597class CSizeTType(CUIntType): 
     598 
     599    to_py_function = "__pyx_PyInt_FromSize_t" 
     600    from_py_function = "__pyx_PyInt_AsSize_t" 
     601 
     602 
    597603class CFloatType(CNumericType): 
    598604 
    599605    is_float = 1 
     
    11531159    "long",         # 3 
    11541160    "PY_LONG_LONG", # 4 
    11551161    "Py_ssize_t",   # 5 
    1156     "float",        # 6 
    1157     "double",       # 7 
    1158     "long double",  # 8 
     1162    "size_t",       # 6 
     1163    "float",        # 7 
     1164    "double",       # 8 
     1165    "long double",  # 9 
    11591166) 
    11601167 
    11611168py_object_type = PyObjectType() 
     
    11751182c_int_type =         CIntType(2, 1, "T_INT") 
    11761183c_long_type =        CIntType(3, 1, "T_LONG") 
    11771184c_longlong_type =    CLongLongType(4, 1, "T_LONGLONG") 
    1178 c_py_ssize_t_type =  CPySSizeTType(5, 1) 
    11791185c_bint_type =        CBIntType(2, 1, "T_INT") 
    11801186 
    11811187c_schar_type =       CIntType(0, 2, "T_CHAR") 
     
    11841190c_slong_type =       CIntType(3, 2, "T_LONG") 
    11851191c_slonglong_type =   CLongLongType(4, 2, "T_LONGLONG") 
    11861192 
    1187 c_float_type =       CFloatType(6, "T_FLOAT") 
    1188 c_double_type =      CFloatType(7, "T_DOUBLE") 
    1189 c_longdouble_type =  CFloatType(8) 
     1193c_py_ssize_t_type =  CPySSizeTType(5, 1) 
     1194c_size_t_type =      CSizeTType(6, 1) 
     1195 
     1196c_float_type =       CFloatType(7, "T_FLOAT") 
     1197c_double_type =      CFloatType(8, "T_DOUBLE") 
     1198c_longdouble_type =  CFloatType(9) 
    11901199 
    11911200c_null_ptr_type =     CNullPtrType(c_void_type) 
    11921201c_char_array_type =   CCharArrayType(None) 
    11931202c_char_ptr_type =     CCharPtrType() 
    11941203c_utf8_char_array_type = CUTF8CharArrayType(None) 
    11951204c_char_ptr_ptr_type = CPtrType(c_char_ptr_type) 
     1205c_int_ptr_type =      CPtrType(c_int_type) 
    11961206c_py_ssize_t_ptr_type =  CPtrType(c_py_ssize_t_type) 
    1197 c_int_ptr_type =      CPtrType(c_int_type) 
     1207c_size_t_ptr_type =  CPtrType(c_size_t_type) 
    11981208 
    11991209c_returncode_type =   CIntType(2, 1, "T_INT", is_returncode = 1) 
    12001210 
     
    12071217error_type =    ErrorType() 
    12081218unspecified_type = UnspecifiedType() 
    12091219 
    1210 lowest_float_rank = 6 
    1211  
    12121220sign_and_rank_to_type = { 
    12131221    #(signed, rank) 
    12141222    (0, 0, ): c_uchar_type,  
    12151223    (0, 1): c_ushort_type,  
    12161224    (0, 2): c_uint_type,  
    1217   (0, 3): c_ulong_type, 
    1218   (0, 4): c_ulonglong_type, 
    1219     (0, 5):  c_ulonglong_type,            # I'm not sure about this.  this should be for size_t Py_ssize_t 
     1225    (0, 3): c_ulong_type, 
     1226    (0, 4): c_ulonglong_type, 
     1227    (0, 5): c_ulonglong_type, 
     1228     
    12201229    (1, 0): c_char_type,  
    12211230    (1, 1): c_short_type,  
    12221231    (1, 2): c_int_type,  
    12231232    (1, 3): c_long_type, 
    12241233    (1, 4): c_longlong_type, 
    1225     (1, 5): c_py_ssize_t_type, 
    12261234    (2, 0): c_schar_type,  
    12271235    (2, 1): c_sshort_type,  
    12281236    (2, 2): c_sint_type,  
    12291237    (2, 3): c_slong_type, 
    12301238    (2, 4): c_slonglong_type, 
     1239 
     1240    (1, 5): c_py_ssize_t_type, 
    12311241    (2, 5): c_py_ssize_t_type, 
     1242    (0, 6): c_size_t_type, 
     1243    (1, 6): c_size_t_type, 
     1244 
    12321245    (1, 6): c_float_type,  
    12331246    (1, 7): c_double_type, 
    12341247    (1, 8): c_longdouble_type, 
     
    12511264    (1, 0, "int"): c_int_type,  
    12521265    (1, 1, "int"): c_long_type, 
    12531266    (1, 2, "int"): c_longlong_type, 
    1254     (1, 0, "Py_ssize_t"): c_py_ssize_t_type, 
    12551267    (1, 0, "float"): c_float_type,  
    12561268    (1, 0, "double"): c_double_type, 
    12571269    (1, 1, "double"): c_longdouble_type, 
     
    12621274    (2, 0, "int"): c_sint_type,  
    12631275    (2, 1, "int"): c_slong_type, 
    12641276    (2, 2, "int"): c_slonglong_type, 
     1277 
     1278    (1, 0, "Py_ssize_t"): c_py_ssize_t_type, 
    12651279    (2, 0, "Py_ssize_t"): c_py_ssize_t_type, 
     1280    (0, 0, "size_t") : c_size_t_type, 
     1281    (1, 0, "size_t") : c_size_t_type, 
    12661282     
    12671283    (1, 0, "long"): c_long_type, 
    12681284    (1, 0, "short"): c_short_type, 
     
    13801396static INLINE unsigned PY_LONG_LONG __pyx_PyInt_AsUnsignedLongLong(PyObject* x); 
    13811397static INLINE Py_ssize_t __pyx_PyIndex_AsSsize_t(PyObject* b); 
    13821398 
     1399static INLINE PyObject * __pyx_PyInt_FromSize_t(size_t); 
     1400static INLINE size_t __pyx_PyInt_AsSize_t(PyObject*); 
     1401 
    13831402#define __pyx_PyInt_AsLong(x) (PyInt_CheckExact(x) ? PyInt_AS_LONG(x) : PyInt_AsLong(x)) 
    13841403#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) 
    13851404""" + type_conversion_predeclarations 
     
    13961415  return ival; 
    13971416} 
    13981417 
     1418static INLINE PyObject * __pyx_PyInt_FromSize_t(size_t ival) { 
     1419#if PY_VERSION_HEX < 0x02050000 
     1420   if (ival <= (size_t)LONG_MAX) 
     1421       return PyInt_FromLong((long)ival); 
     1422   else { 
     1423       unsigned char *bytes = (unsigned char *) &ival; 
     1424       int one = 1; 
     1425       return _PyLong_FromByteArray(bytes, sizeof(size_t), 
     1426                                    (int)*(unsigned char*)&one, 0); 
     1427   } 
     1428#else 
     1429   return PyInt_FromSize_t(ival); 
     1430#endif 
     1431} 
     1432 
     1433static INLINE size_t __pyx_PyInt_AsSize_t(PyObject* b) { 
     1434   unsigned PY_LONG_LONG val = __pyx_PyInt_AsUnsignedLongLong(b); 
     1435   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { 
     1436       return (size_t)-1; 
     1437   } else if (unlikely((unsigned PY_LONG_LONG)(size_t)val != val)) { 
     1438       PyErr_SetString(PyExc_OverflowError, "value too large to convert to size_t"); 
     1439   } 
     1440   return val; 
     1441} 
     1442 
    13991443static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { 
    14001444   if (x == Py_True) return 1; 
    14011445   else if (x == Py_False) return 0; 
  • Cython/Includes/python2.5.pxd

    diff -r e898a5663681 Cython/Includes/python2.5.pxd
    a b  
    1414# - Add unicode calls. 
    1515# - Add setobject calls. 
    1616 
    17 cdef extern from "sys/types.h": 
    18     ctypedef unsigned int size_t 
    19  
    2017cdef extern from "stdio.h": 
    2118    ctypedef struct FILE: 
    2219        pass 
  • Cython/Includes/python_mem.pxd

    diff -r e898a5663681 Cython/Includes/python_mem.pxd
    a b  
    11cdef extern from "Python.h": 
    2     ctypedef unsigned long size_t 
    3      
     2 
    43    ##################################################################### 
    54    # 9.2 Memory Interface 
    65    ##################################################################### 
  • Cython/Includes/stdlib.pxd

    diff -r e898a5663681 Cython/Includes/stdlib.pxd
    a b  
    11 
    22cdef extern from "stdlib.h": 
    3     ctypedef unsigned long size_t  
    43    void free(void *ptr) 
    54    void *malloc(size_t size) 
    65    void *realloc(void *ptr, size_t size) 
  • (a) /dev/null vs. (b) b/tests/run/size_t.pyx

    diff -r e898a5663681 tests/run/size_t.pyx
    a b  
     1__doc__ = u""" 
     2>>> test(0) 
     30 
     4>>> test(1) 
     51 
     6>>> test(2) 
     72 
     8>>> str(test((1<<32)-1)) 
     9'4294967295' 
     10 
     11>>> test(-1) #doctest: +ELLIPSIS 
     12Traceback (most recent call last): 
     13    ... 
     14OverflowError: ... 
     15 
     16>>> test(1<<128) #doctest: +ELLIPSIS 
     17Traceback (most recent call last): 
     18    ... 
     19OverflowError: ... 
     20""" 
     21 
     22def test(size_t i): 
     23    return i