From da0c047c0e6b1abd5c7e348e373ccafa9ece7a8d Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 9 Mar 2013 17:28:19 +0100 Subject: [PATCH] add safety guard for ill defined user types --- Cython/Compiler/PyrexTypes.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 557a77a..4cf07b5 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1410,18 +1410,22 @@ static CYTHON_INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject* x return (%(type)s)-1; } #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (%(type)s) ((PyLongObject*)x)->ob_digit[0]; + if (sizeof(digit) <= sizeof(%(type)s)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return (%(type)s) ((PyLongObject*)x)->ob_digit[0]; + } } #endif return (%(type)s)PyLong_AsUnsigned%(TypeName)s(x); } else { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(%(type)s) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(%(type)s) ((PyLongObject*)x)->ob_digit[0]; + if (sizeof(digit) <= sizeof(%(type)s)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return +(%(type)s) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(%(type)s) ((PyLongObject*)x)->ob_digit[0]; + } } #endif return (%(type)s)PyLong_As%(TypeName)s(x); -- 2.7.4