Commit da0c047c authored by Stefan Behnel's avatar Stefan Behnel

add safety guard for ill defined user types

parent b525cf34
...@@ -1410,18 +1410,22 @@ static CYTHON_INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject* x ...@@ -1410,18 +1410,22 @@ static CYTHON_INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject* x
return (%(type)s)-1; return (%(type)s)-1;
} }
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
switch (Py_SIZE(x)) { if (sizeof(digit) <= sizeof(%(type)s)) {
case 0: return 0; switch (Py_SIZE(x)) {
case 1: return (%(type)s) ((PyLongObject*)x)->ob_digit[0]; case 0: return 0;
case 1: return (%(type)s) ((PyLongObject*)x)->ob_digit[0];
}
} }
#endif #endif
return (%(type)s)PyLong_AsUnsigned%(TypeName)s(x); return (%(type)s)PyLong_AsUnsigned%(TypeName)s(x);
} else { } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
switch (Py_SIZE(x)) { if (sizeof(digit) <= sizeof(%(type)s)) {
case 0: return 0; switch (Py_SIZE(x)) {
case 1: return +(%(type)s) ((PyLongObject*)x)->ob_digit[0]; case 0: return 0;
case -1: return -(%(type)s) ((PyLongObject*)x)->ob_digit[0]; case 1: return +(%(type)s) ((PyLongObject*)x)->ob_digit[0];
case -1: return -(%(type)s) ((PyLongObject*)x)->ob_digit[0];
}
} }
#endif #endif
return (%(type)s)PyLong_As%(TypeName)s(x); return (%(type)s)PyLong_As%(TypeName)s(x);
......
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