diff options
Diffstat (limited to 'plugins/pychrysalide/helpers.c')
-rw-r--r-- | plugins/pychrysalide/helpers.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/plugins/pychrysalide/helpers.c b/plugins/pychrysalide/helpers.c index 4c25be5..4ada405 100644 --- a/plugins/pychrysalide/helpers.c +++ b/plugins/pychrysalide/helpers.c @@ -25,11 +25,15 @@ #include <assert.h> +#include <malloc.h> #include <pygobject.h> #include <stdarg.h> #include <string.h> +#include "access.h" + + /* ---------------------------------------------------------------------------------- */ /* ACCELERATEURS POUR PYTHON UNIQUEMENT */ @@ -250,6 +254,64 @@ bool PyDict_AddStringConstant(PyTypeObject *obj_type, const char *key, const cha /* ---------------------------------------------------------------------------------- */ +/* MISE EN PLACE DE MODULES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : super = module dont la définition est à compléter. * +* def = définition du module à créer. * +* * +* Description : Met en place un nouveau module Python. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *build_python_module(PyObject *super, PyModuleDef *def) +{ + PyObject *result; /* Création à retourner */ + int ret; /* Bilan d'un appel */ + char *dot; /* Dernier point de ce chemin */ + + result = PyModule_Create(def); + if (result == NULL) goto quick_bad_exit; + + ret = PyState_AddModule(super, def); + if (ret != 0) goto bad_exit; + + ret = _PyImport_FixupBuiltin(result, def->m_name); + if (ret != 0) goto bad_exit; + + dot = strrchr(def->m_name, '.'); + assert(dot != NULL); + + Py_INCREF(result); + ret = PyModule_AddObject(super, dot + 1, result); + if (ret != 0) goto bad_exit; + + register_access_to_python_module(def->m_name, result); + + return result; + + bad_exit: + + Py_DECREF(result); + + quick_bad_exit: + + assert(false); + + return false; + +} + + + +/* ---------------------------------------------------------------------------------- */ /* CONFORTS CIBLANT PYGOBJECT */ /* ---------------------------------------------------------------------------------- */ |