From dc0757504af5097a4bb323d64e429a99f86d1076 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Tue, 26 May 2015 16:02:01 +0100 Subject: [PATCH] Fix the missing-module-names bug properly. Organization: Straylight/Edgeware From: Mark Wooding Introduce a wrapper `typeready' around `PyType_Ready' which sets the module name, and call it everywhere it's needed. --- algorithms.c | 10 +++++----- catacomb-python.h | 1 + ec.c | 2 +- field.c | 2 +- group.c | 2 +- rand.c | 2 +- util.c | 16 ++++++++++++---- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/algorithms.c b/algorithms.c index aeafad3..4753cf0 100644 --- a/algorithms.c +++ b/algorithms.c @@ -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); } diff --git a/catacomb-python.h b/catacomb-python.h index bf2a840..bb84a74 100644 --- a/catacomb-python.h +++ b/catacomb-python.h @@ -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 a294f09..d27036e 100644 --- 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 f17f4d9..cce2e89 100644 --- 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 13ff554..0fc8eb2 100644 --- 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 37a40e6..6e7d03e 100644 --- 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 717c3d9..8a0c06c 100644 --- a/util.c +++ b/util.c @@ -28,6 +28,10 @@ #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); } -- [mdw]