X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/3aa33042dc760937bb9da54c09f7c668f00eb241..f281293ca70de172b275ecb3224ea36839f2f830:/field.c diff --git a/field.c b/field.c index aa071b2..7fc1f9d 100644 --- a/field.c +++ b/field.c @@ -1,13 +1,11 @@ /* -*-c-*- * - * $Id$ - * * Abstract fields * * (c) 2004 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the Python interface to Catacomb. * @@ -15,12 +13,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * Catacomb/Python is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with Catacomb/Python; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -44,9 +42,9 @@ static PyObject *fe_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { PyObject *x; mp *z; - char *kwlist[] = { "x", 0 }; + static const char *const kwlist[] = { "x", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:fe", kwlist, &x)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:fe", KWLIST, &x)) return (0); if (FE_PYCHECK(x) && FE_F(x) == FIELD_F(ty)) RETURN_OBJ(x); if ((z = getmp(x)) == 0) return (0); @@ -56,20 +54,19 @@ static PyObject *fe_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) static PyObject *field_dopywrap(PyTypeObject *ty, field *f) { - field_pyobj *fobj = newtype(ty, 0); + field_pyobj *fobj = newtype(ty, 0, f->ops->name); fobj->f = f; - fobj->ty.tp_name = (/*unconst*/ char *)f->ops->name; - fobj->ty.tp_basicsize = sizeof(fe_pyobj); - fobj->ty.tp_base = fe_pytype; + fobj->ty.ht_type.tp_basicsize = sizeof(fe_pyobj); + fobj->ty.ht_type.tp_base = fe_pytype; Py_INCREF(fe_pytype); - fobj->ty.tp_flags = (Py_TPFLAGS_DEFAULT | - Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_CHECKTYPES | - Py_TPFLAGS_HEAPTYPE); - fobj->ty.tp_alloc = PyType_GenericAlloc; - fobj->ty.tp_free = 0; - fobj->ty.tp_new = fe_pynew; - PyType_Ready(&fobj->ty); + fobj->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_CHECKTYPES | + Py_TPFLAGS_HEAPTYPE); + fobj->ty.ht_type.tp_alloc = PyType_GenericAlloc; + fobj->ty.ht_type.tp_free = 0; + fobj->ty.ht_type.tp_new = fe_pynew; + typeready(&fobj->ty.ht_type); return ((PyObject *)fobj); } @@ -77,23 +74,23 @@ PyObject *field_pywrap(field *f) { PyTypeObject *ty; - if (strcmp(F_NAME(f), "prime") == 0) ty = primefield_pytype; - else if (strcmp(F_NAME(f), "niceprime") == 0) ty = niceprimefield_pytype; - else if (strcmp(F_NAME(f), "binpoly") == 0) ty = binpolyfield_pytype; - else if (strcmp(F_NAME(f), "binnorm") == 0) ty = binnormfield_pytype; + if (STRCMP(F_NAME(f), ==, "prime")) ty = primefield_pytype; + else if (STRCMP(F_NAME(f), ==, "niceprime")) ty = niceprimefield_pytype; + else if (STRCMP(F_NAME(f), ==, "binpoly")) ty = binpolyfield_pytype; + else if (STRCMP(F_NAME(f), ==, "binnorm")) ty = binnormfield_pytype; else abort(); return (field_dopywrap(ty, f)); } field *field_copy(field *f) { - if (strcmp(F_NAME(f), "prime") == 0) + if (STRCMP(F_NAME(f), ==, "prime")) f = field_prime(f->m); - else if (strcmp(F_NAME(f), "niceprime") == 0) + else if (STRCMP(F_NAME(f), ==, "niceprime")) f = field_niceprime(f->m); - else if (strcmp(F_NAME(f), "binpoly") == 0) + else if (STRCMP(F_NAME(f), ==, "binpoly")) f = field_binpoly(f->m); - else if (strcmp(F_NAME(f), "binnorm") == 0) { + else if (STRCMP(F_NAME(f), ==, "binnorm")) { fctx_binnorm *fc = (fctx_binnorm *)f; f = field_binnorm(f->m, fc->ntop.r[fc->ntop.n - 1]); } else @@ -116,29 +113,19 @@ static mp *tofe(field *f, PyObject *o) if (FE_PYCHECK(o)) { if (FE_F(o) != f && !field_samep(FE_F(o), f)) return (0); - y = FE_X(o); - } - if ((x = tomp(o)) != 0) { + y = MP_COPY(FE_X(o)); + } else if ((x = tomp(o)) != 0) { if (MP_ZEROP(x)) - y = f->zero; + y = MP_COPY(f->zero); else if (MP_EQ(x, MP_ONE)) - y = f->one; + y = MP_COPY(f->one); + else + y = F_IN(f, MP_NEW, x); + MP_DROP(x); } - if (x) MP_DROP(x); - if (y) MP_COPY(y); return (y); } -mp *getfe(field *f, PyObject *o) -{ - mp *x = 0; - if ((x = tofe(f, o)) == 0) { - PyErr_Format(PyExc_TypeError, "can't convert %.100s to fe", - o->ob_type->tp_name); - } - return (x); -} - /*----- Field elements ----------------------------------------------------*/ static int febinop(PyObject *x, PyObject *y, @@ -232,13 +219,7 @@ end: } static long fe_pyhash(PyObject *me) -{ - long i = mp_tolong(FE_X(me)); - i ^= 0xdcf62d6c; /* random perturbance */ - if (i == -1) - i = -2; - return (i); -} + { return (mphash(FE_X(me))); } static int fe_pycoerce(PyObject **x, PyObject **y) { @@ -264,16 +245,18 @@ end: static PyObject *fe_pyint(PyObject *x) { long l; + PyObject *rc; mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x)); - if (mp_tolong_checked(xx, &l)) { MP_DROP(xx); return (0); } + if (!mp_tolong_checked(xx, &l, 0)) rc = PyInt_FromLong(l); + else rc = mp_topylong(xx); MP_DROP(xx); - return (PyInt_FromLong(l)); + return (rc); } static PyObject *fe_pylong(PyObject *x) { mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x)); - PyObject *rc = (PyObject *)mp_topylong(xx); + PyObject *rc = mp_topylong(xx); MP_DROP(xx); return (rc); } @@ -281,7 +264,7 @@ static PyObject *fe_pylong(PyObject *x) #define BASEOP(name, radix, pre) \ static PyObject *fe_py##name(PyObject *x) { \ mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x)); \ - PyObject *rc = mp_topystring(FE_X(x), radix, 0, pre, 0); \ + PyObject *rc = mp_topystring(xx, radix, 0, pre, 0); \ MP_DROP(xx); \ return (rc); \ } @@ -341,16 +324,16 @@ static PyObject *feget__value(PyObject *me, void *hunoz) return (mp_pywrap(x)); } -static PyGetSetDef fe_pygetset[] = { +static const PyGetSetDef fe_pygetset[] = { #define GETSETNAME(op, name) fe##op##_##name GET (field, "X.field -> field containing X") - GET (value, "X.value -> `natural' integer representation of X") - GET (_value, "X._value -> internal integer representation of X") + GET (value, "X.value -> `natural' MP/GF representation of X") + GET (_value, "X._value -> internal MP/GF representation of X") #undef GETSETNAME { 0 } }; -static PyMethodDef fe_pymethods[] = { +static const PyMethodDef fe_pymethods[] = { #define METHNAME(func) femeth_##func METH (inv, "X.inv() -> X^{-1}") METH (sqr, "X.sqr() -> X^2") @@ -364,7 +347,7 @@ static PyMethodDef fe_pymethods[] = { { 0 } }; -static PyNumberMethods fe_pynumber = { +static const PyNumberMethods fe_pynumber = { fe_pyadd, /* @nb_add@ */ fe_pysub, /* @nb_subtract@ */ fe_pymul, /* @nb_multiply@ */ @@ -408,8 +391,8 @@ static PyNumberMethods fe_pynumber = { }; static PyTypeObject fe_pytype_skel = { - PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.FE", /* @tp_name@ */ + PyObject_HEAD_INIT(0) 0, /* Header */ + "FE", /* @tp_name@ */ sizeof(fe_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -419,7 +402,7 @@ static PyTypeObject fe_pytype_skel = { 0, /* @tp_setattr@ */ 0, /* @tp_compare@ */ 0, /* @tp_repr@ */ - &fe_pynumber, /* @tp_as_number@ */ + PYNUMBER(fe), /* @tp_as_number@ */ 0, /* @tp_as_sequence@ */ 0, /* @tp_as_mapping@ */ fe_pyhash, /* @tp_hash@ */ @@ -433,17 +416,17 @@ static PyTypeObject fe_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Finite field elements, abstract base class.", + "Finite field elements, abstract base class.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ fe_pyrichcompare, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ - fe_pymethods, /* @tp_methods@ */ + 0, /* @tp_iternext@ */ + PYMETHODS(fe), /* @tp_methods@ */ 0, /* @tp_members@ */ - fe_pygetset, /* @tp_getset@ */ + PYGETSET(fe), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -473,10 +456,10 @@ end: static PyObject *fmeth_rand(PyObject *me, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "rng", 0 }; + static const char *const kwlist[] = { "rng", 0 }; grand *r = &rand_global; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:rand", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:rand", KWLIST, convgrand, &r)) return (0); return (fe_pywrap(me, F_RAND(FIELD_F(me), MP_NEW, r))); @@ -489,6 +472,21 @@ static PyObject *fmeth__adopt(PyObject *me, PyObject *arg) return (fe_pywrap(me, xx)); } +static PyObject *meth__Field_parse(PyObject *me, PyObject *arg) +{ + field *f; + char *p; + PyObject *rc = 0; + qd_parse qd; + + if (!PyArg_ParseTuple(arg, "Os:parse", &me, &p)) goto end; + qd.p = p; qd.e = 0; + if ((f = field_parse(&qd)) == 0) VALERR(qd.e); + rc = Py_BuildValue("(Ns)", field_pywrap(f), qd.p); +end: + return (rc); +} + static void field_pydealloc(PyObject *me) { F_DESTROY(FIELD_F(me)); @@ -516,7 +514,7 @@ static PyObject *fget_name(PyObject *me, void *hunoz) static PyObject *fget_type(PyObject *me, void *hunoz) { return (PyInt_FromLong(F_TYPE(FIELD_F(me)))); } -static PyGetSetDef field_pygetset[] = { +static const PyGetSetDef field_pygetset[] = { #define GETSETNAME(op, name) f##op##_##name GET (zero, "F.zero -> field additive identity") GET (one, "F.one -> field multiplicative identity") @@ -529,17 +527,17 @@ static PyGetSetDef field_pygetset[] = { { 0 } }; -static PyMethodDef field_pymethods[] = { +static const PyMethodDef field_pymethods[] = { #define METHNAME(name) fmeth_##name METH (_adopt, "F._adopt(X) -> FE") - KWMETH(rand, "F.rand(rng = rand) -> FE, uniformly distributed") + KWMETH(rand, "F.rand([rng = rand]) -> FE, uniformly distributed") #undef METHNAME { 0 } }; static PyTypeObject field_pytype_skel = { - PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.Field", /* @tp_name@ */ + PyObject_HEAD_INIT(0) 0, /* Header */ + "Field", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -562,17 +560,17 @@ static PyTypeObject field_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"An abstract field. This is an abstract type.", + "An abstract field. This is an abstract type.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ field_pyrichcompare, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ - field_pymethods, /* @tp_methods@ */ + 0, /* @tp_iternext@ */ + PYMETHODS(field), /* @tp_methods@ */ 0, /* @tp_members@ */ - field_pygetset, /* @tp_getset@ */ + PYGETSET(field), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -592,9 +590,9 @@ static PyObject *primefield_pynew(PyTypeObject *ty, { mp *xx = 0; field *f; - char *kwlist[] = { "p", 0 }; + static const char *const kwlist[] = { "p", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:primefield", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:primefield", KWLIST, convmp, &xx)) goto end; if ((f = field_prime(xx)) == 0) @@ -609,15 +607,15 @@ end: static PyObject *pfget_p(PyObject *me, void *hunoz) { return (mp_pywrap(MP_COPY(FIELD_F(me)->m))); } -static PyGetSetDef primefield_pygetset[] = { +static const PyGetSetDef primefield_pygetset[] = { #define GETSETNAME(op, name) pf##op##_##name - GET (p, "F.p -> prime field characteristic") + GET (p, "F.p -> prime field characteristic") #undef GETSETNAME }; static PyTypeObject primefield_pytype_skel = { - PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.PrimeField", /* @tp_name@ */ + PyObject_HEAD_INIT(0) 0, /* Header */ + "PrimeField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -640,17 +638,17 @@ static PyTypeObject primefield_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Prime fields.", + "PrimeField(P): prime fields.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ field_pyrichcompare, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ + 0, /* @tp_iternext@ */ 0, /* @tp_methods@ */ 0, /* @tp_members@ */ - primefield_pygetset, /* @tp_getset@ */ + PYGETSET(primefield), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -668,10 +666,10 @@ static PyObject *niceprimefield_pynew(PyTypeObject *ty, { mp *xx = 0; field *f; - char *kwlist[] = { "p", 0 }; + static const char *const kwlist[] = { "p", 0 }; if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:niceprimefield", - kwlist, convmp, &xx)) + KWLIST, convmp, &xx)) goto end; if ((f = field_niceprime(xx)) == 0) VALERR("bad prime for niceprimefield"); @@ -683,8 +681,8 @@ end: } static PyTypeObject niceprimefield_pytype_skel = { - PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.NicePrimeField", /* @tp_name@ */ + PyObject_HEAD_INIT(0) 0, /* Header */ + "NicePrimeField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -707,14 +705,14 @@ static PyTypeObject niceprimefield_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Nice prime fields.", + "NicePrimeField(P): prime field using Solinas reduction.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ field_pyrichcompare, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ + 0, /* @tp_iternext@ */ 0, /* @tp_methods@ */ 0, /* @tp_members@ */ 0, /* @tp_getset@ */ @@ -735,16 +733,20 @@ static PyTypeObject niceprimefield_pytype_skel = { static PyObject *bfget_m(PyObject *me, void *hunoz) { return (PyInt_FromLong(FIELD_F(me)->nbits)); } -static PyGetSetDef binfield_pygetset[] = { +static PyObject *bfget_p(PyObject *me, void *hunoz) + { return (gf_pywrap(MP_COPY(FIELD_F(me)->m))); } + +static const PyGetSetDef binfield_pygetset[] = { #define GETSETNAME(op, name) bf##op##_##name - GET (m, "F.m -> field polynomial degree") + GET (m, "F.m -> field polynomial degree") + GET (p, "F.p -> field polynomial") #undef GETSETNAME { 0 } }; static PyTypeObject binfield_pytype_skel = { - PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.BinField", /* @tp_name@ */ + PyObject_HEAD_INIT(0) 0, /* Header */ + "BinField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -774,10 +776,10 @@ static PyTypeObject binfield_pytype_skel = { field_pyrichcompare, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ + 0, /* @tp_iternext@ */ 0, /* @tp_methods@ */ 0, /* @tp_members@ */ - binfield_pygetset, /* @tp_getset@ */ + PYGETSET(binfield), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -795,9 +797,9 @@ static PyObject *binpolyfield_pynew(PyTypeObject *ty, { mp *xx = 0; field *f; - char *kwlist[] = { "p", 0 }; + static const char *const kwlist[] = { "p", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:binpolyfield", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:binpolyfield", KWLIST, convgf, &xx)) goto end; if ((f = field_binpoly(xx)) == 0) VALERR("bad poly for binpolyfield"); @@ -808,16 +810,9 @@ end: return (0); } -static PyGetSetDef binpolyfield_pygetset[] = { -#define GETSETNAME(op, name) pf##op##_##name - GET (p, "F.p -> field polynomial") -#undef GETSETNAME - { 0 } -}; - static PyTypeObject binpolyfield_pytype_skel = { - PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.BinPolyField", /* @tp_name@ */ + PyObject_HEAD_INIT(0) 0, /* Header */ + "BinPolyField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -840,17 +835,17 @@ static PyTypeObject binpolyfield_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Binary fields with polynomial basis representation.", + "BinPolyField(P): binary fields with polynomial basis representation.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ field_pyrichcompare, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ + 0, /* @tp_iternext@ */ 0, /* @tp_methods@ */ 0, /* @tp_members@ */ - binpolyfield_pygetset, /* @tp_getset@ */ + 0, /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -868,10 +863,10 @@ static PyObject *binnormfield_pynew(PyTypeObject *ty, { mp *xx = 0, *yy = 0; field *f; - char *kwlist[] = { "p", "beta", 0 }; + static const char *const kwlist[] = { "p", "beta", 0 }; if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:binnormfield", - kwlist, convgf, &xx, convgf, &yy)) + KWLIST, convgf, &xx, convgf, &yy)) goto end; if ((f = field_binnorm(xx, yy)) == 0) VALERR("bad args for binnormfield"); MP_DROP(xx); MP_DROP(yy); @@ -887,19 +882,16 @@ static PyObject *bnfget_beta(PyObject *me, void *hunoz) return (gf_pywrap(MP_COPY(fc->ntop.r[fc->ntop.n - 1]))); } -static PyGetSetDef binnormfield_pygetset[] = { -#define GETSETNAME(op, name) pf##op##_##name - GET (p, "F.p -> field polynomial") -#undef GETSETNAME +static const PyGetSetDef binnormfield_pygetset[] = { #define GETSETNAME(op, name) bnf##op##_##name - GET (beta, "F.beta -> conversion factor") + GET (beta, "F.beta -> conversion factor") #undef GETSETNAME { 0 } }; static PyTypeObject binnormfield_pytype_skel = { - PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.BinNormField", /* @tp_name@ */ + PyObject_HEAD_INIT(0) 0, /* Header */ + "BinNormField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -922,17 +914,17 @@ static PyTypeObject binnormfield_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Binary fields with normal basis representation.", + "BinNormField(P, BETA): binary fields with normal basis representation.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ field_pyrichcompare, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ + 0, /* @tp_iternext@ */ 0, /* @tp_methods@ */ 0, /* @tp_members@ */ - binnormfield_pygetset, /* @tp_getset@ */ + PYGETSET(binnormfield), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -947,27 +939,9 @@ static PyTypeObject binnormfield_pytype_skel = { /*----- Setup -------------------------------------------------------------*/ -static PyObject *meth__Field_parse(PyObject *me, PyObject *arg) -{ - field *f; - char *p; - PyObject *rc = 0; - qd_parse qd; - - if (!PyArg_ParseTuple(arg, "Os:parse", &me, &p)) - goto end; - qd.p = p; - qd.e = 0; - if ((f = field_parse(&qd)) == 0) - SYNERR(qd.e); - rc = Py_BuildValue("(Ns)", field_pywrap(f), qd.p); -end: - return (rc); -} - -static PyMethodDef methods[] = { +static const PyMethodDef methods[] = { #define METHNAME(func) meth_##func - METH (_Field_parse, "parse(STR) -> F, REST") + METH (_Field_parse, "parse(STR) -> F, REST") #undef METHNAME { 0 } };