X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/fb23e96c70a3537e72f796973c9d370c7d57029d..f281293ca70de172b275ecb3224ea36839f2f830:/pgen.c diff --git a/pgen.c b/pgen.c index 8e1911b..dd2d827 100644 --- a/pgen.c +++ b/pgen.c @@ -134,7 +134,7 @@ static PyObject *pfget_x(PyObject *me, void *hunoz) static PyObject *pfget_status(PyObject *me, void *hunoz) { return (PyInt_FromLong(PFILT_ST(me))); } -static PyGetSetDef pfilt_pygetset[] = { +static const PyGetSetDef pfilt_pygetset[] = { #define GETSETNAME(op, name) pf##op##_##name GET (x, "F.x -> current position of filter") GET (status, "F.status -> primality status of filter") @@ -142,7 +142,7 @@ static PyGetSetDef pfilt_pygetset[] = { { 0 } }; -static PyMethodDef pfilt_pymethods[] = { +static const PyMethodDef pfilt_pymethods[] = { #define METHNAME(name) pfmeth_##name METH (step, "F.step(N)") METH (muladd, "F.muladd(M, A)") @@ -151,7 +151,7 @@ static PyMethodDef pfilt_pymethods[] = { { 0 } }; -static PyNumberMethods pfilt_pynumber = { +static const PyNumberMethods pfilt_pynumber = { 0, /* @nb_add@ */ 0, /* @nb_subtract@ */ 0, /* @nb_multiply@ */ @@ -206,7 +206,7 @@ static PyTypeObject pfilt_pytype_skel = { 0, /* @tp_setattr@ */ 0, /* @tp_compare@ */ 0, /* @tp_repr@ */ - &pfilt_pynumber, /* @tp_as_number@ */ + PYNUMBER(pfilt), /* @tp_as_number@ */ 0, /* @tp_as_sequence@ */ 0, /* @tp_as_mapping@ */ 0, /* @tp_hash@ */ @@ -219,7 +219,7 @@ static PyTypeObject pfilt_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"PrimeFilter(X): small-primes filter.", + "PrimeFilter(X): small-primes filter.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -227,9 +227,9 @@ static PyTypeObject pfilt_pytype_skel = { 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ 0, /* @tp_iternext@ */ - pfilt_pymethods, /* @tp_methods@ */ + PYMETHODS(pfilt), /* @tp_methods@ */ 0, /* @tp_members@ */ - pfilt_pygetset, /* @tp_getset@ */ + PYGETSET(pfilt), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -311,7 +311,7 @@ static PyObject *meth__RabinMiller_iters(PyObject *me, PyObject *arg) return (PyInt_FromLong(rabin_iters(n))); } -static PyGetSetDef rabin_pygetset[] = { +static const PyGetSetDef rabin_pygetset[] = { #define GETSETNAME(op, name) r##op##_##name GET (x, "R.x -> number under test") GET (niters, "R.niters -> suggested number of tests") @@ -319,7 +319,7 @@ static PyGetSetDef rabin_pygetset[] = { { 0 } }; -static PyMethodDef rabin_pymethods[] = { +static const PyMethodDef rabin_pymethods[] = { #define METHNAME(name) rmeth_##name METH (test, "R.test(W) -> PGST") METH (rtest, "R.rtest(W) -> PGST") @@ -352,7 +352,7 @@ static PyTypeObject rabin_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"RabinMiller(X): Rabin-Miller strong primality test.", + "RabinMiller(X): Rabin-Miller strong primality test.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -360,9 +360,9 @@ static PyTypeObject rabin_pytype_skel = { 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ 0, /* @tp_iternext@ */ - rabin_pymethods, /* @tp_methods@ */ + PYMETHODS(rabin), /* @tp_methods@ */ 0, /* @tp_members@ */ - rabin_pygetset, /* @tp_getset@ */ + PYGETSET(rabin), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -406,8 +406,7 @@ static void pgevent_kill(PyObject *me) 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 { \ @@ -454,7 +453,7 @@ end: return (rc); } -static PyGetSetDef pgevent_pygetset[] = { +static const PyGetSetDef pgevent_pygetset[] = { #define GETSETNAME(op, name) pe##op##_##name GET (name, "EV.name -> value being generated") GETSET(x, "EV.x -> value under test") @@ -490,7 +489,7 @@ static PyTypeObject pgevent_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Prime-generation event.", + "Prime-generation event.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -500,7 +499,7 @@ static PyTypeObject pgevent_pytype_skel = { 0, /* @tp_iternext@ */ 0, /* @tp_methods@ */ 0, /* @tp_members@ */ - pgevent_pygetset, /* @tp_getset@ */ + PYGETSET(pgevent), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -632,7 +631,7 @@ PGMETH(fail, FAIL) static PyObject *pgev_stdev(pgen_proc *proc) { pgev pg; pg.proc = proc; pg.ctx = 0; return (pgev_pywrap(&pg)); } -static PyMethodDef pgev_pymethods[] = { +static const PyMethodDef pgev_pymethods[] = { #define METHNAME(name) pgmeth_##name METH (pg_abort, "E.pg_abort(EV) -> PGST -- prime generation aborted") METH (pg_done, "E.pg_done(EV) -> PGST -- prime generation finished") @@ -669,7 +668,7 @@ static PyTypeObject pgev_pytype_skel = { 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@ */ @@ -677,7 +676,7 @@ static PyTypeObject pgev_pytype_skel = { 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ 0, /* @tp_iternext@ */ - pgev_pymethods, /* @tp_methods@ */ + PYMETHODS(pgev), /* @tp_methods@ */ 0, /* @tp_members@ */ 0, /* @tp_getset@ */ 0, /* @tp_base@ */ @@ -711,7 +710,7 @@ end: static PyObject *psget_step(PyObject *me, void *hunoz) { return (PyInt_FromLong(PGSTEP_STEP(me))); } -static PyGetSetDef pgstep_pygetset[] = { +static const PyGetSetDef pgstep_pygetset[] = { #define GETSETNAME(op, name) ps##op##_##name GET (step, "S.step -> step size for the stepper") #undef GETSETNAME @@ -743,7 +742,7 @@ static PyTypeObject pgstep_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"PrimeGenStepper(STEP): simple stepper with small-factors filter.", + "PrimeGenStepper(STEP): simple stepper with small-factors filter.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -753,7 +752,7 @@ static PyTypeObject pgstep_pytype_skel = { 0, /* @tp_iternext@ */ 0, /* @tp_methods@ */ 0, /* @tp_members@ */ - pgstep_pygetset, /* @tp_getset@ */ + PYGETSET(pgstep), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -793,7 +792,7 @@ static void pgjump_pydealloc(PyObject *me) static PyObject *pjget_jump(PyObject *me, void *hunoz) { RETURN_OBJ(PGJUMP_FOBJ(me)); } -static PyGetSetDef pgjump_pygetset[] = { +static const PyGetSetDef pgjump_pygetset[] = { #define GETSETNAME(op, name) pj##op##_##name GET (jump, "S.jump -> jump size for the stepper") #undef GETSETNAME @@ -825,7 +824,8 @@ static PyTypeObject pgjump_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"PrimeGenJumper(JUMP): stepper for larger steps with small-factors filter.", + "PrimeGenJumper(JUMP): " + "stepper for larger steps with small-factors filter.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -835,7 +835,7 @@ static PyTypeObject pgjump_pytype_skel = { 0, /* @tp_iternext@ */ 0, /* @tp_methods@ */ 0, /* @tp_members@ */ - pgjump_pygetset, /* @tp_getset@ */ + PYGETSET(pgjump), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -886,7 +886,7 @@ static PyTypeObject pgtest_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"PrimeGenTester(): Rabin-Miller tester.", + "PrimeGenTester(): Rabin-Miller tester.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -1049,23 +1049,24 @@ end: /*----- Global stuff ------------------------------------------------------*/ -static PyMethodDef methods[] = { +static const PyMethodDef methods[] = { #define METHNAME(name) meth_##name - METH (_PrimeFilter_smallfactor, "smallfactor(X) -> PGST") - 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 } };