field.c: Push field-polynomial property into binary-field base class.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 23 Oct 2019 09:41:34 +0000 (10:41 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 10 Apr 2020 21:42:39 +0000 (22:42 +0100)
Using the same code as for prime fields was a mistake, but sharing the
same code between polynomial- and normal-basis fields works just fine;
but there's no point in duplicating the property-table entry when
there's a perfectly good superclass to hang the property off -- and it
already has a property table!

field.c

diff --git a/field.c b/field.c
index 417c550..e5f5eca 100644 (file)
--- a/field.c
+++ b/field.c
@@ -718,9 +718,13 @@ static PyTypeObject niceprimefield_pytype_skel = {
 static PyObject *bfget_m(PyObject *me, void *hunoz)
   { return (PyInt_FromLong(FIELD_F(me)->nbits)); }
 
+static PyObject *bfget_p(PyObject *me, void *hunoz)
+  { return (gf_pywrap(MP_COPY(FIELD_F(me)->m))); }
+
 static PyGetSetDef binfield_pygetset[] = {
 #define GETSETNAME(op, name) bf##op##_##name
   GET  (m,             "F.m -> field polynomial degree")
+  GET  (p,             "F.p -> field polynomial")
 #undef GETSETNAME
   { 0 }
 };
@@ -791,16 +795,6 @@ end:
   return (0);
 }
 
-static PyObject *bfget_p(PyObject *me, void *hunoz)
-  { return (gf_pywrap(MP_COPY(FIELD_F(me)->m))); }
-
-static PyGetSetDef binpolyfield_pygetset[] = {
-#define GETSETNAME(op, name) bf##op##_##name
-  GET  (p,             "F.p -> field polynomial")
-#undef GETSETNAME
-  { 0 }
-};
-
 static PyTypeObject binpolyfield_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "BinPolyField",                      /* @tp_name@ */
@@ -836,7 +830,7 @@ static PyTypeObject binpolyfield_pytype_skel = {
   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@ */
@@ -874,9 +868,6 @@ static PyObject *bnfget_beta(PyObject *me, void *hunoz)
 }
 
 static PyGetSetDef binnormfield_pygetset[] = {
-#define GETSETNAME(op, name) bf##op##_##name
-  GET  (p,             "F.p -> field polynomial")
-#undef GETSETNAME
 #define GETSETNAME(op, name) bnf##op##_##name
   GET  (beta,          "F.beta -> conversion factor")
 #undef GETSETNAME