From 5ef8c817f6248c9799c8b5590e1572671345d000 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 10 Sep 2009 21:22:34 -0700 Subject: [PATCH] imported patch shrink-int-convert --- Cython/Compiler/PyrexTypes.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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; -- 2.26.2