if (type1.is_ptr or type1.is_array) and (type2.is_int or type2.is_enum):
return type1
elif (type1.is_ptr or type1.is_array) and (type2.is_ptr or type2.is_array):
- return PyrexTypes.c_int_type
+ return PyrexTypes.c_ptrdiff_t_type
else:
return NumBinopNode.compute_c_result_type(
self, type1, type2)
"Py_ssize_t" : (2, 0),
"ssize_t" : (2, 0),
"size_t" : (0, 0),
+ "ptrdiff_t" : (2, 0),
}
sign_and_longness_words = ("short", "long", "signed", "unsigned")
def sign_and_name(self):
return "size_t"
+class CPtrdiffTType(CIntType):
+
+ to_py_function = "__Pyx_PyInt_FromPtrdiff_t"
+ from_py_function = "__Pyx_PyInt_AsPtrdiff_t"
+
+ def sign_and_name(self):
+ return "ptrdiff_t"
+
class CFloatType(CNumericType):
c_py_ssize_t_type = CPySSizeTType(RANK_LONG+0.5, SIGNED)
c_ssize_t_type = CSSizeTType(RANK_LONG+0.5, SIGNED)
c_size_t_type = CSizeTType(RANK_LONG+0.5, UNSIGNED)
+c_ptrdiff_t_type = CPtrdiffTType(RANK_LONG+0.25, SIGNED)
c_null_ptr_type = CNullPtrType(c_void_type)
c_void_ptr_type = CPtrType(c_void_type)
(2, 0, "Py_ssize_t"): c_py_ssize_t_type,
(2, 0, "ssize_t") : c_ssize_t_type,
(0, 0, "size_t") : c_size_t_type,
+ (2, 0, "ptrdiff_t") : c_ptrdiff_t_type,
(1, 0, "object"): py_object_type,
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromPtrdiff_t(ptrdiff_t);
+static CYTHON_INLINE ptrdiff_t __Pyx_PyInt_AsPtrdiff_t(PyObject*);
+
#if CYTHON_COMPILING_IN_CPYTHON
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
}
return (size_t)val;
}
+
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromPtrdiff_t(ptrdiff_t ival) {
+ if (LONG_MIN < ival && ival <= LONG_MAX)
+ return PyInt_FromLong((long)ival);
+ else {
+ unsigned char *bytes = (unsigned char *) &ival;
+ int one = 1; int little = (int)*(unsigned char*)&one;
+ return _PyLong_FromByteArray(bytes, sizeof(ptrdiff_t), little, 0);
+ }
+}
+
+static CYTHON_INLINE ptrdiff_t __Pyx_PyInt_AsPtrdiff_t(PyObject* x) {
+ unsigned PY_LONG_LONG val = __Pyx_PyInt_AsLongLong(x);
+ if (unlikely(val != (unsigned PY_LONG_LONG)(ptrdiff_t)val)) {
+ if ((val != (unsigned PY_LONG_LONG)-1) || !PyErr_Occurred())
+ PyErr_SetString(PyExc_OverflowError,
+ "value too large to convert to size_t");
+ return (ptrdiff_t)-1;
+ }
+ return (ptrdiff_t)val;
+}
/////////////// FromPyStructUtility.proto ///////////////
{{struct_type_decl}};
ptr1 = ptr2 - ptr3 # error
_ERRORS = u"""
6:13: Invalid operand types for '-' (int; char *)
-7:13: Cannot assign type 'int' to 'char *'
+7:13: Cannot assign type 'ptrdiff_t' to 'char *'
"""