chiark / gitweb /
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>
Sat, 11 Apr 2020 11:49:31 +0000 (12:49 +0100)
This seems to match better what Python does under these conditions.

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

index 30f6735e8a9c63bf24c9a8dffac04f49763d0e0f..900dc41524a5fe884b41466db32f8228b0c6c597 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 261c53bf05e5aab36b6d5221510c29c319166971..593e6cf2e9524c21611e37b397b83261dbc58d35 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 21a83d869efe22613f31060b4c5b2a774091ec30..db512261dba78f06ff1043c41837db99ef07235d 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'."""