imported patch shrink-int-convert
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 11 Sep 2009 04:22:34 +0000 (21:22 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 11 Sep 2009 04:22:34 +0000 (21:22 -0700)
Cython/Compiler/PyrexTypes.py

index 2c393992b8b0265b23f9ec35a21b228f5114ccfc..dd43f0a6e9ee40ef5db4983d68925548457db9fc 100644 (file)
@@ -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;