pyke/pyke-mLib.c: Raise `OverflowError' on out-of-range inputs.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 23 Nov 2019 15:05:39 +0000 (15:05 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 25 Nov 2019 17:51:31 +0000 (17:51 +0000)
This seems to match better what Python does under these conditions.

pyke/pyke-mLib.c
t/t-algorithms.py
t/t-buffer.py

index 30f6735..900dc41 100644 (file)
@@ -70,7 +70,7 @@ end:
      uint64 t;                                                         \
      if (!convk64(o, &k)) goto end;                                    \
      t = GET64(uint64, k);                                             \
-     if (t > MASK##n) VALERR("out of range");                          \
+     if (t > MASK##n) OVFERR("out of range");                          \
      *p = t;                                                           \
    } while (0)
 #else
@@ -87,7 +87,7 @@ end:
       CONVu64(n);                                                      \
     else {                                                             \
       if (!convulong(o, &u)) goto end;                                 \
-      if (u > MASK##n) VALERR("out of range");                         \
+      if (u > MASK##n) OVFERR("out of range");                         \
       *p = u;                                                          \
     }                                                                  \
     return (1);                                                                \
@@ -121,7 +121,7 @@ int convk64(PyObject *o, void *pp)
   hi = PyInt_AsUnsignedLongMask(i);
   if ((t = PyNumber_InPlaceRshift(i, i32)) == 0) goto end;
   Py_DECREF(i); i = t;
-  if (PyObject_IsTrue(i)) VALERR("out of range");
+  if (PyObject_IsTrue(i)) OVFERR("out of range");
   SET64(*(kludge64 *)pp, hi, lo);
 #endif
   rc = 1;
index 261c53b..593e6cf 100644 (file)
@@ -76,8 +76,7 @@ class HashBufferTestMixin (U.TestCase):
 
     ## Check overflow detection.
     h0, _ = makefn(w)
-    me.assertRaises((OverflowError, ValueError),
-                    hashfn, h0, 1 << 8*w)
+    me.assertRaises(OverflowError, hashfn, h0, 1 << 8*w)
 
   def check_hashbuffer_bufn(me, w, bigendp, makefn, hashfn):
     """Check `hashbufN'."""
index 21a83d8..db51226 100644 (file)
@@ -186,8 +186,7 @@ class TestWriteBuffer (U.TestCase):
     me.assertEqual(putfn(C.WriteBuffer(), C.MP(0)).contents, w*C.bytes("00"))
 
     ## Check overflow detection.
-    me.assertRaises((OverflowError, ValueError),
-                    putfn, C.WriteBuffer(), 1 << 8*w)
+    me.assertRaises(OverflowError, putfn, C.WriteBuffer(), 1 << 8*w)
 
   def check_putbufn(me, w, bigendp, putfn):
     """Check `putblkN'."""