gf: Make GF.fromstring consistent with MP.fromstring
authorMark Wooding <mdw@distorted.org.uk>
Sat, 4 Feb 2006 17:53:52 +0000 (17:53 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 4 Feb 2006 17:53:52 +0000 (17:53 +0000)
The latter raises an exception if given an empty string, and reports
`bad radix' if it is, rather than `out of range'.

mp.c

diff --git a/mp.c b/mp.c
index 0c0dd86..f31691e 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -2070,13 +2070,14 @@ static PyObject *meth__GF_fromstring(PyObject *me,
   if (!PyArg_ParseTupleAndKeywords(arg, kw, "Os#|i:fromstring",
                                   kwlist, &me, &p, &len, &r))
     goto end;
-  if (!good_radix_p(r, 1)) VALERR("radix out of range");
+  if (!good_radix_p(r, 1)) VALERR("bad radix");
   sc.buf = p; sc.lim = p + len;
-  if ((zz = mp_read(MP_NEW, r, &mptext_stringops, &sc)) == 0 || MP_NEGP(zz))
-    z = Py_BuildValue("(Os#)", Py_None, p, len);
-  else
-    z = Py_BuildValue("(Ns#)", gf_pywrap(zz),
-                     sc.buf, (int)(sc.lim - sc.buf));
+  if ((zz = mp_read(MP_NEW, r, &mptext_stringops, &sc)) == 0 ||
+      MP_NEGP(zz)) {
+    if (zz) MP_DROP(zz);
+    SYNERR("bad binary polynomial");
+  }
+  z = Py_BuildValue("(Ns#)", gf_pywrap(zz), sc.buf, (int)(sc.lim - sc.buf));
 end:
   return (z);
 }