summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/helpers.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-08-16 09:16:53 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-08-16 09:16:53 (GMT)
commitfb315963527f6412273829f09513325e446eb6c9 (patch)
tree361f19767812a8f758545e8daa2973fe0b3c9de7 /plugins/pychrysalide/helpers.c
parent36945bffa2ca648b58c99905ebf9b1b536a9188a (diff)
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/helpers.c')
-rw-r--r--plugins/pychrysalide/helpers.c62
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 */
/* ---------------------------------------------------------------------------------- */