From: Robert Bradshaw Date: Fri, 11 Sep 2009 04:22:34 +0000 (-0700) Subject: imported patch shrink-int-convert X-Git-Tag: 0.11.3.rc0~17 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5ef8c817f6248c9799c8b5590e1572671345d000;p=cython.git imported patch shrink-int-convert --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 2c393992..dd43f0a6 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -599,15 +599,12 @@ static INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject* x) { if (sizeof(%(type)s) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(%(type)s)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (%(type)s)-1; - if (((%(type)s)-1) > ((%(type)s)0) && unlikely(val < 0)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to %(type)s"); - return (%(type)s)-1; + (((%(type)s)-1) > ((%(type)s)0) && unlikely(val < 0)) ? + "can't convert negative value to %(type)s" : + "value too large to convert to %(type)s"); } - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to %(type)s"); return (%(type)s)-1; } return (%(type)s)val;