From: Mark Wooding Date: Sat, 23 Nov 2019 15:05:39 +0000 (+0000) Subject: pyke/pyke-mLib.c: Raise `OverflowError' on out-of-range inputs. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/b4dbeed57af31ba6b03c3eda36168d36c26de954?hp=37e554049676f4a826fa783eacbbee20e763f4b7 pyke/pyke-mLib.c: Raise `OverflowError' on out-of-range inputs. This seems to match better what Python does under these conditions. --- diff --git a/pyke/pyke-mLib.c b/pyke/pyke-mLib.c index 30f6735..900dc41 100644 --- a/pyke/pyke-mLib.c +++ b/pyke/pyke-mLib.c @@ -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; diff --git a/t/t-algorithms.py b/t/t-algorithms.py index 261c53b..593e6cf 100644 --- a/t/t-algorithms.py +++ b/t/t-algorithms.py @@ -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'.""" diff --git a/t/t-buffer.py b/t/t-buffer.py index 21a83d8..db51226 100644 --- a/t/t-buffer.py +++ b/t/t-buffer.py @@ -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'."""