|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int __Pyx_check_twos_complement(void) { |
|
|
if ((-1) != (~0)) { |
|
|
PyErr_SetString(PyExc_RuntimeError, "Two's complement required for overflow checks."); |
|
|
return 1; |
|
|
} else if ((sizeof(short) == sizeof(int))) { |
|
|
PyErr_SetString(PyExc_RuntimeError, "sizeof(short) < sizeof(int) required for overflow checks."); |
|
|
return 1; |
|
|
} else { |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
#define __PYX_SIGN_BIT(type) ((((unsigned type) 1) << (sizeof(type) * 8 - 1))) |
|
|
#define __PYX_HALF_MAX(type) ((((type) 1) << (sizeof(type) * 8 - 2))) |
|
|
#define __PYX_MIN(type) ((__PYX_IS_UNSIGNED(type) ? (type) 0 : 0 - __PYX_HALF_MAX(type) - __PYX_HALF_MAX(type))) |
|
|
#define __PYX_MAX(type) ((~__PYX_MIN(type))) |
|
|
|
|
|
#define __Pyx_add_no_overflow(a, b, overflow) ((a) + (b)) |
|
|
#define __Pyx_add_const_no_overflow(a, b, overflow) ((a) + (b)) |
|
|
#define __Pyx_sub_no_overflow(a, b, overflow) ((a) - (b)) |
|
|
#define __Pyx_sub_const_no_overflow(a, b, overflow) ((a) - (b)) |
|
|
#define __Pyx_mul_no_overflow(a, b, overflow) ((a) * (b)) |
|
|
#define __Pyx_mul_const_no_overflow(a, b, overflow) ((a) * (b)) |
|
|
#define __Pyx_div_no_overflow(a, b, overflow) ((a) / (b)) |
|
|
#define __Pyx_div_const_no_overflow(a, b, overflow) ((a) / (b)) |
|
|
|
|
|
#if defined(__has_builtin) |
|
|
# if __has_builtin(__builtin_add_overflow) && !defined(__ibmxl__) |
|
|
# define __PYX_HAVE_BUILTIN_OVERFLOW |
|
|
# endif |
|
|
#elif defined(__GNUC__) && (__GNUC__ >= 5) && (!defined(__INTEL_COMPILER) || (__INTEL_COMPILER >= 1800)) |
|
|
# define __PYX_HAVE_BUILTIN_OVERFLOW |
|
|
#endif |
|
|
|
|
|
#if defined(__GNUC__) |
|
|
# define __Pyx_is_constant(x) (__builtin_constant_p(x)) |
|
|
#elif defined(__has_builtin) |
|
|
# if __has_builtin(__builtin_constant_p) |
|
|
# define __Pyx_is_constant(x) (__builtin_constant_p(x)) |
|
|
# endif |
|
|
#else |
|
|
# define __Pyx_is_constant(x) (0) |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if (likely(__Pyx_check_twos_complement() == 0)); else |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{{if UINT == "long long"}}#ifdef HAVE_LONG_LONG{{endif}} |
|
|
|
|
|
static CYTHON_INLINE {{UINT}} __Pyx_add_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow); |
|
|
static CYTHON_INLINE {{UINT}} __Pyx_sub_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow); |
|
|
static CYTHON_INLINE {{UINT}} __Pyx_mul_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow); |
|
|
static CYTHON_INLINE {{UINT}} __Pyx_div_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow); |
|
|
|
|
|
|
|
|
#define __Pyx_add_const_{{NAME}}_checking_overflow __Pyx_add_{{NAME}}_checking_overflow |
|
|
#define __Pyx_sub_const_{{NAME}}_checking_overflow __Pyx_sub_{{NAME}}_checking_overflow |
|
|
#if defined(__PYX_HAVE_BUILTIN_OVERFLOW) |
|
|
#define __Pyx_mul_const_{{NAME}}_checking_overflow __Pyx_mul_{{NAME}}_checking_overflow |
|
|
#else |
|
|
static CYTHON_INLINE {{UINT}} __Pyx_mul_const_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} constant, int *overflow); |
|
|
#endif |
|
|
#define __Pyx_div_const_{{NAME}}_checking_overflow __Pyx_div_{{NAME}}_checking_overflow |
|
|
|
|
|
{{if UINT == "long long"}}#endif{{endif}} |
|
|
|
|
|
|
|
|
|
|
|
{{if UINT == "long long"}}#ifdef HAVE_LONG_LONG{{endif}} |
|
|
|
|
|
#if defined(__PYX_HAVE_BUILTIN_OVERFLOW) |
|
|
|
|
|
static CYTHON_INLINE {{UINT}} __Pyx_add_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) { |
|
|
{{UINT}} result; |
|
|
*overflow |= __builtin_add_overflow(a, b, &result); |
|
|
return result; |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{UINT}} __Pyx_sub_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) { |
|
|
{{UINT}} result; |
|
|
*overflow |= __builtin_sub_overflow(a, b, &result); |
|
|
return result; |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{UINT}} __Pyx_mul_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) { |
|
|
{{UINT}} result; |
|
|
*overflow |= __builtin_mul_overflow(a, b, &result); |
|
|
return result; |
|
|
} |
|
|
|
|
|
#else |
|
|
|
|
|
static CYTHON_INLINE {{UINT}} __Pyx_add_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) { |
|
|
{{UINT}} r = a + b; |
|
|
*overflow |= r < a; |
|
|
return r; |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{UINT}} __Pyx_sub_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) { |
|
|
{{UINT}} r = a - b; |
|
|
*overflow |= r > a; |
|
|
return r; |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{UINT}} __Pyx_mul_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) { |
|
|
|
|
|
if (__Pyx_is_constant(b)) { |
|
|
return __Pyx_mul_const_{{NAME}}_checking_overflow(a, b, overflow); |
|
|
} else if (__Pyx_is_constant(a)) { |
|
|
return __Pyx_mul_const_{{NAME}}_checking_overflow(b, a, overflow); |
|
|
} else if ((sizeof({{UINT}}) < sizeof(unsigned long))) { |
|
|
unsigned long big_r = ((unsigned long) a) * ((unsigned long) b); |
|
|
{{UINT}} r = ({{UINT}}) big_r; |
|
|
*overflow |= big_r != r; |
|
|
return r; |
|
|
#ifdef HAVE_LONG_LONG |
|
|
} else if ((sizeof({{UINT}}) < sizeof(unsigned PY_LONG_LONG))) { |
|
|
unsigned PY_LONG_LONG big_r = ((unsigned PY_LONG_LONG) a) * ((unsigned PY_LONG_LONG) b); |
|
|
{{UINT}} r = ({{UINT}}) big_r; |
|
|
*overflow |= big_r != r; |
|
|
return r; |
|
|
#endif |
|
|
} else { |
|
|
return __Pyx_mul_const_{{NAME}}_checking_overflow(a, b, overflow); |
|
|
} |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{UINT}} __Pyx_mul_const_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) { |
|
|
|
|
|
|
|
|
|
|
|
{{UINT}} prod; |
|
|
if (__Pyx_is_constant(a) && !__Pyx_is_constant(b)) { |
|
|
|
|
|
{{UINT}} temp = b; |
|
|
b = a; |
|
|
a = temp; |
|
|
} |
|
|
prod = a * b; |
|
|
if (b != 0) |
|
|
*overflow |= a > (__PYX_MAX({{UINT}}) / b); |
|
|
return prod; |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
|
static CYTHON_INLINE {{UINT}} __Pyx_div_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) { |
|
|
if (b == 0) { |
|
|
*overflow |= 1; |
|
|
return 0; |
|
|
} |
|
|
return a / b; |
|
|
} |
|
|
|
|
|
{{if UINT == "long long"}}#endif{{endif}} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{{if INT == "long long"}}#ifdef HAVE_LONG_LONG{{endif}} |
|
|
|
|
|
static CYTHON_INLINE {{INT}} __Pyx_add_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow); |
|
|
static CYTHON_INLINE {{INT}} __Pyx_sub_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow); |
|
|
static CYTHON_INLINE {{INT}} __Pyx_mul_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow); |
|
|
static CYTHON_INLINE {{INT}} __Pyx_div_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow); |
|
|
|
|
|
|
|
|
|
|
|
#define __Pyx_add_const_{{NAME}}_checking_overflow __Pyx_add_{{NAME}}_checking_overflow |
|
|
#define __Pyx_sub_const_{{NAME}}_checking_overflow __Pyx_sub_{{NAME}}_checking_overflow |
|
|
#if defined(__PYX_HAVE_BUILTIN_OVERFLOW) |
|
|
#define __Pyx_mul_const_{{NAME}}_checking_overflow __Pyx_mul_{{NAME}}_checking_overflow |
|
|
#else |
|
|
static CYTHON_INLINE {{INT}} __Pyx_mul_const_{{NAME}}_checking_overflow({{INT}} a, {{INT}} constant, int *overflow); |
|
|
#endif |
|
|
#define __Pyx_div_const_{{NAME}}_checking_overflow __Pyx_div_{{NAME}}_checking_overflow |
|
|
|
|
|
{{if INT == "long long"}}#endif{{endif}} |
|
|
|
|
|
|
|
|
|
|
|
{{if INT == "long long"}}#ifdef HAVE_LONG_LONG{{endif}} |
|
|
|
|
|
#if defined(__PYX_HAVE_BUILTIN_OVERFLOW) |
|
|
|
|
|
static CYTHON_INLINE {{INT}} __Pyx_add_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) { |
|
|
{{INT}} result; |
|
|
*overflow |= __builtin_add_overflow(a, b, &result); |
|
|
return result; |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{INT}} __Pyx_sub_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) { |
|
|
{{INT}} result; |
|
|
*overflow |= __builtin_sub_overflow(a, b, &result); |
|
|
return result; |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{INT}} __Pyx_mul_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) { |
|
|
{{INT}} result; |
|
|
*overflow |= __builtin_mul_overflow(a, b, &result); |
|
|
return result; |
|
|
} |
|
|
|
|
|
#else |
|
|
|
|
|
static CYTHON_INLINE {{INT}} __Pyx_add_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) { |
|
|
if ((sizeof({{INT}}) < sizeof(long))) { |
|
|
long big_r = ((long) a) + ((long) b); |
|
|
{{INT}} r = ({{INT}}) big_r; |
|
|
*overflow |= big_r != r; |
|
|
return r; |
|
|
#ifdef HAVE_LONG_LONG |
|
|
} else if ((sizeof({{INT}}) < sizeof(PY_LONG_LONG))) { |
|
|
PY_LONG_LONG big_r = ((PY_LONG_LONG) a) + ((PY_LONG_LONG) b); |
|
|
{{INT}} r = ({{INT}}) big_r; |
|
|
*overflow |= big_r != r; |
|
|
return r; |
|
|
#endif |
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
unsigned {{INT}} r = (unsigned {{INT}}) a + (unsigned {{INT}}) b; |
|
|
|
|
|
|
|
|
*overflow |= (((unsigned {{INT}})a ^ r) & ((unsigned {{INT}})b ^ r)) >> (8 * sizeof({{INT}}) - 1); |
|
|
return ({{INT}}) r; |
|
|
} |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{INT}} __Pyx_sub_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) { |
|
|
|
|
|
unsigned {{INT}} r = (unsigned {{INT}}) a - (unsigned {{INT}}) b; |
|
|
|
|
|
|
|
|
*overflow |= (((unsigned {{INT}})a ^ (unsigned {{INT}})b) & ((unsigned {{INT}})a ^ r)) >> (8 * sizeof({{INT}}) - 1); |
|
|
return ({{INT}}) r; |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{INT}} __Pyx_mul_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) { |
|
|
|
|
|
if (__Pyx_is_constant(b)) { |
|
|
return __Pyx_mul_const_{{NAME}}_checking_overflow(a, b, overflow); |
|
|
} else if (__Pyx_is_constant(a)) { |
|
|
return __Pyx_mul_const_{{NAME}}_checking_overflow(b, a, overflow); |
|
|
} else if ((sizeof({{INT}}) < sizeof(long))) { |
|
|
long big_r = ((long) a) * ((long) b); |
|
|
{{INT}} r = ({{INT}}) big_r; |
|
|
*overflow |= big_r != r; |
|
|
return ({{INT}}) r; |
|
|
#ifdef HAVE_LONG_LONG |
|
|
} else if ((sizeof({{INT}}) < sizeof(PY_LONG_LONG))) { |
|
|
PY_LONG_LONG big_r = ((PY_LONG_LONG) a) * ((PY_LONG_LONG) b); |
|
|
{{INT}} r = ({{INT}}) big_r; |
|
|
*overflow |= big_r != r; |
|
|
return ({{INT}}) r; |
|
|
#endif |
|
|
} else { |
|
|
return __Pyx_mul_const_{{NAME}}_checking_overflow(a, b, overflow); |
|
|
} |
|
|
} |
|
|
|
|
|
static CYTHON_INLINE {{INT}} __Pyx_mul_const_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) { |
|
|
|
|
|
|
|
|
|
|
|
if (__Pyx_is_constant(a) && !__Pyx_is_constant(b)) { |
|
|
|
|
|
{{INT}} temp = b; |
|
|
b = a; |
|
|
a = temp; |
|
|
} |
|
|
if (b > 1) { |
|
|
*overflow |= a > __PYX_MAX({{INT}}) / b; |
|
|
*overflow |= a < __PYX_MIN({{INT}}) / b; |
|
|
} else if (b == -1) { |
|
|
*overflow |= a == __PYX_MIN({{INT}}); |
|
|
} else if (b < -1) { |
|
|
*overflow |= a > __PYX_MIN({{INT}}) / b; |
|
|
*overflow |= a < __PYX_MAX({{INT}}) / b; |
|
|
} |
|
|
return ({{INT}}) (((unsigned {{INT}})a) * ((unsigned {{INT}}) b)); |
|
|
} |
|
|
#endif |
|
|
|
|
|
static CYTHON_INLINE {{INT}} __Pyx_div_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) { |
|
|
if (b == 0) { |
|
|
*overflow |= 1; |
|
|
return 0; |
|
|
} |
|
|
*overflow |= a == __PYX_MIN({{INT}}) && b == -1; |
|
|
return ({{INT}}) ((unsigned {{INT}}) a / (unsigned {{INT}}) b); |
|
|
} |
|
|
|
|
|
{{if INT == "long long"}}#endif{{endif}} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (likely(__Pyx_check_sane_{{NAME}}() == 0)); else |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int __Pyx_check_sane_{{NAME}}(void) { |
|
|
if (((sizeof({{TYPE}}) <= sizeof(int)) || |
|
|
#ifdef HAVE_LONG_LONG |
|
|
(sizeof({{TYPE}}) == sizeof(PY_LONG_LONG)) || |
|
|
#endif |
|
|
(sizeof({{TYPE}}) == sizeof(long)))) { |
|
|
return 0; |
|
|
} else { |
|
|
PyErr_Format(PyExc_RuntimeError, \ |
|
|
"Bad size for int type %.{{max(60, len(TYPE))}}s: %d", "{{TYPE}}", (int) sizeof({{TYPE}})); |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}} a, {{TYPE}} b, int *overflow); |
|
|
|
|
|
|
|
|
|
|
|
static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}} a, {{TYPE}} b, int *overflow) { |
|
|
if ((sizeof({{TYPE}}) < sizeof(int))) { |
|
|
return __Pyx_{{BINOP}}_no_overflow(a, b, overflow); |
|
|
} else if (__PYX_IS_UNSIGNED({{TYPE}})) { |
|
|
if ((sizeof({{TYPE}}) == sizeof(unsigned int))) { |
|
|
return ({{TYPE}}) __Pyx_{{BINOP}}_unsigned_int_checking_overflow(a, b, overflow); |
|
|
} else if ((sizeof({{TYPE}}) == sizeof(unsigned long))) { |
|
|
return ({{TYPE}}) __Pyx_{{BINOP}}_unsigned_long_checking_overflow(a, b, overflow); |
|
|
#ifdef HAVE_LONG_LONG |
|
|
} else if ((sizeof({{TYPE}}) == sizeof(unsigned PY_LONG_LONG))) { |
|
|
return ({{TYPE}}) __Pyx_{{BINOP}}_unsigned_long_long_checking_overflow(a, b, overflow); |
|
|
#endif |
|
|
} else { |
|
|
Py_FatalError( |
|
|
"__Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}}) executed an unexpected code path. " |
|
|
"Please report this as a bug in Cython" |
|
|
); |
|
|
return 0; |
|
|
} |
|
|
} else { |
|
|
if ((sizeof({{TYPE}}) == sizeof(int))) { |
|
|
return ({{TYPE}}) __Pyx_{{BINOP}}_int_checking_overflow(a, b, overflow); |
|
|
} else if ((sizeof({{TYPE}}) == sizeof(long))) { |
|
|
return ({{TYPE}}) __Pyx_{{BINOP}}_long_checking_overflow(a, b, overflow); |
|
|
#ifdef HAVE_LONG_LONG |
|
|
} else if ((sizeof({{TYPE}}) == sizeof(PY_LONG_LONG))) { |
|
|
return ({{TYPE}}) __Pyx_{{BINOP}}_long_long_checking_overflow(a, b, overflow); |
|
|
#endif |
|
|
} else { |
|
|
Py_FatalError( |
|
|
"__Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}}) executed an unexpected code path. " |
|
|
"Please report this as a bug in Cython" |
|
|
); |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static CYTHON_INLINE {{TYPE}} __Pyx_lshift_{{NAME}}_checking_overflow({{TYPE}} a, {{TYPE}} b, int *overflow) { |
|
|
int overflow_check = |
|
|
#if {{SIGNED}} |
|
|
(a < 0) || (b < 0) || |
|
|
#endif |
|
|
|
|
|
(b >= ({{TYPE}}) (8 * sizeof({{TYPE}}))) || (a > (__PYX_MAX({{TYPE}}) >> b)); |
|
|
if (overflow_check) { |
|
|
*overflow |= 1; |
|
|
return 0; |
|
|
} else { |
|
|
return a << b; |
|
|
} |
|
|
} |
|
|
#define __Pyx_lshift_const_{{NAME}}_checking_overflow __Pyx_lshift_{{NAME}}_checking_overflow |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define __Pyx_UNARY_NEG_WOULD_OVERFLOW(x) \ |
|
|
(((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) |
|
|
|