pyke/pyke.c: Check conversions hidden inside `KWLIST' and `KWMETH'.
[catacomb-python] / field.c
diff --git a/field.c b/field.c
index c23f311..e33fdfd 100644 (file)
--- a/field.c
+++ b/field.c
@@ -74,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
@@ -416,7 +416,7 @@ 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@ */
@@ -545,7 +545,7 @@ 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@ */
@@ -623,7 +623,7 @@ static PyTypeObject primefield_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"PrimeField(P): prime fields.",
+  "PrimeField(P): prime fields.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -690,7 +690,7 @@ static PyTypeObject niceprimefield_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"NicePrimeField(P): prime field using Solinas reduction.",
+  "NicePrimeField(P): prime field using Solinas reduction.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -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 }
 };
@@ -750,7 +754,7 @@ static PyTypeObject binfield_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Binary fields.  Abstract class.",
+  "Binary fields.  Abstract class.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -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@ */
@@ -826,7 +820,7 @@ static PyTypeObject binpolyfield_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"BinPolyField(P): binary fields with polynomial basis representation.",
+  "BinPolyField(P): binary fields with polynomial basis representation.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -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
@@ -908,7 +899,7 @@ static PyTypeObject binnormfield_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"BinNormField(P, BETA): binary fields with normal basis representation.",
+  "BinNormField(P, BETA): binary fields with normal basis representation.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -953,7 +944,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 }
 };