static PyObject *pfilt_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
{
- char *kwlist[] = { "x", 0 };
+ static const char *const kwlist[] = { "x", 0 };
PyObject *xobj;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", kwlist, &xobj))
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", KWLIST, &xobj))
return (0);
return (pfilt_pymake(ty, xobj));
}
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Small-primes filter.",
+ "PrimeFilter(X): small-primes filter.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
{
mp *x = 0;
rabin_pyobj *o = 0;
- char *kwlist[] = { "x", 0 };
+ static const char *const kwlist[] = { "x", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:new", kwlist, convmp, &x))
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:new", KWLIST, convmp, &x))
goto end;
if (!MP_POSP(x) || MP_EVENP(x)) VALERR("must be positive and odd");
o = (rabin_pyobj *)ty->tp_alloc(ty, 0);
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Rabin-Miller strong primality test.",
+ "RabinMiller(X): Rabin-Miller strong primality test.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
static void pgevent_pydealloc(PyObject *me)
{
pgevent_pyobj *ev = (pgevent_pyobj *)me;
- if (ev->r) Py_DECREF(ev->r);
- FREEOBJ(me);
+ Py_XDECREF(ev->r); FREEOBJ(me);
}
#define PGEVENT_CHECK(me) do { \
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Prime-generation event.",
+ "Prime-generation event.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
PyObject *rc = 0;
int st = PGEN_ABORT;
long l;
- char *meth[] = {
- "pg_abort", "pg_done", "pg_begin", "pg_try", "pg_fail", "pg_pass"
- };
+ static const char *const meth[] =
+ { "pg_abort", "pg_done", "pg_begin", "pg_try", "pg_fail", "pg_pass" };
rq++;
if (rq > N(meth)) SYSERR("event code out of range");
pyev = pgevent_pywrap(ev);
- if ((rc = PyObject_CallMethod(pg->obj, meth[rq], "(O)", pyev)) == 0)
+ if ((rc = PyObject_CallMethod(pg->obj, (/*unconst*/ char *)meth[rq],
+ "(O)", pyev)) == 0)
goto end;
if (rc == Py_None)
st = PGEN_TRY;
static PyMethodDef pgev_pymethods[] = {
#define METHNAME(name) pgmeth_##name
- METH (pg_abort, "E.pg_abort(EV) -> PGRC -- prime generation aborted")
- METH (pg_done, "E.pg_done(EV) -> PGRC -- prime generation finished")
- METH (pg_begin, "E.pg_begin(EV) -> PGRC -- commence stepping/testing")
- METH (pg_try, "E.pg_try(EV) -> PGRC -- found new candidate")
- METH (pg_pass, "E.pg_pass(EV) -> PGRC -- passed primality test")
- METH (pg_fail, "E.pg_fail(EV) -> PGRC -- failed primality test")
+ METH (pg_abort, "E.pg_abort(EV) -> PGST -- prime generation aborted")
+ METH (pg_done, "E.pg_done(EV) -> PGST -- prime generation finished")
+ METH (pg_begin, "E.pg_begin(EV) -> PGST -- commence stepping/testing")
+ METH (pg_try, "E.pg_try(EV) -> PGST -- found new candidate")
+ METH (pg_pass, "E.pg_pass(EV) -> PGST -- passed primality test")
+ METH (pg_fail, "E.pg_fail(EV) -> PGST -- failed primality test")
#undef METHNAME
{ 0 }
};
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Built-in prime-generation event handler, base class.",
+ "Built-in prime-generation event handler, base class.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
{
mpw s;
pgstep_pyobj *rc = 0;
- char *kwlist[] = { "step", 0 };
+ static const char *const kwlist[] = { "step", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:new", kwlist, convmpw, &s))
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:new", KWLIST, convmpw, &s))
goto end;
rc = (pgstep_pyobj *)ty->tp_alloc(ty, 0);
rc->f.step = s;
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
- "Simple prime-number stepper with small-factors filter.",
+ "PrimeGenStepper(STEP): simple stepper with small-factors filter.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
{
PyObject *o, *fobj;
pgjump_pyobj *rc = 0;
- char *kwlist[] = { "jump", 0 };
+ static const char *const kwlist[] = { "jump", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", kwlist, &o) ||
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", KWLIST, &o) ||
(fobj = pfilt_pymake(pfilt_pytype, o)) == 0)
goto end;
rc = (pgjump_pyobj *)ty->tp_alloc(ty, 0);
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Stepper for larger steps, with small-factors filter.",
+ "PrimeGenJumper(JUMP): "
+ "stepper for larger steps with small-factors filter.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
static PyObject *pgtest_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
{
pgtest_pyobj *rc = 0;
- char *kwlist[] = { 0 };
+ static const char *const kwlist[] = { 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", kwlist)) goto end;
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST)) goto end;
rc = (pgtest_pyobj *)ty->tp_alloc(ty, 0);
rc->pg.proc = pgen_test;
rc->pg.ctx = &rc->r;
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Rabin-Miller tester.",
+ "PrimeGenTester(): Rabin-Miller tester.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
struct excinfo exc = EXCINFO_INIT;
pypgev step = { { 0 } }, test = { { 0 } }, evt = { { 0 } };
unsigned nsteps = 0, ntests = 0;
- char *kwlist[] = { "start", "name", "stepper", "tester", "event",
- "nsteps", "ntests", 0 };
+ static const char *const kwlist[] =
+ { "start", "name", "stepper", "tester", "event", "nsteps", "ntests", 0 };
step.exc = &exc; step.ev.proc = pgen_filter; step.ev.ctx = &fc;
test.exc = &exc; test.ev.proc = pgen_test; test.ev.ctx = &tc;
evt.exc = &exc;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|sO&O&O&O&O&:pgen", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|sO&O&O&O&O&:pgen", KWLIST,
convmp, &x, &p, convpgev, &step,
convpgev, &test, convpgev, &evt,
convuint, &nsteps, convuint, &ntests))
struct excinfo exc = EXCINFO_INIT;
pypgev evt = { { 0 } };
PyObject *rc = 0;
- char *kwlist[] = { "nbits", "name", "event", "rng", "nsteps", 0 };
+ static const char *const kwlist[] =
+ { "nbits", "name", "event", "rng", "nsteps", 0 };
evt.exc = &exc;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|sO&O&O&", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|sO&O&O&", KWLIST,
convuint, &nbits, &name,
convpgev, &evt, convgrand, &r,
convuint, &n))
struct excinfo exc = EXCINFO_INIT;
pypgev evt = { { 0 } };
PyObject *rc = 0;
- char *kwlist[] = { "nbits", "name", "event", "rng", "nsteps", 0 };
+ static const char *const kwlist[] =
+ { "nbits", "name", "event", "rng", "nsteps", 0 };
evt.exc = &exc;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|sO&O&O&", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|sO&O&O&", KWLIST,
convuint, &nbits, &name,
convpgev, &evt, convgrand, &r,
convuint, &n))
unsigned on = 0;
size_t i, nf = 0;
PyObject *rc = 0, *vec;
- char *kwlist[] = { "pbits", "qbits", "name", "event", "ievent",
- "rng", "nsteps", 0 };
+ static const char *const kwlist[] =
+ { "pbits", "qbits", "name", "event", "ievent", "rng", "nsteps", 0 };
mp *x = 0, **v = 0;
ie.exc = oe.exc = &exc;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&|sO&O&O&O&:limlee", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&|sO&O&O&O&:limlee", KWLIST,
convuint, &pl, convuint, &ql,
&p, convpgev, &oe, convpgev, &ie,
convgrand, &r, convuint, &on))
PGENERR(&exc);;
vec = PyList_New(nf);
for (i = 0; i < nf; i++)
- PyList_SetItem(vec, i, mp_pywrap(v[i]));
+ PyList_SET_ITEM(vec, i, mp_pywrap(v[i]));
xfree(v);
rc = Py_BuildValue("(NN)", mp_pywrap(x), vec);
end:
static PyMethodDef methods[] = {
#define METHNAME(name) meth_##name
- METH (_PrimeFilter_smallfactor, "smallfactor(X) -> PGRC")
- METH (_RabinMiller_iters, "iters(NBITS) -> NITERS")
- KWMETH(pgen, "\
-pgen(START, [name = 'p'[, [stepper = PrimeGenStepper(2)],\n\
- [tester = PrimeGenTester()], [event = pgen_nullev],\n\
- [nsteps = 0], [ntests = RabinMiller.iters(START.nbits)]) -> P")
- KWMETH(strongprime_setup, "\
-strongprime_setup(NBITS, [name = 'p'], [event = pgen_nullev],\n\
- [rng = rand], [nsteps = 0]) -> (START, JUMP)")
- KWMETH(strongprime, "\
-strongprime(NBITS, [name = 'p'], [event = pgen_nullev],\n\
- [rng = rand], [nsteps = 0]) -> P")
- KWMETH(limlee, "\
-limlee(PBITS, QBITS, [name = 'p'], [event = pgen_nullev],\n\
- [ievent = pgen_nullev], [rng = rand], [nsteps = 0]) -> (P, [Q, ...])")
+ METH (_PrimeFilter_smallfactor, "smallfactor(X) -> PGRC")
+ METH (_RabinMiller_iters, "iters(NBITS) -> NITERS")
+ KWMETH(pgen,
+ "pgen(START, [name = 'p'], [stepper = PrimeGenStepper(2)],\n"
+ " [tester = PrimeGenTester()], [event = pgen_nullev],\n"
+ " [nsteps = 0], [ntests = RabinMiller.iters(START.nbits)]) -> P")
+ KWMETH(strongprime_setup,
+ "strongprime_setup(NBITS, [name = 'p'], [event = pgen_nullev],\n"
+ " [rng = rand], [nsteps = 0]) -> (START, JUMP)")
+ KWMETH(strongprime,
+ "strongprime(NBITS, [name = 'p'], [event = pgen_nullev],\n"
+ " [rng = rand], [nsteps = 0]) -> P")
+ KWMETH(limlee,
+ "limlee(PBITS, QBITS, [name = 'p'], [event = pgen_nullev],\n"
+ " [ievent = pgen_nullev], [rng = rand], [nsteps = 0]) "
+ "-> (P, [Q, ...])")
#undef METHNAME
{ 0 }
};