X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/6d4db0bf4b67e65708637466d4f0d306ed1dfe53..refs/tags/1.0.2:/field.c diff --git a/field.c b/field.c index 9ea62dd..af7a561 100644 --- a/field.c +++ b/field.c @@ -7,7 +7,7 @@ * (c) 2004 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the Python interface to Catacomb. * @@ -15,12 +15,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. @@ -58,17 +58,17 @@ static PyObject *field_dopywrap(PyTypeObject *ty, field *f) { field_pyobj *fobj = newtype(ty, 0, f->ops->name); fobj->f = f; - fobj->ty.type.tp_basicsize = sizeof(fe_pyobj); - fobj->ty.type.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.type.tp_flags = (Py_TPFLAGS_DEFAULT | - Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_CHECKTYPES | - Py_TPFLAGS_HEAPTYPE); - fobj->ty.type.tp_alloc = PyType_GenericAlloc; - fobj->ty.type.tp_free = 0; - fobj->ty.type.tp_new = fe_pynew; - PyType_Ready(&fobj->ty.type); + 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; + PyType_Ready(&fobj->ty.ht_type); return ((PyObject *)fobj); } @@ -115,16 +115,16 @@ 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); } @@ -272,7 +272,7 @@ static PyObject *fe_pyint(PyObject *x) 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); } @@ -439,7 +439,7 @@ static PyTypeObject fe_pytype_skel = { fe_pyrichcompare, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ + 0, /* @tp_iternext@ */ fe_pymethods, /* @tp_methods@ */ 0, /* @tp_members@ */ fe_pygetset, /* @tp_getset@ */ @@ -568,7 +568,7 @@ static PyTypeObject field_pytype_skel = { field_pyrichcompare, /* @tp_richcompare@ */ 0, /* @tp_weaklistoffset@ */ 0, /* @tp_iter@ */ - 0, /* @tp_iternexr@ */ + 0, /* @tp_iternext@ */ field_pymethods, /* @tp_methods@ */ 0, /* @tp_members@ */ field_pygetset, /* @tp_getset@ */ @@ -593,7 +593,7 @@ static PyObject *primefield_pynew(PyTypeObject *ty, field *f; char *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) @@ -610,7 +610,7 @@ static PyObject *pfget_p(PyObject *me, void *hunoz) static 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 }; @@ -646,7 +646,7 @@ static PyTypeObject primefield_pytype_skel = { 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@ */ @@ -713,7 +713,7 @@ static PyTypeObject niceprimefield_pytype_skel = { 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@ */ @@ -736,7 +736,7 @@ static PyObject *bfget_m(PyObject *me, void *hunoz) static PyGetSetDef binfield_pygetset[] = { #define GETSETNAME(op, name) bf##op##_##name - GET (m, "F.m -> field polynomial degree") + GET (m, "F.m -> field polynomial degree") #undef GETSETNAME { 0 } }; @@ -773,7 +773,7 @@ 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@ */ @@ -809,7 +809,7 @@ end: static PyGetSetDef binpolyfield_pygetset[] = { #define GETSETNAME(op, name) pf##op##_##name - GET (p, "F.p -> field polynomial") + GET (p, "F.p -> field polynomial") #undef GETSETNAME { 0 } }; @@ -846,7 +846,7 @@ static PyTypeObject binpolyfield_pytype_skel = { 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@ */ @@ -888,10 +888,10 @@ static PyObject *bnfget_beta(PyObject *me, void *hunoz) static PyGetSetDef binnormfield_pygetset[] = { #define GETSETNAME(op, name) pf##op##_##name - GET (p, "F.p -> field polynomial") + GET (p, "F.p -> field polynomial") #undef GETSETNAME #define GETSETNAME(op, name) bnf##op##_##name - GET (beta, "F.beta -> conversion factor") + GET (beta, "F.beta -> conversion factor") #undef GETSETNAME { 0 } }; @@ -928,7 +928,7 @@ static PyTypeObject binnormfield_pytype_skel = { 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@ */ @@ -966,7 +966,7 @@ end: static PyMethodDef methods[] = { #define METHNAME(func) meth_##func - METH (_Field_parse, "parse(STR) -> F, REST") + METH (_Field_parse, "parse(STR) -> F, REST") #undef METHNAME { 0 } };