From 4b3890c73f33bfa86f927e66592a4e9e8ef33203 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 4 Feb 2006 17:53:52 +0000 Subject: [PATCH] gf: Make GF.fromstring consistent with MP.fromstring The latter raises an exception if given an empty string, and reports `bad radix' if it is, rather than `out of range'. --- mp.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mp.c b/mp.c index 0c0dd86..f31691e 100644 --- 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); } -- 2.11.0