*.c: Publish algorithm and crypto-group tables as `mapping' objects.
[catacomb-python] / mp.c
diff --git a/mp.c b/mp.c
index 2fc82b2..2f8594d 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -931,7 +931,7 @@ static const PyNumberMethods mp_pynumber = {
   0,                                   /* @nb_inplace_true_divide@ */
 };
 
-static PyTypeObject mp_pytype_skel = {
+static const PyTypeObject mp_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "MP",                                        /* @tp_name@ */
   sizeof(mp_pyobj),                    /* @tp_basicsize@ */
@@ -995,6 +995,8 @@ static PyTypeObject mp_pytype_skel = {
 
 /*----- Products of small integers ----------------------------------------*/
 
+static PyTypeObject *mpmul_pytype;
+
 typedef struct mpmul_pyobj {
   PyObject_HEAD
   int livep;
@@ -1088,7 +1090,7 @@ static const PyMethodDef mpmul_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject *mpmul_pytype, mpmul_pytype_skel = {
+static const PyTypeObject mpmul_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "MPMul",                             /* @tp_name@ */
   sizeof(mpmul_pyobj),                 /* @tp_basicsize@ */
@@ -1138,6 +1140,8 @@ static PyTypeObject *mpmul_pytype, mpmul_pytype_skel = {
 
 /*----- Montgomery reduction ----------------------------------------------*/
 
+static PyTypeObject *mpmont_pytype;
+
 typedef struct mpmont_pyobj {
   PyObject_HEAD
   mpmont mm;
@@ -1355,7 +1359,7 @@ static const PyMethodDef mpmont_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject *mpmont_pytype, mpmont_pytype_skel = {
+static const PyTypeObject mpmont_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "MPMont",                            /* @tp_name@ */
   sizeof(mpmont_pyobj),                        /* @tp_basicsize@ */
@@ -1405,6 +1409,8 @@ static PyTypeObject *mpmont_pytype, mpmont_pytype_skel = {
 
 /*----- Barrett reduction -------------------------------------------------*/
 
+static PyTypeObject *mpbarrett_pytype;
+
 typedef struct mpbarrett_pyobj {
   PyObject_HEAD
   mpbarrett mb;
@@ -1494,7 +1500,7 @@ static const PyMethodDef mpbarrett_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject *mpbarrett_pytype, mpbarrett_pytype_skel = {
+static const PyTypeObject mpbarrett_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "MPBarrett",                         /* @tp_name@ */
   sizeof(mpbarrett_pyobj),             /* @tp_basicsize@ */
@@ -1544,6 +1550,8 @@ static PyTypeObject *mpbarrett_pytype, mpbarrett_pytype_skel = {
 
 /*----- Nice prime reduction ----------------------------------------------*/
 
+static PyTypeObject *mpreduce_pytype;
+
 typedef struct mpreduce_pyobj {
   PyObject_HEAD
   mpreduce mr;
@@ -1622,7 +1630,7 @@ static const const PyMethodDef mpreduce_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject *mpreduce_pytype, mpreduce_pytype_skel = {
+static const PyTypeObject mpreduce_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "MPReduce",                          /* @tp_name@ */
   sizeof(mpreduce_pyobj),              /* @tp_basicsize@ */
@@ -1672,6 +1680,8 @@ static PyTypeObject *mpreduce_pytype, mpreduce_pytype_skel = {
 
 /*----- Chinese Remainder Theorem solution --------------------------------*/
 
+static PyTypeObject *mpcrt_pytype;
+
 typedef struct mpcrt_pyobj {
   PyObject_HEAD
   mpcrt c;
@@ -1804,7 +1814,7 @@ static const PyMethodDef mpcrt_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject *mpcrt_pytype, mpcrt_pytype_skel = {
+static const PyTypeObject mpcrt_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "MPCRT",                             /* @tp_name@ */
   sizeof(mpcrt_pyobj),                 /* @tp_basicsize@ */
@@ -2104,7 +2114,7 @@ static const PyNumberMethods gf_pynumber = {
   0,                                   /* @nb_inplace_true_divide@ */
 };
 
-static PyTypeObject gf_pytype_skel = {
+static const PyTypeObject gf_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "GF",                                        /* @tp_name@ */
   sizeof(mp_pyobj),                    /* @tp_basicsize@ */
@@ -2169,6 +2179,8 @@ static PyTypeObject gf_pytype_skel = {
 
 /*----- Sparse poly reduction ---------------------------------------------*/
 
+static PyTypeObject *gfreduce_pytype;
+
 typedef struct gfreduce_pyobj {
   PyObject_HEAD
   gfreduce mr;
@@ -2303,7 +2315,7 @@ static const PyMethodDef gfreduce_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject *gfreduce_pytype, gfreduce_pytype_skel = {
+static const PyTypeObject gfreduce_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "GFReduce",                          /* @tp_name@ */
   sizeof(gfreduce_pyobj),              /* @tp_basicsize@ */
@@ -2353,14 +2365,14 @@ static PyTypeObject *gfreduce_pytype, gfreduce_pytype_skel = {
 
 /*----- Normal/poly transformation ----------------------------------------*/
 
+static PyTypeObject *gfn_pytype;
+
 typedef struct gfn_pyobj {
   PyObject_HEAD
   mp *p;
   gfn ntop, pton;
 } gfn_pyobj;
 
-static PyTypeObject *gfn_pytype, gfn_pytype_skel;
-
 #define GFN_P(o) (((gfn_pyobj *)(o))->p)
 #define GFN_PTON(o) (&((gfn_pyobj *)(o))->pton)
 #define GFN_NTOP(o) (&((gfn_pyobj *)(o))->ntop)
@@ -2441,7 +2453,7 @@ static const PyMethodDef gfn_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject gfn_pytype_skel = {
+static const PyTypeObject gfn_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "GFN",                               /* @tp_name@ */
   sizeof(gfn_pyobj),                   /* @tp_basicsize@ */
@@ -2492,6 +2504,11 @@ static PyTypeObject gfn_pytype_skel = {
 
 /*----- Glue --------------------------------------------------------------*/
 
+static const struct nameval consts[] = {
+  CONST(MPW_MAX),
+  { 0 }
+};
+
 void mp_pyinit(void)
 {
   INITTYPE(mp, root);
@@ -2516,6 +2533,7 @@ void mp_pyinsert(PyObject *mod)
   INSERT("GF", gf_pytype);
   INSERT("GFReduce", gfreduce_pytype);
   INSERT("GFN", gfn_pytype);
+  setconstants(mod, consts);
 }
 
 /*----- That's all, folks -------------------------------------------------*/