Commit 8da7f0ff authored by Stefan Behnel's avatar Stefan Behnel

avoid compile time dependency on PY_LONG_LONG if user code doesn't explicitly make use of that type

parent 5f8d97cf
...@@ -499,9 +499,11 @@ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject ...@@ -499,9 +499,11 @@ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject
if ((size_t)shiftby <= sizeof(long) * 8 - 2) { if ((size_t)shiftby <= sizeof(long) * 8 - 2) {
long value = 1L << shiftby; long value = 1L << shiftby;
return PyInt_FromLong(value); return PyInt_FromLong(value);
#ifdef HAVE_LONG_LONG
} else if ((size_t)shiftby <= sizeof(unsigned PY_LONG_LONG) * 8 - 1) { } else if ((size_t)shiftby <= sizeof(unsigned PY_LONG_LONG) * 8 - 1) {
unsigned PY_LONG_LONG value = ((unsigned PY_LONG_LONG)1) << shiftby; unsigned PY_LONG_LONG value = ((unsigned PY_LONG_LONG)1) << shiftby;
return PyLong_FromUnsignedLongLong(value); return PyLong_FromUnsignedLongLong(value);
#endif
} else { } else {
PyObject *one = PyInt_FromLong(1L); PyObject *one = PyInt_FromLong(1L);
if (unlikely(!one)) return NULL; if (unlikely(!one)) return NULL;
...@@ -609,8 +611,10 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO ...@@ -609,8 +611,10 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
const long {{'a' if order == 'CObj' else 'b'}} = intval; const long {{'a' if order == 'CObj' else 'b'}} = intval;
long {{ival}}{{if op not in ('Eq', 'Ne')}}, x{{endif}}; long {{ival}}{{if op not in ('Eq', 'Ne')}}, x{{endif}};
{{if op not in ('Eq', 'Ne', 'TrueDivide')}} {{if op not in ('Eq', 'Ne', 'TrueDivide')}}
#ifdef HAVE_LONG_LONG
const PY_LONG_LONG ll{{'a' if order == 'CObj' else 'b'}} = intval; const PY_LONG_LONG ll{{'a' if order == 'CObj' else 'b'}} = intval;
PY_LONG_LONG ll{{ival}}, llx; PY_LONG_LONG ll{{ival}}, llx;
#endif
{{endif}} {{endif}}
const digit* digits = ((PyLongObject*){{pyval}})->ob_digit; const digit* digits = ((PyLongObject*){{pyval}})->ob_digit;
const Py_ssize_t size = Py_SIZE({{pyval}}); const Py_ssize_t size = Py_SIZE({{pyval}});
...@@ -627,9 +631,11 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO ...@@ -627,9 +631,11 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
{{ival}} = {{'-' if _case < 0 else ''}}(long) {{pylong_join(_size, 'digits')}}; {{ival}} = {{'-' if _case < 0 else ''}}(long) {{pylong_join(_size, 'digits')}};
break; break;
{{if op not in ('Eq', 'Ne', 'TrueDivide')}} {{if op not in ('Eq', 'Ne', 'TrueDivide')}}
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > {{_size}} * PyLong_SHIFT) { } else if (8 * sizeof(PY_LONG_LONG) - 1 > {{_size}} * PyLong_SHIFT) {
ll{{ival}} = {{'-' if _case < 0 else ''}}(PY_LONG_LONG) {{pylong_join(_size, 'digits', 'unsigned PY_LONG_LONG')}}; ll{{ival}} = {{'-' if _case < 0 else ''}}(PY_LONG_LONG) {{pylong_join(_size, 'digits', 'unsigned PY_LONG_LONG')}};
goto long_long; goto long_long;
#endif
{{endif}} {{endif}}
} }
// if size doesn't fit into a long or PY_LONG_LONG anymore, fall through to default // if size doesn't fit into a long or PY_LONG_LONG anymore, fall through to default
...@@ -678,15 +684,20 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO ...@@ -678,15 +684,20 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
{{else}} {{else}}
x = a {{c_op}} b; x = a {{c_op}} b;
{{if op == 'Lshift'}} {{if op == 'Lshift'}}
#ifdef HAVE_LONG_LONG
if (unlikely(a != x >> b)) { if (unlikely(a != x >> b)) {
ll{{ival}} = {{ival}}; ll{{ival}} = {{ival}};
goto long_long; goto long_long;
} }
#else
if (likely(a == x >> b)) /* execute return statement below */
#endif
{{endif}} {{endif}}
{{endif}} {{endif}}
return PyLong_FromLong(x); return PyLong_FromLong(x);
{{if op != 'TrueDivide'}} {{if op != 'TrueDivide'}}
#ifdef HAVE_LONG_LONG
long_long: long_long:
{{if c_op == '%'}} {{if c_op == '%'}}
// see ExprNodes.py :: mod_int_utility_code // see ExprNodes.py :: mod_int_utility_code
...@@ -708,8 +719,9 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO ...@@ -708,8 +719,9 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
{{endif}} {{endif}}
{{endif}} {{endif}}
return PyLong_FromLongLong(llx); return PyLong_FromLongLong(llx);
{{endif}} #endif
{{endif}} {{endif}}{# if op != 'TrueDivide' #}
{{endif}}{# if op in ('Eq', 'Ne') #}
} }
#endif #endif
......
...@@ -83,11 +83,13 @@ static CYTHON_INLINE {{UINT}} __Pyx_mul_{{NAME}}_checking_overflow({{UINT}} a, { ...@@ -83,11 +83,13 @@ static CYTHON_INLINE {{UINT}} __Pyx_mul_{{NAME}}_checking_overflow({{UINT}} a, {
{{UINT}} r = ({{UINT}}) big_r; {{UINT}} r = ({{UINT}}) big_r;
*overflow |= big_r != r; *overflow |= big_r != r;
return r; return r;
#ifdef HAVE_LONG_LONG
} else if (sizeof({{UINT}}) < sizeof(unsigned PY_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); unsigned PY_LONG_LONG big_r = ((unsigned PY_LONG_LONG) a) * ((unsigned PY_LONG_LONG) b);
{{UINT}} r = ({{UINT}}) big_r; {{UINT}} r = ({{UINT}}) big_r;
*overflow |= big_r != r; *overflow |= big_r != r;
return r; return r;
#endif
} else { } else {
{{UINT}} prod = a * b; {{UINT}} prod = a * b;
double dprod = ((double) a) * ((double) b); double dprod = ((double) a) * ((double) b);
...@@ -137,11 +139,13 @@ static CYTHON_INLINE {{INT}} __Pyx_add_{{NAME}}_checking_overflow({{INT}} a, {{I ...@@ -137,11 +139,13 @@ static CYTHON_INLINE {{INT}} __Pyx_add_{{NAME}}_checking_overflow({{INT}} a, {{I
{{INT}} r = ({{INT}}) big_r; {{INT}} r = ({{INT}}) big_r;
*overflow |= big_r != r; *overflow |= big_r != r;
return r; return r;
#ifdef HAVE_LONG_LONG
} else if (sizeof({{INT}}) < sizeof(PY_LONG_LONG)) { } else if (sizeof({{INT}}) < sizeof(PY_LONG_LONG)) {
PY_LONG_LONG big_r = ((PY_LONG_LONG) a) + ((PY_LONG_LONG) b); PY_LONG_LONG big_r = ((PY_LONG_LONG) a) + ((PY_LONG_LONG) b);
{{INT}} r = ({{INT}}) big_r; {{INT}} r = ({{INT}}) big_r;
*overflow |= big_r != r; *overflow |= big_r != r;
return r; return r;
#endif
} else { } else {
// Signed overflow undefined, but unsigned overflow is well defined. // Signed overflow undefined, but unsigned overflow is well defined.
{{INT}} r = ({{INT}}) ((unsigned {{INT}}) a + (unsigned {{INT}}) b); {{INT}} r = ({{INT}}) ((unsigned {{INT}}) a + (unsigned {{INT}}) b);
...@@ -181,11 +185,13 @@ static CYTHON_INLINE {{INT}} __Pyx_mul_{{NAME}}_checking_overflow({{INT}} a, {{I ...@@ -181,11 +185,13 @@ static CYTHON_INLINE {{INT}} __Pyx_mul_{{NAME}}_checking_overflow({{INT}} a, {{I
{{INT}} r = ({{INT}}) big_r; {{INT}} r = ({{INT}}) big_r;
*overflow |= big_r != r; *overflow |= big_r != r;
return ({{INT}}) r; return ({{INT}}) r;
#ifdef HAVE_LONG_LONG
} else if (sizeof({{INT}}) < sizeof(PY_LONG_LONG)) { } else if (sizeof({{INT}}) < sizeof(PY_LONG_LONG)) {
PY_LONG_LONG big_r = ((PY_LONG_LONG) a) * ((PY_LONG_LONG) b); PY_LONG_LONG big_r = ((PY_LONG_LONG) a) * ((PY_LONG_LONG) b);
{{INT}} r = ({{INT}}) big_r; {{INT}} r = ({{INT}}) big_r;
*overflow |= big_r != r; *overflow |= big_r != r;
return ({{INT}}) r; return ({{INT}}) r;
#endif
} else { } else {
{{INT}} prod = a * b; {{INT}} prod = a * b;
double dprod = ((double) a) * ((double) b); double dprod = ((double) a) * ((double) b);
...@@ -227,8 +233,10 @@ __Pyx_check_sane_{{NAME}}(); ...@@ -227,8 +233,10 @@ __Pyx_check_sane_{{NAME}}();
static int __Pyx_check_sane_{{NAME}}(void) { static int __Pyx_check_sane_{{NAME}}(void) {
if (sizeof({{TYPE}}) <= sizeof(int) || if (sizeof({{TYPE}}) <= sizeof(int) ||
sizeof({{TYPE}}) == sizeof(long) || #ifdef HAVE_LONG_LONG
sizeof({{TYPE}}) == sizeof(PY_LONG_LONG)) { sizeof({{TYPE}}) == sizeof(PY_LONG_LONG) ||
#endif
sizeof({{TYPE}}) == sizeof(long)) {
return 0; return 0;
} else { } else {
PyErr_Format(PyExc_RuntimeError, \ PyErr_Format(PyExc_RuntimeError, \
...@@ -252,8 +260,10 @@ static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE} ...@@ -252,8 +260,10 @@ static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}
return __Pyx_{{BINOP}}_unsigned_int_checking_overflow(a, b, overflow); return __Pyx_{{BINOP}}_unsigned_int_checking_overflow(a, b, overflow);
} else if (sizeof({{TYPE}}) == sizeof(unsigned long)) { } else if (sizeof({{TYPE}}) == sizeof(unsigned long)) {
return __Pyx_{{BINOP}}_unsigned_long_checking_overflow(a, b, overflow); return __Pyx_{{BINOP}}_unsigned_long_checking_overflow(a, b, overflow);
#ifdef HAVE_LONG_LONG
} else if (sizeof({{TYPE}}) == sizeof(unsigned PY_LONG_LONG)) { } else if (sizeof({{TYPE}}) == sizeof(unsigned PY_LONG_LONG)) {
return __Pyx_{{BINOP}}_unsigned_long_long_checking_overflow(a, b, overflow); return __Pyx_{{BINOP}}_unsigned_long_long_checking_overflow(a, b, overflow);
#endif
} else { } else {
abort(); return 0; // handled elsewhere abort(); return 0; // handled elsewhere
} }
...@@ -262,8 +272,10 @@ static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE} ...@@ -262,8 +272,10 @@ static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}
return __Pyx_{{BINOP}}_int_checking_overflow(a, b, overflow); return __Pyx_{{BINOP}}_int_checking_overflow(a, b, overflow);
} else if (sizeof({{TYPE}}) == sizeof(long)) { } else if (sizeof({{TYPE}}) == sizeof(long)) {
return __Pyx_{{BINOP}}_long_checking_overflow(a, b, overflow); return __Pyx_{{BINOP}}_long_checking_overflow(a, b, overflow);
#ifdef HAVE_LONG_LONG
} else if (sizeof({{TYPE}}) == sizeof(PY_LONG_LONG)) { } else if (sizeof({{TYPE}}) == sizeof(PY_LONG_LONG)) {
return __Pyx_{{BINOP}}_long_long_checking_overflow(a, b, overflow); return __Pyx_{{BINOP}}_long_long_checking_overflow(a, b, overflow);
#endif
} else { } else {
abort(); return 0; // handled elsewhere abort(); return 0; // handled elsewhere
} }
......
...@@ -555,14 +555,18 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value) { ...@@ -555,14 +555,18 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value) {
return PyInt_FromLong((long) value); return PyInt_FromLong((long) value);
} else if (sizeof({{TYPE}}) <= sizeof(unsigned long)) { } else if (sizeof({{TYPE}}) <= sizeof(unsigned long)) {
return PyLong_FromUnsignedLong((unsigned long) value); return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
} else if (sizeof({{TYPE}}) <= sizeof(unsigned PY_LONG_LONG)) { } else if (sizeof({{TYPE}}) <= sizeof(unsigned PY_LONG_LONG)) {
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
} }
} else { } else {
if (sizeof({{TYPE}}) <= sizeof(long)) { if (sizeof({{TYPE}}) <= sizeof(long)) {
return PyInt_FromLong((long) value); return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
} else if (sizeof({{TYPE}}) <= sizeof(PY_LONG_LONG)) { } else if (sizeof({{TYPE}}) <= sizeof(PY_LONG_LONG)) {
return PyLong_FromLongLong((PY_LONG_LONG) value); return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
} }
} }
{ {
...@@ -807,8 +811,10 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) { ...@@ -807,8 +811,10 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
#endif #endif
if (sizeof({{TYPE}}) <= sizeof(unsigned long)) { if (sizeof({{TYPE}}) <= sizeof(unsigned long)) {
__PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, unsigned long, PyLong_AsUnsignedLong(x)) __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
} else if (sizeof({{TYPE}}) <= sizeof(unsigned PY_LONG_LONG)) { } else if (sizeof({{TYPE}}) <= sizeof(unsigned PY_LONG_LONG)) {
__PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
} }
} else { } else {
// signed // signed
...@@ -835,8 +841,10 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) { ...@@ -835,8 +841,10 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
#endif #endif
if (sizeof({{TYPE}}) <= sizeof(long)) { if (sizeof({{TYPE}}) <= sizeof(long)) {
__PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, long, PyLong_AsLong(x)) __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
} else if (sizeof({{TYPE}}) <= sizeof(PY_LONG_LONG)) { } else if (sizeof({{TYPE}}) <= sizeof(PY_LONG_LONG)) {
__PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, PY_LONG_LONG, PyLong_AsLongLong(x)) __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
} }
} }
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment