chiark / gitweb /
Fix the missing-module-names bug properly.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 26 May 2015 15:02:01 +0000 (16:02 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 26 May 2015 15:04:44 +0000 (16:04 +0100)
Introduce a wrapper `typeready' around `PyType_Ready' which sets the
module name, and call it everywhere it's needed.

algorithms.c
catacomb-python.h
ec.c
field.c
group.c
rand.c
util.c

index aeafad3c0336e6cc4dad12b93624b81dc6fb0ea3..4753cf0c3060e623314bc45d7244a0342b208ca3 100644 (file)
@@ -487,7 +487,7 @@ PyObject *gccipher_pywrap(gccipher *cc)
   g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
   g->ty.ht_type.tp_free = 0;
   g->ty.ht_type.tp_new = gcipher_pynew;
-  PyType_Ready(&g->ty.ht_type);
+  typeready(&g->ty.ht_type);
   return ((PyObject *)g);
 }
 
@@ -731,7 +731,7 @@ PyObject *gchash_pywrap(gchash *ch)
   g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
   g->ty.ht_type.tp_free = 0;
   g->ty.ht_type.tp_new = ghash_pynew;
-  PyType_Ready(&g->ty.ht_type);
+  typeready(&g->ty.ht_type);
   return ((PyObject *)g);
 }
 
@@ -986,7 +986,7 @@ PyObject *gcmac_pywrap(gcmac *cm)
   g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
   g->ty.ht_type.tp_free = 0;
   g->ty.ht_type.tp_new = gmac_pynew;
-  PyType_Ready(&g->ty.ht_type);
+  typeready(&g->ty.ht_type);
   return ((PyObject *)g);
 }
 
@@ -1006,7 +1006,7 @@ PyObject *gmac_pywrap(PyObject *cobj, gmac *m, unsigned f)
   g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
   g->ty.ht_type.tp_free = 0;
   g->ty.ht_type.tp_new = gmhash_pynew;
-  PyType_Ready(&g->ty.ht_type);
+  typeready(&g->ty.ht_type);
   g->m = m;
   g->f = f;
   return ((PyObject *)g);
@@ -1275,7 +1275,7 @@ static PyObject *gcprp_pywrap(const prpinfo *prp)
   g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
   g->ty.ht_type.tp_free = 0;
   g->ty.ht_type.tp_new = gprp_pynew;
-  PyType_Ready(&g->ty.ht_type);
+  typeready(&g->ty.ht_type);
   return ((PyObject *)g);
 }
 
index bf2a840cc33cb8c557b7b98527e4dabfbeee0f30..bb84a74dec4297ac2afb7c87dff38c5051fa4354 100644 (file)
@@ -247,6 +247,7 @@ extern PyObject *getulong(unsigned long);
 extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
 
 extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
+extern void typeready(PyTypeObject *);
 extern PyTypeObject *inittype(PyTypeObject *);
 extern void addmethods(const PyMethodDef *);
 extern PyMethodDef *donemethods(void);
diff --git a/ec.c b/ec.c
index a294f093c2f9de40851637416b53984f84bc3bed..d27036eed9c478136bf0fd35d0a9b82490edf07b 100644 (file)
--- a/ec.c
+++ b/ec.c
@@ -916,7 +916,7 @@ static PyObject *eccurve_dopywrap(PyTypeObject *ty,
   cobj->ty.ht_type.tp_alloc = PyType_GenericAlloc;
   cobj->ty.ht_type.tp_free = 0;
   cobj->ty.ht_type.tp_new = ecpt_pynew;
-  PyType_Ready(&cobj->ty.ht_type);
+  typeready(&cobj->ty.ht_type);
   return ((PyObject *)cobj);
 }
 
diff --git a/field.c b/field.c
index f17f4d9eaa22784c94eaa52d0b5094e853ea20a9..cce2e89124d10d22ef83d6a613826df65c4c9fef 100644 (file)
--- a/field.c
+++ b/field.c
@@ -66,7 +66,7 @@ static PyObject *field_dopywrap(PyTypeObject *ty, field *f)
   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);
+  typeready(&fobj->ty.ht_type);
   return ((PyObject *)fobj);
 }
 
diff --git a/group.c b/group.c
index 13ff554d97edaf7e810a917aa46a1c27d3954ba5..0fc8eb2b228886e7d65278d0a7829a443bc618cb 100644 (file)
--- a/group.c
+++ b/group.c
@@ -542,7 +542,7 @@ static PyObject *group_dopywrap(PyTypeObject *ty, group *g)
   gobj->ty.ht_type.tp_alloc = PyType_GenericAlloc;
   gobj->ty.ht_type.tp_free = 0;
   gobj->ty.ht_type.tp_new = ge_pynew;
-  PyType_Ready(&gobj->ty.ht_type);
+  typeready(&gobj->ty.ht_type);
   return ((PyObject *)gobj);
 }
 
diff --git a/rand.c b/rand.c
index 37a40e6e9394214d98a950e6d2edc8cea9fe2499..6e7d03ef19c2293a75dff51da21510a8eec56898 100644 (file)
--- a/rand.c
+++ b/rand.c
@@ -655,7 +655,7 @@ static PyObject *gccrand_pywrap(const gccrand_info *info)
     g->ty.ht_type.tp_new = gcirand_pynew;
   else
     g->ty.ht_type.tp_new = gcrand_pynew;
-  PyType_Ready(&g->ty.ht_type);
+  typeready(&g->ty.ht_type);
   return ((PyObject *)g);
 }
 
diff --git a/util.c b/util.c
index 717c3d97258413f99a04e7f81e9bfbd03d6e958a..8a0c06c0e75c58955c40a8f783f8abb8fa75686c 100644 (file)
--- a/util.c
+++ b/util.c
 
 #include "catacomb-python.h"
 
+/*----- External values ---------------------------------------------------*/
+
+static PyObject *modname = 0;
+
 /*----- Conversions -------------------------------------------------------*/
 
 PyObject *getulong(unsigned long w)
@@ -168,14 +172,17 @@ void *newtype(PyTypeObject *metaty,
   return (ty);
 }
 
+void typeready(PyTypeObject *ty)
+{
+  PyType_Ready(ty);
+  PyDict_SetItemString(ty->tp_dict, "__module__", modname);
+}
+
 PyTypeObject *inittype(PyTypeObject *tyskel)
 {
-  static PyObject *modname = 0;
   PyTypeObject *ty = newtype(&PyType_Type, tyskel, 0);
-  if (!modname) modname = PyString_FromString("catacomb");
   ty->tp_flags |= Py_TPFLAGS_HEAPTYPE;
-  PyType_Ready(ty);
-  PyDict_SetItemString(ty->tp_dict, "__module__", modname);
+  typeready(ty);
   return (ty);
 }
 
@@ -637,6 +644,7 @@ PyMethodDef gmap_pymethods[] = {
 
 void util_pyinit(void)
 {
+  modname = PyString_FromString("catacomb");
   INITTYPE(itemiter, root);
   INITTYPE(valiter, root);
 }