From 91e56f0647ff205643debd5cdb93797ea0e8da24 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 20 Oct 2019 21:00:18 +0100 Subject: [PATCH] *.c: Use Python `METH_NOARGS' methods where applicable. Rather than rolling our own. We need a little extra machinery to insert the table entries, especially for the generic mapping support, but this still saves 95 lines of code. The `CONVERT_CAREFULLY' macro recently added will check that we haven't messed things up too badly. --- algorithms.c | 91 +++++++++++++++++++++------------------------------------- buffer.c | 25 +++++++--------- ec.c | 20 ++++++------- field.c | 19 ++++++------ group.c | 27 +++++++---------- key.c | 27 ++++++----------- mp.c | 49 ++++++++++++------------------- pubkey.c | 18 ++++-------- pyke/mapping.c | 42 +++++++++++---------------- pyke/pyke.h | 39 ++++++++++++++++--------- rand.c | 66 ++++++++++++++---------------------------- share.c | 10 +++---- 12 files changed, 170 insertions(+), 263 deletions(-) diff --git a/algorithms.c b/algorithms.c index ad9fe9c..4d4f5e2 100644 --- a/algorithms.c +++ b/algorithms.c @@ -640,9 +640,8 @@ end: return (0); } -static PyObject *gcmeth_bdry(PyObject *me, PyObject *arg) +static PyObject *gcmeth_bdry(PyObject *me) { - if (!PyArg_ParseTuple(arg, ":bdry")) goto end; if (!GCIPHER_C(me)->ops->bdry) VALERR("`bdry' not supported"); if (!GC_CLASS(GCIPHER_C(me))->blksz) VALERR("not a block cipher mode"); GC_BDRY(GCIPHER_C(me)); @@ -667,7 +666,7 @@ static const PyMethodDef gcipher_pymethods[] = { METH (decrypt, "C.decrypt(CT) -> PT") METH (deczero, "C.deczero(N) -> PT") METH (setiv, "C.setiv(IV)") - METH (bdry, "C.bdry()") + NAMETH(bdry, "C.bdry()") #undef METHNAME { 0 } }; @@ -976,12 +975,11 @@ static const PyGetSetDef gcaead_pygetset[] = { { 0 } }; -static PyObject *gaekmeth_aad(PyObject *me, PyObject *arg) +static PyObject *gaekmeth_aad(PyObject *me) { const gaead_key *k = GAEADKEY_K(me); PyObject *rc = 0; - if (!PyArg_ParseTuple(arg, ":aad")) return (0); if (k->ops->c->f&AEADF_AADNDEP) VALERR("aad must be associated with enc/dec op"); rc = gaeadaad_pywrap((PyObject *)GCAEAD_AAD(me->ob_type), @@ -1068,7 +1066,7 @@ end: static const PyMethodDef gaeadkey_pymethods[] = { #define METHNAME(name) gaekmeth_##name - METH (aad, "KEY.aad() -> AAD") + NAMETH(aad, "KEY.aad() -> AAD") KWMETH(enc, "KEY.enc(NONCE, [hsz], [msz], [tsz]) -> ENC") KWMETH(dec, "KEY.dec(NONCE, [hsz], [csz], [tsz]) -> DEC") #undef METHNAME @@ -1132,11 +1130,10 @@ static const PyGetSetDef gaeadaad_pygetset[] = { { 0 } }; -static PyObject *gaeameth_copy(PyObject *me, PyObject *arg) +static PyObject *gaeameth_copy(PyObject *me) { PyObject *rc = 0; - if (!PyArg_ParseTuple(arg, ":copy")) goto end; if (gaea_check(me)) goto end; if (GAEADAAD_F(me)&AEADF_AADNDEP) VALERR("can't duplicate nonce-dependent aad"); @@ -1207,7 +1204,7 @@ static PyObject *gaeameth_hashstrz(PyObject *me, PyObject *arg) static const PyMethodDef gaeadaad_pymethods[] = { #define METHNAME(name) gaeameth_##name - METH (copy, "AAD.copy() -> AAD'") + NAMETH(copy, "AAD.copy() -> AAD'") METH (hash, "AAD.hash(H)") #define METHU_(n, W, w) METH(hashu##w, "AAD.hashu" #w "(WORD)") DOUINTCONV(METHU_) @@ -1271,12 +1268,11 @@ static const PyGetSetDef gaeadenc_pygetset[] = { { 0 } }; -static PyObject *gaeemeth_aad(PyObject *me, PyObject *arg) +static PyObject *gaeemeth_aad(PyObject *me) { gaeadenc_pyobj *ge = (gaeadenc_pyobj *)me; PyObject *rc = 0; - if (!PyArg_ParseTuple(arg, ":aad")) return (0); if (!(ge->f&AEADF_AADNDEP)) rc = gaeadaad_pywrap((PyObject *)GCAEADENC_KEY(ge->ob_type)->aad, GAEAD_AAD(ge->e), 0, 0); @@ -1388,7 +1384,7 @@ end: static const PyMethodDef gaeadenc_pymethods[] = { #define METHNAME(name) gaeemeth_##name - METH (aad, "ENC.aad() -> AAD") + NAMETH(aad, "ENC.aad() -> AAD") KWMETH(reinit, "ENC.reinit(NONCE, [hsz], [msz], [tsz])") METH (encrypt, "ENC.encrypt(MSG) -> CT") KWMETH(done, "ENC.done([tsz], [aad]) -> CT, TAG") @@ -1446,11 +1442,10 @@ static const PyGetSetDef gaeaddec_pygetset[] = { { 0 } }; -static PyObject *gaedmeth_aad(PyObject *me, PyObject *arg) +static PyObject *gaedmeth_aad(PyObject *me) { gaeaddec_pyobj *gd = (gaeaddec_pyobj *)me; - if (!PyArg_ParseTuple(arg, ":aad")) return (0); if (!(gd->f&AEADF_AADNDEP)) return (gaeadaad_pywrap((PyObject *)GCAEADDEC_KEY(gd->ob_type)->aad, GAEAD_AAD(gd->d), 0, 0)); @@ -1551,7 +1546,7 @@ end: static const PyMethodDef gaeaddec_pymethods[] = { #define METHNAME(name) gaedmeth_##name - METH (aad, "DEC.aad() -> AAD") + NAMETH(aad, "DEC.aad() -> AAD") KWMETH(reinit, "DEC.reinit(NONCE, [hsz], [csz], [tsz])") METH (decrypt, "DEC.decrypt(CT) -> MSG") KWMETH(done, "DEC.done(TAG, [aad]) -> MSG | None") @@ -2013,11 +2008,8 @@ static PyObject *gchget_hashsz(PyObject *me, void *hunoz) static PyObject *gchget_bufsz(PyObject *me, void *hunoz) { return (PyInt_FromLong(GCHASH_CH(me)->bufsz)); } -static PyObject *ghmeth_copy(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":copy")) return (0); - return (ghash_pywrap((PyObject *)me->ob_type, GH_COPY(GHASH_H(me)))); -} +static PyObject *ghmeth_copy(PyObject *me) + { return (ghash_pywrap((PyObject *)me->ob_type, GH_COPY(GHASH_H(me)))); } static PyObject *ghmeth_hash(PyObject *me, PyObject *arg) { @@ -2060,11 +2052,10 @@ static PyObject *ghmeth_hashstrz(PyObject *me, PyObject *arg) RETURN_ME; } -static PyObject *ghmeth_done(PyObject *me, PyObject *arg) +static PyObject *ghmeth_done(PyObject *me) { ghash *g; PyObject *rc; - if (!PyArg_ParseTuple(arg, ":done")) return (0); g = GH_COPY(GHASH_H(me)); rc = bytestring_pywrap(0, g->ops->c->hashsz); GH_DONE(g, PyString_AS_STRING(rc)); @@ -2083,7 +2074,7 @@ static const PyGetSetDef gchash_pygetset[] = { static const PyMethodDef ghash_pymethods[] = { #define METHNAME(name) ghmeth_##name - METH (copy, "H.copy() -> HH") + NAMETH(copy, "H.copy() -> HH") METH (hash, "H.hash(M)") #define METHU_(n, W, w) METH(hashu##w, "H.hashu" #w "(WORD)") DOUINTCONV(METHU_) @@ -2092,7 +2083,7 @@ static const PyMethodDef ghash_pymethods[] = { DOUINTCONV(METHBUF_) #undef METHBUF_ METH (hashstrz, "H.hashstrz(STRING)") - METH (done, "H.done() -> HASH") + NAMETH(done, "H.done() -> HASH") #undef METHNAME { 0 } }; @@ -2542,10 +2533,9 @@ static PyObject *poly1305clsget_masksz(PyObject *me, void *hunoz) static PyObject *poly1305clsget_tagsz(PyObject *me, void *hunoz) { return (PyInt_FromLong(POLY1305_TAGSZ)); } -static PyObject *polymeth_copy(PyObject *me, PyObject *arg) +static PyObject *polymeth_copy(PyObject *me) { poly1305hash_pyobj *ph; - if (!PyArg_ParseTuple(arg, ":copy")) return (0); ph = PyObject_NEW(poly1305hash_pyobj, me->ob_type); poly1305_copy(&ph->ctx, P1305_CTX(me)); Py_INCREF(me->ob_type); @@ -2596,19 +2586,11 @@ static PyObject *polymeth_hashstrz(PyObject *me, PyObject *arg) RETURN_ME; } -static PyObject *polymeth_flush(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":flush")) return (0); - poly1305_flush(P1305_CTX(me)); - RETURN_ME; -} +static PyObject *polymeth_flush(PyObject *me) + { poly1305_flush(P1305_CTX(me)); RETURN_ME; } -static PyObject *polymeth_flushzero(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":flushzero")) return (0); - poly1305_flushzero(P1305_CTX(me)); - RETURN_ME; -} +static PyObject *polymeth_flushzero(PyObject *me) + { poly1305_flushzero(P1305_CTX(me)); RETURN_ME; } static PyObject *polymeth_concat(PyObject *me, PyObject *arg) { @@ -2626,10 +2608,9 @@ end: return (0); } -static PyObject *polymeth_done(PyObject *me, PyObject *arg) +static PyObject *polymeth_done(PyObject *me) { PyObject *rc; - if (!PyArg_ParseTuple(arg, ":done")) return (0); if (!(P1305_F(me) & f_mask)) VALERR("no mask"); rc = bytestring_pywrap(0, POLY1305_TAGSZ); poly1305_done(P1305_CTX(me), PyString_AS_STRING(rc)); @@ -2650,7 +2631,7 @@ static const PyGetSetDef poly1305cls_pygetset[] = { static const PyMethodDef poly1305hash_pymethods[] = { #define METHNAME(name) polymeth_##name - METH (copy, "P.copy() -> PP") + NAMETH(copy, "P.copy() -> PP") METH (hash, "P.hash(M)") #define METHU_(n, W, w) METH(hashu##w, "P.hashu" #w "(WORD)") DOUINTCONV(METHU_) @@ -2659,10 +2640,10 @@ static const PyMethodDef poly1305hash_pymethods[] = { DOUINTCONV(METHBUF_) #undef METHBUF_ METH (hashstrz, "P.hashstrz(STRING)") - METH (flush, "P.flush()") - METH (flushzero, "P.flushzero()") + NAMETH(flush, "P.flush()") + NAMETH(flushzero, "P.flushzero()") METH (concat, "P.concat(PREFIX, SUFFIX)") - METH (done, "P.done() -> TAG") + NAMETH(done, "P.done() -> TAG") #undef METHNAME { 0 } }; @@ -2866,13 +2847,11 @@ end: return ((PyObject *)rc); } -static PyObject *kxvikmeth_copy(PyObject *me, PyObject *arg) +static PyObject *kxvikmeth_copy(PyObject *me) { kxvik_pyobj *k = (kxvik_pyobj *)me, *rc = 0; - if (!PyArg_ParseTuple(arg, ":copy")) goto end; rc = (kxvik_pyobj *)k->ob_type->tp_alloc(k->ob_type, 0); rc->s = k->s; rc->n = k->n; -end: return ((PyObject *)rc); } @@ -2921,10 +2900,9 @@ end: return (rc); } -static PyObject *kxvikmeth_step(PyObject *me, PyObject *arg) +static PyObject *kxvikmeth_step(PyObject *me) { kxvik_pyobj *k = (kxvik_pyobj *)me; - if (!PyArg_ParseTuple(arg, ":step")) return (0); keccak1600_p(&k->s, &k->s, k->n); RETURN_ME; } @@ -2958,10 +2936,10 @@ static const PyGetSetDef kxvik_pygetset[] = { static const PyMethodDef kxvik_pymethods[] = { #define METHNAME(func) kxvikmeth_##func - METH (copy, "KECCAK.copy() -> KECCAK'") + NAMETH(copy, "KECCAK.copy() -> KECCAK'") METH (mix, "KECCAK.mix(DATA)") METH (extract, "KECCAK.extract(NOCTETS)") - METH (step, "KECCAK.step()") + NAMETH(step, "KECCAK.step()") #undef METHNAME { 0 } }; @@ -3110,9 +3088,8 @@ static PyObject *shakemeth_hashstrz(PyObject *me, PyObject *arg) RETURN_ME; } -static PyObject *shakemeth_xof(PyObject *me, PyObject *arg) +static PyObject *shakemeth_xof(PyObject *me) { - if (!PyArg_ParseTuple(arg, ":xof")) goto end; if (shake_check(me, 0)) goto end; shake_xof(SHAKE_H(me)); SHAKE_ST(me) = 1; @@ -3134,15 +3111,13 @@ end: return (rc); } -static PyObject *shakemeth_copy(PyObject *me, PyObject *arg) +static PyObject *shakemeth_copy(PyObject *me) { shake_pyobj *rc = 0; - if (!PyArg_ParseTuple(arg, ":copy")) goto end; rc = PyObject_NEW(shake_pyobj, me->ob_type); rc->h = *SHAKE_H(me); rc->st = SHAKE_ST(me); -end: return ((PyObject *)rc); } @@ -3196,7 +3171,7 @@ static const PyGetSetDef shake_pygetset[] = { static const PyMethodDef shake_pymethods[] = { #define METHNAME(func) shakemeth_##func - METH (copy, "S.copy() -> SS") + NAMETH(copy, "S.copy() -> SS") METH (hash, "S.hash(M)") #define METHU_(n, W, w) METH(hashu##w, "S.hashu" #w "(WORD)") DOUINTCONV(METHU_) @@ -3205,7 +3180,7 @@ static const PyMethodDef shake_pymethods[] = { DOUINTCONV(METHBUF_) #undef METHBUF_ METH (hashstrz, "S.hashstrz(STRING)") - METH (xof, "S.xof()") + NAMETH(xof, "S.xof()") METH (done, "S.done(LEN) -> H") METH (get, "S.get(LEN) -> H") METH (mask, "S.mask(M) -> C") diff --git a/buffer.c b/buffer.c index 49ed9d2..690c7cd 100644 --- a/buffer.c +++ b/buffer.c @@ -107,10 +107,9 @@ end: } #define RBMETH_GETU_(n, W, w) \ - static PyObject *rbmeth_getu##w(PyObject *me, PyObject *arg) \ + static PyObject *rbmeth_getu##w(PyObject *me) \ { \ uint##n x; \ - if (!PyArg_ParseTuple(arg, ":getu" #w)) goto end; \ if (buf_getu##w(BUF_B(me), &x)) BUFERR("buffer exhausted"); \ if (MASK##W <= ULONG_MAX) return (getulong(x)); \ else { kludge64 y; ASSIGN64(y, x); return (getk64(y)); } \ @@ -120,11 +119,10 @@ end: DOUINTCONV(RBMETH_GETU_) #define RBMETH_GETBLK_(n, W, w) \ - static PyObject *rbmeth_getblk##w(PyObject *me, PyObject *arg) \ + static PyObject *rbmeth_getblk##w(PyObject *me) \ { \ size_t sz; \ char *q; \ - if (!PyArg_ParseTuple(arg, ":getblk" #w)) goto end; \ if ((q = buf_getmem##w(BUF_B(me), &sz)) == 0) \ BUFERR("buffer exhausted"); \ return (bytestring_pywrap(q, sz)); \ @@ -134,11 +132,10 @@ DOUINTCONV(RBMETH_GETU_) BUF_DOSUFFIXES(RBMETH_GETBLK_) #define RBMETH_GETBUF_(n, W, w) \ - static PyObject *rbmeth_getbuf##w(PyObject *me, PyObject *arg) \ + static PyObject *rbmeth_getbuf##w(PyObject *me) \ { \ buf_pyobj *b; \ buf bb; \ - if (!PyArg_ParseTuple(arg, ":getbuf" #w)) goto end; \ if (buf_getbuf##w(BUF_B(me), &bb)) BUFERR("buffer exhausted"); \ b = PyObject_NEW(buf_pyobj, rbuf_pytype); \ b->b = bb; \ @@ -150,20 +147,18 @@ BUF_DOSUFFIXES(RBMETH_GETBLK_) } BUF_DOSUFFIXES(RBMETH_GETBUF_) -static PyObject *rbmeth_getmp(PyObject *me, PyObject *arg) +static PyObject *rbmeth_getmp(PyObject *me) { mp *x; - if (!PyArg_ParseTuple(arg, ":getmp")) goto end; if ((x = buf_getmp(BUF_B(me))) == 0) BUFERR("buffer exhausted"); return (mp_pywrap(x)); end: return (0); } -static PyObject *rbmeth_getgf(PyObject *me, PyObject *arg) +static PyObject *rbmeth_getgf(PyObject *me) { mp *x; - if (!PyArg_ParseTuple(arg, ":getgf")) goto end; if ((x = buf_getmp(BUF_B(me))) == 0) BUFERR("buffer exhausted"); return (gf_pywrap(x)); end: @@ -260,16 +255,16 @@ static const PyMethodDef rbuf_pymethods[] = { METH (skip, "RBUF.skip(N)") METH (get, "RBUF.get(N) -> BYTES") #define RBMETH_DECL_GETU_(n, W, w) \ - METH(getu##w, "RBUF.getu" #w "() -> INT") + NAMETH(getu##w, "RBUF.getu" #w "() -> INT") DOUINTCONV(RBMETH_DECL_GETU_) #define RBMETH_DECL_GETBLK_(n, W, w) \ - METH(getblk##w, "RBUF.getblk" #w "() -> BYTES") + NAMETH(getblk##w, "RBUF.getblk" #w "() -> BYTES") BUF_DOSUFFIXES(RBMETH_DECL_GETBLK_) #define RBMETH_DECL_GETBUF_(n, W, w) \ - METH(getbuf##w, "RBUF.getbuf" #w "() -> RBUF'") + NAMETH(getbuf##w, "RBUF.getbuf" #w "() -> RBUF'") BUF_DOSUFFIXES(RBMETH_DECL_GETBUF_) - METH (getmp, "RBUF.getmp() -> X") - METH (getgf, "RBUF.getgf() -> X") + NAMETH(getmp, "RBUF.getmp() -> X") + NAMETH(getgf, "RBUF.getgf() -> X") KWMETH(getecpt, "RBUF.getecpt([curve = None]) -> P") METH (getecptraw, "RBUF.getecptraw(CURVE) -> P") METH (getge, "RBUF.getge(GROUP) -> X") diff --git a/ec.c b/ec.c index bcf5531..b69dbf3 100644 --- a/ec.c +++ b/ec.c @@ -225,29 +225,26 @@ end: return (rc); } -static PyObject *epmeth_oncurvep(PyObject *me, PyObject *arg) +static PyObject *epmeth_oncurvep(PyObject *me) { - if (!PyArg_ParseTuple(arg, ":oncurvep")) return (0); return (getbool(EC_ATINF(ECPT_P(me)) || !EC_CHECK(ECPT_C(me), ECPT_P(me)))); } -static PyObject *epmeth_dbl(PyObject *me, PyObject *arg) +static PyObject *epmeth_dbl(PyObject *me) { ec p = EC_INIT; - if (!PyArg_ParseTuple(arg, ":dbl")) return (0); EC_DBL(ECPT_C(me), &p, ECPT_P(me)); return (ecpt_pywrap(ECPT_COBJ(me), &p)); } -static PyObject *epmeth_tobuf(PyObject *me, PyObject *arg) +static PyObject *epmeth_tobuf(PyObject *me) { buf b; ec p = EC_INIT; PyObject *rc; size_t n; - if (!PyArg_ParseTuple(arg, ":tobuf")) return (0); getecptout(&p, me); if (EC_ATINF(&p)) n = 2; @@ -262,7 +259,7 @@ static PyObject *epmeth_tobuf(PyObject *me, PyObject *arg) return (rc); } -static PyObject *epmeth_toraw(PyObject *me, PyObject *arg) +static PyObject *epmeth_toraw(PyObject *me) { buf b; PyObject *rc; @@ -271,7 +268,6 @@ static PyObject *epmeth_toraw(PyObject *me, PyObject *arg) ec pp = EC_INIT; int len; - if (!PyArg_ParseTuple(arg, ":toraw")) return (0); len = c->f->noctets * 2 + 1; rc = bytestring_pywrap(0, len); p = PyString_AS_STRING(rc); @@ -641,7 +637,7 @@ static const PyGetSetDef ecptnc_pygetset[] = { static const PyMethodDef ecptnc_pymethods[] = { #define METHNAME(func) epmeth_##func - METH (tobuf, "X.tobuf() -> BIN") + NAMETH(tobuf, "X.tobuf() -> BIN") CMTH (frombuf, "frombuf(STR) -> (P, REST)") CMTH (parse, "parse(STR) -> (P, REST)") #undef METHNAME @@ -757,10 +753,10 @@ static const PyGetSetDef ecpt_pygetset[] = { static const PyMethodDef ecpt_pymethods[] = { #define METHNAME(func) epmeth_##func - METH (toraw, "X.toraw() -> BIN") + NAMETH(toraw, "X.toraw() -> BIN") KWMETH(ec2osp, "X.ec2osp([flags = EC_EXPLY]) -> BIN") - METH (dbl, "X.dbl() -> X + X") - METH (oncurvep, "X.oncurvep() -> BOOL") + NAMETH(dbl, "X.dbl() -> X + X") + NAMETH(oncurvep, "X.oncurvep() -> BOOL") CMTH (fromraw, "fromraw(STR) -> (P, REST)") KWCMTH(os2ecp, "os2ecp(STR, [flags = ...]) -> (P, REST)") #undef METHNAME diff --git a/field.c b/field.c index 51864d0..987b47d 100644 --- a/field.c +++ b/field.c @@ -280,10 +280,9 @@ static void fe_pydealloc(PyObject *me) } #define UNOP(name, check) \ - static PyObject *femeth_##name(PyObject *me, PyObject *arg) { \ + static PyObject *femeth_##name(PyObject *me) { \ field *f = FE_F(me); \ mp *x = FE_X(me); \ - if (!PyArg_ParseTuple(arg, ":" #name)) return (0); \ if (!f->ops->name) TYERR(#name " not supported for this field"); \ check \ x = f->ops->name(f, MP_NEW, x); \ @@ -335,14 +334,14 @@ static const PyGetSetDef fe_pygetset[] = { static const PyMethodDef fe_pymethods[] = { #define METHNAME(func) femeth_##func - METH (inv, "X.inv() -> X^{-1}") - METH (sqr, "X.sqr() -> X^2") - METH (sqrt, "X.sqrt() -> sqrt(X)") - METH (quadsolve, "X.quadsolve() -> Y where Y^2 + Y = X (binary only)") - METH (dbl, "X.dbl() -> 2 * X (prime only)") - METH (tpl, "X.tpl() -> 3 * X (prime only)") - METH (qdl, "X.qdl() -> 4 * X (prime only)") - METH (hlv, "X.hlv() -> X/2 (prime only)") + NAMETH(inv, "X.inv() -> X^{-1}") + NAMETH(sqr, "X.sqr() -> X^2") + NAMETH(sqrt, "X.sqrt() -> sqrt(X)") + NAMETH(quadsolve, "X.quadsolve() -> Y where Y^2 + Y = X (binary only)") + NAMETH(dbl, "X.dbl() -> 2 * X (prime only)") + NAMETH(tpl, "X.tpl() -> 3 * X (prime only)") + NAMETH(qdl, "X.qdl() -> 4 * X (prime only)") + NAMETH(hlv, "X.hlv() -> X/2 (prime only)") #undef METHNAME { 0 } }; diff --git a/group.c b/group.c index 254f8ce..62e67b3 100644 --- a/group.c +++ b/group.c @@ -622,11 +622,10 @@ BINOP(div) #undef BINOP #define UNOP(name) \ - static PyObject *gemeth_##name(PyObject *me, PyObject *arg) \ + static PyObject *gemeth_##name(PyObject *me) \ { \ group *g; \ ge *z; \ - if (!PyArg_ParseTuple(arg, ":" #name)) return (0); \ g = GE_G(me); \ z = G_CREATE(g); \ g->ops->name(g, z, GE_X(me)); \ @@ -696,9 +695,8 @@ end: return (rc); } -static PyObject *gemeth_check(PyObject *me, PyObject *arg) +static PyObject *gemeth_check(PyObject *me) { - if (!PyArg_ParseTuple(arg, ":check")) goto end; if (group_check(GE_G(me), GE_X(me))) VALERR("bad group element"); RETURN_OBJ(me); end: @@ -747,11 +745,10 @@ end: return (rc); } -static PyObject *gemeth_toint(PyObject *me, PyObject *arg) +static PyObject *gemeth_toint(PyObject *me) { mp *x; - if (!PyArg_ParseTuple(arg, ":toint")) goto end; if ((x = G_TOINT(GE_G(me), MP_NEW, GE_X(me))) == 0) TYERR("can't convert to integer"); return (mp_pywrap(x)); @@ -792,13 +789,12 @@ end: return (rc); } -static PyObject *gemeth_tobuf(PyObject *me, PyObject *arg) +static PyObject *gemeth_tobuf(PyObject *me) { buf b; PyObject *rc; size_t n; - if (!PyArg_ParseTuple(arg, ":tobuf")) return (0); n = GE_G(me)->noctets + 4; rc = bytestring_pywrap(0, n); buf_init(&b, PyString_AS_STRING(rc), n); @@ -808,13 +804,12 @@ static PyObject *gemeth_tobuf(PyObject *me, PyObject *arg) return (rc); } -static PyObject *gemeth_toraw(PyObject *me, PyObject *arg) +static PyObject *gemeth_toraw(PyObject *me) { buf b; PyObject *rc; size_t n; - if (!PyArg_ParseTuple(arg, ":toraw")) return (0); n = GE_G(me)->noctets; rc = bytestring_pywrap(0, n); buf_init(&b, PyString_AS_STRING(rc), n); @@ -996,14 +991,14 @@ static const PyGetSetDef ge_pygetset[] = { static const PyMethodDef ge_pymethods[] = { #define METHNAME(name) gemeth_##name - METH (inv, "X.inv() -> inverse element of X") - METH (sqr, "X.sqr() -> X^2 = X * X") - METH (check, "X.check() -> check X really belongs to its group") - METH (toint, "X.toint() -> X converted to an integer") + NAMETH(inv, "X.inv() -> inverse element of X") + NAMETH(sqr, "X.sqr() -> X^2 = X * X") + NAMETH(check, "X.check() -> check X really belongs to its group") + NAMETH(toint, "X.toint() -> X converted to an integer") KWMETH(toec, "X.toec([curve = ECPt]) -> " "X converted to elliptic curve point") - METH (tobuf, "X.tobuf() -> X in buffer representation") - METH (toraw, "X.toraw() -> X in raw representation") + NAMETH(tobuf, "X.tobuf() -> X in buffer representation") + NAMETH(toraw, "X.toraw() -> X in raw representation") CMTH (frombuf, "frombuf(BUF) -> X, REST") CMTH (fromraw, "fromraw(BUF) -> X, REST") CMTH (fromstring, "fromstring(STR) -> X, REST") diff --git a/key.c b/key.c index 5f097f0..a4caa50 100644 --- a/key.c +++ b/key.c @@ -339,13 +339,8 @@ static PyObject *kdmeth_matchp(PyObject *me, PyObject *arg) return (getbool(KEY_MATCH(KEYDATA_KD(me), &f))); } -static PyObject *kdmeth_split(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":split")) - return (0); - key_split(&KEYDATA_KD(me)); - RETURN_ME; -} +static PyObject *kdmeth_split(PyObject *me) + { key_split(&KEYDATA_KD(me)); RETURN_ME; } static PyObject *kdmeth_copy(PyObject *me, PyObject *arg, PyObject *kw) { @@ -459,7 +454,7 @@ static PyObject *kdget_flags(PyObject *me, void *hunoz) static const PyMethodDef keydata_pymethods[] = { #define METHNAME(func) kdmeth_##func METH (matchp, "KD.matchp(FILTER) -> BOOL") - METH (split, "KD.split()") + NAMETH(split, "KD.split()") KWMETH(write, "KD.write([filter = ]) -> STRING") KWMETH(encode, "KD.encode([filter = ]) -> BYTES") KWMETH(copy, "KD.copy([filter = ]) -> KD") @@ -1407,22 +1402,20 @@ static void key_pydealloc(PyObject *me) FREEOBJ(me); } -static PyObject *kmeth_delete(PyObject *me, PyObject *arg) +static PyObject *kmeth_delete(PyObject *me) { int err; - if (!PyArg_ParseTuple(arg, ":delete")) goto end; if ((err = key_delete(KEY_KF(me), KEY_K(me))) != 0) KEYERR(err); RETURN_ME; end: return (0); } -static PyObject *kmeth_expire(PyObject *me, PyObject *arg) +static PyObject *kmeth_expire(PyObject *me) { int err; - if (!PyArg_ParseTuple(arg, ":expire")) goto end; if ((err = key_expire(KEY_KF(me), KEY_K(me))) != 0) KEYERR(err); RETURN_ME; end: @@ -1596,8 +1589,8 @@ end: static const PyMethodDef key_pymethods[] = { #define METHNAME(func) kmeth_##func - METH (delete, "KEY.delete()") - METH (expire, "KEY.expire()") + NAMETH(delete, "KEY.delete()") + NAMETH(expire, "KEY.expire()") METH (used, "KEY.used(TIME)") KWMETH(extract, "KEY.extract(FILE, [filter = ])") KWMETH(fingerprint, "KEY.fingerprint(HASH, [filter = '-secret'])") @@ -1809,10 +1802,8 @@ static void keyfile_pydealloc(PyObject *me) FREEOBJ(me); } -static PyObject *kfmeth_save(PyObject *me, PyObject *arg) +static PyObject *kfmeth_save(PyObject *me) { - if (!PyArg_ParseTuple(arg, ":save")) - goto end; switch (key_save(KEYFILE_KF(me))) { case KWRITE_OK: RETURN_ME; @@ -1989,7 +1980,7 @@ static PyObject *kfget_filep(PyObject *me, void *hunoz) static const PyMethodDef keyfile_pymethods[] = { #define METHNAME(func) kfmeth_##func - METH (save, "KF.save()") + NAMETH(save, "KF.save()") KWMETH(merge, "KF.merge(FILE, [report = ])") KWMETH(newkey, "KF.newkey(ID, TYPE, [exptime = KEXP_FOREVER]) " "-> KEY") diff --git a/mp.c b/mp.c index 29e8881..2fc82b2 100644 --- a/mp.c +++ b/mp.c @@ -593,25 +593,20 @@ static PyObject *gfmeth_testbit(PyObject *me, PyObject *arg) return (getbool(mp_testbit(MP_X(me), i))); } -static PyObject *mpmeth_odd(PyObject *me, PyObject *arg) +static PyObject *mpmeth_odd(PyObject *me) { mp *t; size_t s; - if (!PyArg_ParseTuple(arg, ":odd")) return (0); t = mp_odd(MP_NEW, MP_X(me), &s); return (Py_BuildValue("(lN)", (long)s, mp_pywrap(t))); } -static PyObject *mpmeth_sqr(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":sqr")) return (0); - return (mp_pywrap(mp_sqr(MP_NEW, MP_X(me)))); -} +static PyObject *mpmeth_sqr(PyObject *me) + { return (mp_pywrap(mp_sqr(MP_NEW, MP_X(me)))); } -static PyObject *mpmeth_sqrt(PyObject *me, PyObject *arg) +static PyObject *mpmeth_sqrt(PyObject *me) { - if (!PyArg_ParseTuple(arg, ":sqrt")) return (0); if (MP_NEGP(MP_X(me))) VALERR("negative root"); return (mp_pywrap(mp_sqrt(MP_NEW, MP_X(me)))); end: @@ -745,14 +740,13 @@ BUFOP(mp) BUFOP(gf) #undef BUFOP -static PyObject *mpmeth_tobuf(PyObject *me, PyObject *arg) +static PyObject *mpmeth_tobuf(PyObject *me) { buf b; PyObject *rc; mp *x; size_t n; - if (!PyArg_ParseTuple(arg, ":tobuf")) return (0); x = MP_X(me); n = mp_octets(x) + 3; rc = bytestring_pywrap(0, n); @@ -858,9 +852,9 @@ static const PyMethodDef mp_pymethods[] = { METH (setbit, "X.setbit(N) -> X with bit N set") METH (clearbit, "X.clearbit(N) -> X with bit N clear") METH (testbit, "X.testbit(N) -> true/false if bit N set/clear in X") - METH (odd, "X.odd() -> S, T where X = 2^S T with T odd") - METH (sqr, "X.sqr() -> X^2") - METH (sqrt, "X.sqrt() -> largest integer <= sqrt(X)") + NAMETH(odd, "X.odd() -> S, T where X = 2^S T with T odd") + NAMETH(sqr, "X.sqr() -> X^2") + NAMETH(sqrt, "X.sqrt() -> largest integer <= sqrt(X)") METH (gcd, "X.gcd(Y) -> gcd(X, Y)") METH (gcdx, "X.gcdx(Y) -> (gcd(X, Y), U, V) " "with X U + Y V = gcd(X, Y)") @@ -876,7 +870,7 @@ static const PyMethodDef mp_pymethods[] = { "little-endian bytes, two's complement") KWMETH(storeb2c, "X.storeb2c([len = -1]) -> " "big-endian bytes, two's complement") - METH (tobuf, "X.tobuf() -> buffer format") + NAMETH(tobuf, "X.tobuf() -> buffer format") KWSMTH(fromstring, "fromstring(STR, [radix = 0]) -> (X, REST)\n" " Parse STR as a large integer, according to RADIX. If RADIX is\n" " zero, read a prefix from STR to decide radix: allow `0b' for binary,\n" @@ -1047,11 +1041,10 @@ end: return (0); } -static PyObject *mmmeth_done(PyObject *me, PyObject *arg) +static PyObject *mmmeth_done(PyObject *me) { mp *x; - if (!PyArg_ParseTuple(arg, ":done")) goto end; if (!MPMUL_LIVEP(me)) VALERR("MPMul object invalid"); x = mpmul_done(MPMUL_PY(me)); MPMUL_LIVEP(me) = 0; @@ -1090,7 +1083,7 @@ static const PyGetSetDef mpmul_pygetset[] = { static const PyMethodDef mpmul_pymethods[] = { #define METHNAME(name) mmmeth_##name METH (factor, "MM.factor(ITERABLE) or MM.factor(I, ...)") - METH (done, "MM.done() -> PRODUCT") + NAMETH(done, "MM.done() -> PRODUCT") #undef METHNAME { 0 } }; @@ -1948,11 +1941,8 @@ end: return (rc); } -static PyObject *gfmeth_sqr(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":sqr")) return (0); - return (gf_pywrap(gf_sqr(MP_NEW, MP_X(me)))); -} +static PyObject *gfmeth_sqr(PyObject *me) + { return (gf_pywrap(gf_sqr(MP_NEW, MP_X(me)))); } static PyObject *gfmeth_gcd(PyObject *me, PyObject *arg) { @@ -2023,11 +2013,8 @@ end: return (z); } -static PyObject *gfmeth_irreduciblep(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":irreduciblep")) return (0); - return getbool(gf_irreduciblep(MP_X(me))); -} +static PyObject *gfmeth_irreduciblep(PyObject *me) + { return getbool(gf_irreduciblep(MP_X(me))); } static PyObject *gfget_degree(PyObject *me, void *hunoz) { return (PyInt_FromLong(mp_bits(MP_X(me)) - 1)); } @@ -2048,11 +2035,11 @@ static const PyMethodDef gf_pymethods[] = { METH (setbit, "X.setbit(N) -> X with bit N set") METH (clearbit, "X.clearbit(N) -> X with bit N clear") METH (testbit, "X.testbit(N) -> true/false if bit N set/clear in X") - METH (sqr, "X.sqr() -> X^2") + NAMETH(sqr, "X.sqr() -> X^2") METH (gcd, "X.gcd(Y) -> gcd(X, Y)") METH (gcdx, "X.gcdx(Y) -> (gcd(X, Y), U, V) with X U + Y V = gcd(X, Y)") METH (modinv, "X.modinv(Y) -> multiplicative inverse of Y mod X") - METH (irreduciblep, "X.irreduciblep() -> true/false") + NAMETH(irreduciblep, "X.irreduciblep() -> true/false") KWSMTH(fromstring, "fromstring(STR, [radix = 0]) -> (X, REST)\n" " Parse STR as a binary polynomial, according to RADIX. If RADIX is\n" " zero, read a prefix from STR to decide radix: allow `0b' for binary,\n" @@ -2069,7 +2056,7 @@ static const PyMethodDef gf_pymethods[] = { "little-endian bytes, two's complement") KWMETH(storeb2c, "X.storeb2c([len = -1]) -> " "big-endian bytes, two's complement") - METH (tobuf, "X.tobuf() -> buffer format") + NAMETH(tobuf, "X.tobuf() -> buffer format") #undef METHNAME { 0 } }; diff --git a/pubkey.c b/pubkey.c index 6084c3d..2c906cd 100644 --- a/pubkey.c +++ b/pubkey.c @@ -108,11 +108,8 @@ end: return (rc); } -static PyObject *dsameth_beginhash(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":beginhash")) return (0); - return (ghash_pywrap(DSA_HASH(me), gdsa_beginhash(DSA_D(me)))); -} +static PyObject *dsameth_beginhash(PyObject *me) + { return (ghash_pywrap(DSA_HASH(me), gdsa_beginhash(DSA_D(me)))); } static PyObject *dsameth_endhash(PyObject *me, PyObject *arg) { @@ -190,7 +187,7 @@ end: static const PyMethodDef dsapub_pymethods[] = { #define METHNAME(name) dsameth_##name - METH (beginhash, "D.beginhash() -> hash object") + NAMETH(beginhash, "D.beginhash() -> hash object") METH (endhash, "D.endhash(H) -> BYTES") METH (verify, "D.verify(MSG, (R, S)) -> true/false") #undef METHNAME @@ -363,11 +360,8 @@ end: return (rc); } -static PyObject *kcdsameth_beginhash(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":beginhash")) return (0); - return (ghash_pywrap(DSA_HASH(me), gkcdsa_beginhash(DSA_D(me)))); -} +static PyObject *kcdsameth_beginhash(PyObject *me) + { return (ghash_pywrap(DSA_HASH(me), gkcdsa_beginhash(DSA_D(me)))); } static PyObject *kcdsameth_endhash(PyObject *me, PyObject *arg) { @@ -428,7 +422,7 @@ end: static const PyMethodDef kcdsapub_pymethods[] = { #define METHNAME(name) kcdsameth_##name - METH (beginhash, "D.beginhash() -> hash object") + NAMETH(beginhash, "D.beginhash() -> hash object") METH (endhash, "D.endhash(H) -> BYTES") METH (verify, "D.verify(MSG, (R, S)) -> true/false") #undef METHNAME diff --git a/pyke/mapping.c b/pyke/mapping.c index 615c5ed..7080ca5 100644 --- a/pyke/mapping.c +++ b/pyke/mapping.c @@ -196,13 +196,12 @@ PyObject *gmapmeth_has_key(PyObject *me, PyObject *arg) return (getbool(PyMapping_HasKey(me, k))); } -PyObject *gmapmeth_keys(PyObject *me, PyObject *arg) +PyObject *gmapmeth_keys(PyObject *me) { PyObject *l = 0, *i = 0, *k, *rc = 0; int err; - if (!PyArg_ParseTuple(arg, ":keys") || - (l = PyList_New(0)) == 0 || + if ((l = PyList_New(0)) == 0 || (i = PyObject_GetIter(me)) == 0) goto done; while ((k = PyIter_Next(i)) != 0) @@ -214,13 +213,12 @@ done: return (rc); } -PyObject *gmapmeth_values(PyObject *me, PyObject *arg) +PyObject *gmapmeth_values(PyObject *me) { PyObject *l = 0, *i = 0, *k, *v, *rc = 0; int err = 0; - if (!PyArg_ParseTuple(arg, ":values") || - (l = PyList_New(0)) == 0 || + if ((l = PyList_New(0)) == 0 || (i = PyObject_GetIter(me)) == 0) goto done; while ((k = PyIter_Next(i)) != 0) { @@ -237,13 +235,12 @@ done: return (rc); } -PyObject *gmapmeth_items(PyObject *me, PyObject *arg) +PyObject *gmapmeth_items(PyObject *me) { PyObject *l = 0, *i = 0, *k, *v, *z, *rc = 0; int err = 0; - if (!PyArg_ParseTuple(arg, ":items") || - (l = PyList_New(0)) == 0 || + if ((l = PyList_New(0)) == 0 || (i = PyObject_GetIter(me)) == 0) goto done; while ((k = PyIter_Next(i)) != 0) { @@ -262,19 +259,15 @@ done: return (rc); } -PyObject *gmapmeth_iterkeys(PyObject *me, PyObject *arg) -{ - if (!PyArg_ParseTuple(arg, ":iterkeys")) return (0); - return (PyObject_GetIter(me)); -} +PyObject *gmapmeth_iterkeys(PyObject *me) + { return (PyObject_GetIter(me)); } -PyObject *gmapmeth_itervalues(PyObject *me, PyObject *arg) +PyObject *gmapmeth_itervalues(PyObject *me) { PyObject *i; iter_pyobj *ii; - if (!PyArg_ParseTuple(arg, ":itervalues") || - (i = PyObject_GetIter(me)) == 0) + if ((i = PyObject_GetIter(me)) == 0) return (0); ii = PyObject_NEW(iter_pyobj, valiter_pytype); ii->map = me; Py_INCREF(me); @@ -282,13 +275,12 @@ PyObject *gmapmeth_itervalues(PyObject *me, PyObject *arg) return ((PyObject *)ii); } -PyObject *gmapmeth_iteritems(PyObject *me, PyObject *arg) +PyObject *gmapmeth_iteritems(PyObject *me) { PyObject *i; iter_pyobj *ii; - if (!PyArg_ParseTuple(arg, ":iteritems") || - (i = PyObject_GetIter(me)) == 0) + if ((i = PyObject_GetIter(me)) == 0) return (0); ii = PyObject_NEW(iter_pyobj, itemiter_pytype); ii->map = me; Py_INCREF(me); @@ -296,12 +288,11 @@ PyObject *gmapmeth_iteritems(PyObject *me, PyObject *arg) return ((PyObject *)ii); } -PyObject *gmapmeth_clear(PyObject *me, PyObject *arg) +PyObject *gmapmeth_clear(PyObject *me) { PyObject *i = 0, *k = 0, *rc = 0; - if (!PyArg_ParseTuple(arg, ":clear") || - (i = PyObject_GetIter(me)) == 0) + if ((i = PyObject_GetIter(me)) == 0) goto end; while ((k = PyIter_Next(i)) != 0) { PyObject_DelItem(me, k); @@ -383,12 +374,11 @@ end: return (rc); } -PyObject *gmapmeth_popitem(PyObject *me, PyObject *arg) +PyObject *gmapmeth_popitem(PyObject *me) { PyObject *i = 0, *k = 0, *v = 0, *rc = 0; - if (!PyArg_ParseTuple(arg, ":popitem") || - (i = PyObject_GetIter(me)) == 0) + if ((i = PyObject_GetIter(me)) == 0) goto end; if ((k = PyIter_Next(i)) == 0) { if (!PyErr_Occurred()) VALERR("popitem(): mapping is empty"); diff --git a/pyke/pyke.h b/pyke/pyke.h index 66438a4..e7a1ece 100644 --- a/pyke/pyke.h +++ b/pyke/pyke.h @@ -236,6 +236,11 @@ extern PyTypeObject *inittype(PyTypeObject */*skel*/, CONVERT_CAREFULLY(PyCFunction, PyCFunctionWithKeywords, decor(func)), \ METH_VARARGS | METH_KEYWORDS | flags, \ doc }, +#define NOARG_METHOD(decor, func, flags, doc) \ + { #func, \ + CONVERT_CAREFULLY(PyCFunction, PyNoArgsFunction, decor(func)), \ + METH_NOARGS | flags, \ + doc }, /* Convenience wrappers for filling in `PyMethodDef' tables, following * Pyke naming convention. Define `METHNAME' locally as @@ -246,10 +251,13 @@ extern PyTypeObject *inittype(PyTypeObject */*skel*/, */ #define METH(func, doc) STD_METHOD(METHNAME, func, 0, doc) #define KWMETH(func, doc) KEYWORD_METHOD(METHNAME, func, 0, doc) +#define NAMETH(func, doc) NOARG_METHOD(METHNAME, func, 0, doc) #define CMTH(func, doc) STD_METHOD(METHNAME, func, METH_CLASS, doc) #define KWCMTH(func, doc) KEYWORD_METHOD(METHNAME, func, METH_CLASS, doc) +#define NACMTH(func, doc) NOARG_METHOD(METHNAME, func, METH_CLASS, doc) #define SMTH(func, doc) STD_METHOD(METHNAME, func, METH_STATIC, doc) #define KWSMTH(func, doc) KEYWORD_METHOD(METHNAME, func, METH_STATIC, doc) +#define NASMTH(func, doc) NOARG_METHOD(METHNAME, func, METH_STATIC, doc) /* Convenience wrappers for filling in `PyGetSetDef' tables, following Pyke * naming convention. Define `GETSETNAME' locally as @@ -365,32 +373,35 @@ extern PyMethodDef *donemethods(void); #define GMAP_METMNAME(func) gmapmeth_##func #define GMAP_METH(func, doc) STD_METHOD(GMAP_METMNAME, func, 0, doc) #define GMAP_KWMETH(func, doc) KEYWORD_METHOD(GMAP_METMNAME, func, 0, doc) +#define GMAP_NAMETH(func, doc) NOARG_METHOD(GMAP_METMNAME, func, 0, doc) #define GMAP_METHDECL(func, doc) \ extern PyObject *gmapmeth_##func(PyObject *, PyObject *); #define GMAP_KWMETHDECL(func, doc) \ extern PyObject *gmapmeth_##func(PyObject *, PyObject *, PyObject *); +#define GMAP_NAMETHDECL(func, doc) \ + extern PyObject *gmapmeth_##func(PyObject *); -#define GMAP_DOROMETHODS(METH, KWMETH) \ +#define GMAP_DOROMETHODS(METH, KWMETH, NAMETH) \ METH (has_key, "D.has_key(KEY) -> BOOL") \ - METH (keys, "D.keys() -> LIST") \ - METH (values, "D.values() -> LIST") \ - METH (items, "D.items() -> LIST") \ - METH (iterkeys, "D.iterkeys() -> ITER") \ - METH (itervalues, "D.itervalues() -> ITER") \ - METH (iteritems, "D.iteritems() -> ITER") \ + NAMETH(keys, "D.keys() -> LIST") \ + NAMETH(values, "D.values() -> LIST") \ + NAMETH(items, "D.items() -> LIST") \ + NAMETH(iterkeys, "D.iterkeys() -> ITER") \ + NAMETH(itervalues, "D.itervalues() -> ITER") \ + NAMETH(iteritems, "D.iteritems() -> ITER") \ KWMETH(get, "D.get(KEY, [default = None]) -> VALUE") -#define GMAP_DOMETHODS(METH, KWMETH) \ - GMAP_DOROMETHODS(METH, KWMETH) \ - METH (clear, "D.clear()") \ +#define GMAP_DOMETHODS(METH, KWMETH, NAMETH) \ + GMAP_DOROMETHODS(METH, KWMETH, NAMETH) \ + NAMETH(clear, "D.clear()") \ KWMETH(setdefault, "D.setdefault(K, [default = None]) -> VALUE") \ KWMETH(pop, "D.pop(KEY, [default = ]) -> VALUE") \ - METH (popitem, "D.popitem() -> (KEY, VALUE)") \ + NAMETH(popitem, "D.popitem() -> (KEY, VALUE)") \ METH (update, "D.update(MAP)") -GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL) -#define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH) -#define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH) +GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL, GMAP_NAMETHDECL) +#define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH, GMAP_NAMETH) +#define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH, GMAP_NAMETH) /* Mapping protocol implementation. */ extern Py_ssize_t gmap_pysize(PyObject *); /* for `mp_length' */ diff --git a/rand.c b/rand.c index 9312c4c..d2b331f 100644 --- a/rand.c +++ b/rand.c @@ -80,16 +80,14 @@ end: return (-1); } -static PyObject *grmeth_byte(PyObject *me, PyObject *arg) +static PyObject *grmeth_byte(PyObject *me) { - if (!PyArg_ParseTuple(arg, ":byte")) return (0); if (grand_check(me)) return (0); return (PyInt_FromLong(grand_byte(GRAND_R(me)))); } -static PyObject *grmeth_word(PyObject *me, PyObject *arg) +static PyObject *grmeth_word(PyObject *me) { - if (!PyArg_ParseTuple(arg, ":word")) return (0); if (grand_check(me)) return (0); return (getulong(grand_word(GRAND_R(me)))); } @@ -269,8 +267,8 @@ static const PyGetSetDef grand_pygetset[] = { static const PyMethodDef grand_pymethods[] = { #define METHNAME(name) grmeth_##name - METH (byte, "R.byte() -> BYTE") - METH (word, "R.word() -> WORD") + NAMETH(byte, "R.byte() -> BYTE") + NAMETH(word, "R.word() -> WORD") METH (block, "R.block(N) -> STRING") KWMETH(mp, "R.mp(bits, [or = 0]) -> MP") METH (range, "R.range(MAX) -> INT") @@ -448,21 +446,11 @@ static PyTypeObject fibrand_pytype_skel = { /*----- True random generator ---------------------------------------------*/ -static PyObject *trmeth_gate(PyObject *me, PyObject *arg) -{ - grand *r = GRAND_R(me); - if (!PyArg_ParseTuple(arg, ":gate")) return (0); - r->ops->misc(r, RAND_GATE); - RETURN_ME; -} +static PyObject *trmeth_gate(PyObject *me) + { grand *r = GRAND_R(me); r->ops->misc(GRAND_R(me), RAND_GATE); RETURN_ME; } -static PyObject *trmeth_stretch(PyObject *me, PyObject *arg) -{ - grand *r = GRAND_R(me); - if (!PyArg_ParseTuple(arg, ":stretch")) return (0); - r->ops->misc(r, RAND_STRETCH); - RETURN_ME; -} +static PyObject *trmeth_stretch(PyObject *me) + { grand *r = GRAND_R(me); r->ops->misc(r, RAND_STRETCH); RETURN_ME; } static PyObject *trmeth_add(PyObject *me, PyObject *arg) { @@ -495,13 +483,8 @@ end: return (0); } -static PyObject *trmeth_timer(PyObject *me, PyObject *arg) -{ - grand *r = GRAND_R(me); - if (!PyArg_ParseTuple(arg, ":timer")) return (0); - r->ops->misc(r, RAND_TIMER); - RETURN_ME; -} +static PyObject *trmeth_timer(PyObject *me) + { grand *r = GRAND_R(me); r->ops->misc(r, RAND_TIMER); RETURN_ME; } static PyObject *truerand_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) @@ -520,12 +503,12 @@ end: static const PyMethodDef truerand_pymethods[] = { #define METHNAME(name) trmeth_##name - METH (gate, "R.gate()") - METH (stretch, "R.stretch()") + NAMETH(gate, "R.gate()") + NAMETH(stretch, "R.stretch()") METH (key, "R.key(BYTES)") METH (seed, "R.seed(NBITS)") METH (add, "R.add(BYTES, GOODBITS") - METH (timer, "R.timer()") + NAMETH(timer, "R.timer()") #undef METHNAME { 0 } }; @@ -754,13 +737,12 @@ static PyObject *gccrget_name(PyObject *me, void *hunoz) static PyObject *gccrget_keysz(PyObject *me, void *hunoz) { return (keysz_pywrap(GCCRAND_INFO(me)->keysz)); } -static PyObject *gclrmeth_tell(PyObject *me, PyObject *arg) +static PyObject *gclrmeth_tell(PyObject *me) { grand *r = GRAND_R(me); PyObject *rc = 0; kludge64 off; - if (!PyArg_ParseTuple(arg, ":tell")) return (0); r->ops->misc(r, SALSA20_TELLU64, &off); rc = getk64(off); return (rc); @@ -786,7 +768,7 @@ static const PyGetSetDef gccrand_pygetset[] = { static const PyMethodDef gclatinrand_pymethods[] = { #define METHNAME(name) gclrmeth_##name - METH (tell, "R.tell() -> OFF") + NAMETH(tell, "R.tell() -> OFF") METH (seek, "R.seek(OFF)") #undef METHNAME { 0 } @@ -1234,11 +1216,8 @@ end: return (rc); } -static PyObject *bbsmeth_step(PyObject *me, PyObject *arg) -{ - grand *r = GRAND_R(me); if (!PyArg_ParseTuple(arg, ":step")) return (0); - r->ops->misc(r, BBS_STEP); RETURN_ME; -} +static PyObject *bbsmeth_step(PyObject *me) + { grand *r = GRAND_R(me); r->ops->misc(r, BBS_STEP); RETURN_ME; } static PyObject *bbsmeth_bits(PyObject *me, PyObject *arg) { @@ -1250,11 +1229,8 @@ end: return (0); } -static PyObject *bbsmeth_wrap(PyObject *me, PyObject *arg) -{ - grand *r = GRAND_R(me); if (!PyArg_ParseTuple(arg, ":wrap")) return (0); - r->ops->misc(r, BBS_WRAP); RETURN_ME; -} +static PyObject *bbsmeth_wrap(PyObject *me) + { grand *r = GRAND_R(me); r->ops->misc(r, BBS_WRAP); RETURN_ME; } static PyObject *bbsget_n(PyObject *me, void *hunoz) { @@ -1284,9 +1260,9 @@ static PyObject *bbsget_stepsz(PyObject *me, void *hunoz) static const PyMethodDef bbs_pymethods[] = { #define METHNAME(name) bbsmeth_##name - METH (step, "R.step(): steps the generator (not useful)") + NAMETH(step, "R.step(): steps the generator (not useful)") METH (bits, "R.bits(N) -> W: returns N bits (<= 32) from the generator") - METH (wrap, "R.wrap(): flushes unused bits in internal buffer") + NAMETH(wrap, "R.wrap(): flushes unused bits in internal buffer") #undef METHNAME { 0 } }; diff --git a/share.c b/share.c index 16d376e..5d54947 100644 --- a/share.c +++ b/share.c @@ -241,10 +241,9 @@ end: return (0); } -static PyObject *gfsmeth_combine(PyObject *me, PyObject *arg) +static PyObject *gfsmeth_combine(PyObject *me) { PyObject *rc = 0; - if (!PyArg_ParseTuple(arg, ":combine")) goto end; if (GFSHARE_S(me)->i < GFSHARE_S(me)->t) VALERR("not enough shares yet"); rc = bytestring_pywrap(0, GFSHARE_S(me)->sz); gfshare_combine(GFSHARE_S(me), PyString_AS_STRING(rc)); @@ -256,7 +255,7 @@ static const PyMethodDef gfsharejoin_pymethods[] = { #define METHNAME(name) gfsmeth_##name METH (addedp, "S.addedp(I) -> BOOL") METH (add, "S.add(I, SHARE) -> REMAIN") - METH (combine, "S.combine() -> SECRET") + NAMETH(combine, "S.combine() -> SECRET") #undef METHNAME { 0 } }; @@ -541,10 +540,9 @@ end: return (rc); } -static PyObject *smeth_combine(PyObject *me, PyObject *arg) +static PyObject *smeth_combine(PyObject *me) { PyObject *rc = 0; - if (!PyArg_ParseTuple(arg, ":combine")) goto end; if (SHARE_S(me)->i < SHARE_S(me)->t) VALERR("not enough shares yet"); rc = mp_pywrap(share_combine(SHARE_S(me))); end: @@ -555,7 +553,7 @@ static const PyMethodDef sharejoin_pymethods[] = { #define METHNAME(name) smeth_##name METH (addedp, "S.addedp(I) -> BOOL") METH (add, "S.add(I, SHARE) -> REMAIN") - METH (combine, "S.combine() -> SECRET") + NAMETH(combine, "S.combine() -> SECRET") #undef METHNAME { 0 } }; -- 2.11.0