+static PyObject *mpmeth_fromstring(PyObject *me,
+ PyObject *arg, PyObject *kw)
+{
+ int r = 0;
+ char *p;
+ Py_ssize_t len;
+ PyObject *z = 0;
+ mp *zz;
+ mptext_stringctx sc;
+ static const char *const kwlist[] = { "x", "radix", 0 };
+
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#|i:fromstring", KWLIST,
+ &p, &len, &r))
+ goto end;
+ 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)
+ VALERR("bad integer");
+ z = Py_BuildValue("(Ns#)", mp_pywrap(zz),
+ sc.buf, (Py_ssize_t)(sc.lim - sc.buf));
+end:
+ return (z);
+}
+
+static PyObject *mpmeth_factorial(PyObject *me, PyObject *arg)
+{
+ unsigned long i;
+ mp *x;
+ if (!PyArg_ParseTuple(arg, "O&:factorial", convulong, &i)) return (0);
+ x = mp_factorial(i);
+ return mp_pywrap(x);
+}
+
+static PyObject *mpmeth_fibonacci(PyObject *me, PyObject *arg)
+{
+ long i;
+ mp *x;
+ if (!PyArg_ParseTuple(arg, "l:fibonacci", &i)) return (0);
+ x = mp_fibonacci(i);
+ return mp_pywrap(x);
+}
+
+#define LOADOP(pre, name) \
+ static PyObject *pre##meth_##name(PyObject *me, PyObject *arg) \
+ { \
+ char *p; \
+ Py_ssize_t len; \
+ if (!PyArg_ParseTuple(arg, "s#:" #name, &p, &len)) return (0); \
+ return (pre##_pywrap(mp_##name(MP_NEW, p, len))); \
+ }
+LOADOP(mp, loadl)
+LOADOP(mp, loadb)
+LOADOP(mp, loadl2c)
+LOADOP(mp, loadb2c)
+LOADOP(gf, loadl)
+LOADOP(gf, loadb)
+#undef LOADOP
+