mp.c: Fix overly ambitious section header.
[catacomb-python] / mp.c
diff --git a/mp.c b/mp.c
index 3abbcd5..6ce2792 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -122,6 +122,12 @@ mp *mp_frompyobject(PyObject *o, int radix)
     mp *x;
     size_t sz;
     TEXT_PTRLEN(o, sc.buf, sz); sc.lim = sc.buf + sz;
+    if (sc.buf + 2 < sc.lim && sc.buf[0] == '0' &&
+       (radix == 16 ? (sc.buf[1] == 'x' || sc.buf[1] == 'X') :
+        radix ==  8 ? (sc.buf[1] == 'o' || sc.buf[1] == 'O') :
+        radix ==  2 ? (sc.buf[1] == 'b' || sc.buf[1] == 'B') :
+        0))
+      sc.buf += 2;
     x = mp_read(MP_NEW, radix, &mptext_stringops, &sc);
     if (!x) return (0);
     if (sc.buf < sc.lim) { MP_DROP(x); return (0); }
@@ -196,7 +202,7 @@ end:
   return (rc);
 }
 
-/*----- Python interface --------------------------------------------------*/
+/*----- Arbitrary-precision integers --------------------------------------*/
 
 static void mp_pydealloc(PyObject *o)
 {
@@ -1783,12 +1789,10 @@ static PyObject *mcmeth_solve(PyObject *me, PyObject *arg)
   mp **v = 0;
   Py_ssize_t i = 0, n = c->k;
 
-  Py_INCREF(me);
   if (PyTuple_GET_SIZE(arg) == n)
     q = arg;
   else if (!PyArg_ParseTuple(arg, "O:solve", &q))
     goto end;
-  Py_INCREF(q);
   if (!PySequence_Check(q)) TYERR("want a sequence of residues");
   i = PySequence_Size(q); if (i < 0) goto end;
   if (i != n) VALERR("residue count mismatch");
@@ -1806,8 +1810,6 @@ end:
       MP_DROP(v[i]);
     xfree(v);
   }
-  Py_DECREF(me);
-  Py_XDECREF(q);
   return (z);
 }
 
@@ -1832,7 +1834,6 @@ static PyObject *mpcrt_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
     q = arg;
   else if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", KWLIST, &q))
     goto end;
-  Py_INCREF(q);
   if (!PySequence_Check(q)) TYERR("want a sequence of moduli");
   n = PySequence_Size(q); if (n < 0) goto end;
   if (!n) VALERR("want at least one modulus");
@@ -1854,7 +1855,6 @@ static PyObject *mpcrt_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
 
   c = (mpcrt_pyobj *)ty->tp_alloc(ty, 0);
   mpcrt_create(&c->c, v, n, 0);
-  Py_DECREF(q);
   mp_drop(xx); mp_drop(y); mp_drop(g);
   return ((PyObject *)c);
 
@@ -1865,7 +1865,6 @@ end:
       MP_DROP(v[i].m);
     xfree(v);
   }
-  Py_XDECREF(q);
   mp_drop(xx); mp_drop(y); mp_drop(g);
   return (0);
 }