buffer.c: Give `BufferError' a text message.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 20 Oct 2019 20:08:32 +0000 (21:08 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 25 Nov 2019 17:43:08 +0000 (17:43 +0000)
buffer.c

index 5b7bb64..45888ec 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -46,7 +46,7 @@ static PyTypeObject *rbuf_pytype, *wbuf_pytype;
 
 static PyObject *buferr;
 
-#define BUFERR() do { PyErr_SetNone(buferr); goto end; } while (0)
+#define BUFERR(str) do { PyErr_SetString(buferr, str); goto end; } while (0)
 
 /*----- Read buffers ------------------------------------------------------*/
 
@@ -88,7 +88,7 @@ static PyObject *rbmeth_skip(PyObject *me, PyObject *arg)
   size_t n;
 
   if (!PyArg_ParseTuple(arg, "O&:skip", convszt, &n)) goto end;
-  if (!buf_get(BUF_B(me), n)) BUFERR();
+  if (!buf_get(BUF_B(me), n)) BUFERR("buffer exhausted");
   RETURN_ME;
 end:
   return (0);
@@ -100,7 +100,7 @@ static PyObject *rbmeth_get(PyObject *me, PyObject *arg)
   size_t n;
 
   if (!PyArg_ParseTuple(arg, "O&:get", convszt, &n)) goto end;
-  if ((p = buf_get(BUF_B(me), n)) == 0) BUFERR();
+  if ((p = buf_get(BUF_B(me), n)) == 0) BUFERR("buffer exhausted");
   return (bytestring_pywrap(p, n));
 end:
   return (0);
@@ -111,7 +111,7 @@ end:
   {                                                                    \
     uint##n x;                                                         \
     if (!PyArg_ParseTuple(arg, ":getu" #w)) goto end;                  \
-    if (buf_getu##w(BUF_B(me), &x)) BUFERR();                          \
+    if (buf_getu##w(BUF_B(me), &x)) BUFERR("buffer exhausted");                \
     if (MASK##W <= ULONG_MAX) return (getulong(x));                    \
     else { kludge64 y; ASSIGN64(y, x); return (getk64(y)); }           \
   end:                                                                 \
@@ -125,7 +125,8 @@ DOUINTCONV(RBMETH_GETU_)
     size_t sz;                                                         \
     char *q;                                                           \
     if (!PyArg_ParseTuple(arg, ":getblk" #w)) goto end;                        \
-    if ((q = buf_getmem##w(BUF_B(me), &sz)) == 0) BUFERR();            \
+    if ((q = buf_getmem##w(BUF_B(me), &sz)) == 0)                      \
+      BUFERR("buffer exhausted");                                      \
     return (bytestring_pywrap(q, sz));                                 \
   end:                                                                 \
     return (0);                                                                \
@@ -138,7 +139,7 @@ BUF_DOSUFFIXES(RBMETH_GETBLK_)
     buf_pyobj *b;                                                      \
     buf bb;                                                            \
     if (!PyArg_ParseTuple(arg, ":getbuf" #w)) goto end;                        \
-    if (buf_getbuf##w(BUF_B(me), &bb)) BUFERR();                       \
+    if (buf_getbuf##w(BUF_B(me), &bb)) BUFERR("buffer exhausted");     \
     b = PyObject_NEW(buf_pyobj, rbuf_pytype);                          \
     b->b = bb;                                                         \
     b->sub = me;                                                       \
@@ -153,7 +154,7 @@ static PyObject *rbmeth_getmp(PyObject *me, PyObject *arg)
 {
   mp *x;
   if (!PyArg_ParseTuple(arg, ":getmp")) goto end;
-  if ((x = buf_getmp(BUF_B(me))) == 0) BUFERR();
+  if ((x = buf_getmp(BUF_B(me))) == 0) BUFERR("buffer exhausted");
   return (mp_pywrap(x));
 end:
   return (0);
@@ -163,7 +164,7 @@ static PyObject *rbmeth_getgf(PyObject *me, PyObject *arg)
 {
   mp *x;
   if (!PyArg_ParseTuple(arg, ":getgf")) goto end;
-  if ((x = buf_getmp(BUF_B(me))) == 0) BUFERR();
+  if ((x = buf_getmp(BUF_B(me))) == 0) BUFERR("buffer exhausted");
   return (gf_pywrap(x));
 end:
   return (0);
@@ -180,7 +181,7 @@ static PyObject *rbmeth_getecpt(PyObject *me, PyObject *arg, PyObject *kw)
   if (!PyType_Check(cobj) ||
       !PyType_IsSubtype((PyTypeObject *)cobj, ecpt_pytype))
     TYERR("expected elliptic curve type");
-  if (buf_getec(BUF_B(me), &pt)) BUFERR();
+  if (buf_getec(BUF_B(me), &pt)) BUFERR("buffer exhausted");
   return (ecpt_pywrapout(cobj, &pt));
 end:
   return (0);
@@ -192,7 +193,7 @@ static PyObject *rbmeth_getecptraw(PyObject *me, PyObject *arg)
   ec pt = EC_INIT;
   if (!PyArg_ParseTuple(arg, "O!:getecptraw", eccurve_pytype, &cobj))
     goto end;
-  if (ec_getraw(ECCURVE_C(cobj), BUF_B(me), &pt)) BUFERR();
+  if (ec_getraw(ECCURVE_C(cobj), BUF_B(me), &pt)) BUFERR("buffer exhausted");
   return (ecpt_pywrapout(cobj, &pt));
 end:
   return (0);
@@ -204,7 +205,7 @@ static PyObject *rbmeth_getge(PyObject *me, PyObject *arg)
   ge *x = 0;
   if (!PyArg_ParseTuple(arg, "O!:getge", group_pytype, &gobj)) goto end;
   x = G_CREATE(GROUP_G(gobj));
-  if (G_FROMBUF(GROUP_G(gobj), BUF_B(me), x)) BUFERR();
+  if (G_FROMBUF(GROUP_G(gobj), BUF_B(me), x)) BUFERR("buffer exhausted");
   return (ge_pywrap(gobj, x));
 end:
   if (x) G_DESTROY(GROUP_G(gobj), x);
@@ -217,7 +218,7 @@ static PyObject *rbmeth_getgeraw(PyObject *me, PyObject *arg)
   ge *x = 0;
   if (!PyArg_ParseTuple(arg, "O!:getgeraw", group_pytype, &gobj)) goto end;
   x = G_CREATE(GROUP_G(gobj));
-  if (G_FROMRAW(GROUP_G(gobj), BUF_B(me), x)) BUFERR();
+  if (G_FROMRAW(GROUP_G(gobj), BUF_B(me), x)) BUFERR("buffer exhausted");
   return (ge_pywrap(gobj, x));
 end:
   if (x) G_DESTROY(GROUP_G(gobj), x);