summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/glibext
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/glibext
parent36945bffa2ca648b58c99905ebf9b1b536a9188a (diff)
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/glibext')
-rw-r--r--plugins/pychrysalide/glibext/buffercache.c22
-rw-r--r--plugins/pychrysalide/glibext/buffercache.h2
-rw-r--r--plugins/pychrysalide/glibext/bufferline.c24
-rw-r--r--plugins/pychrysalide/glibext/bufferline.h2
-rw-r--r--plugins/pychrysalide/glibext/configuration.c70
-rw-r--r--plugins/pychrysalide/glibext/configuration.h6
-rw-r--r--plugins/pychrysalide/glibext/linegen.c18
-rw-r--r--plugins/pychrysalide/glibext/linegen.h2
-rw-r--r--plugins/pychrysalide/glibext/loadedpanel.c22
-rw-r--r--plugins/pychrysalide/glibext/loadedpanel.h2
-rw-r--r--plugins/pychrysalide/glibext/module.c58
-rw-r--r--plugins/pychrysalide/glibext/module.h7
12 files changed, 149 insertions, 86 deletions
diff --git a/plugins/pychrysalide/glibext/buffercache.c b/plugins/pychrysalide/glibext/buffercache.c
index f61d34f..b01b68c 100644
--- a/plugins/pychrysalide/glibext/buffercache.c
+++ b/plugins/pychrysalide/glibext/buffercache.c
@@ -31,8 +31,9 @@
#include <glibext/gbuffercache.h>
-#include "../arch/vmpa.h"
+#include "../access.h"
#include "../helpers.h"
+#include "../arch/vmpa.h"
@@ -148,17 +149,24 @@ PyTypeObject *get_python_buffer_cache_type(void)
* *
******************************************************************************/
-bool register_python_buffer_cache(PyObject *module)
+bool ensure_python_buffer_cache_is_registered(void)
{
- PyTypeObject *py_buffer_cache_type; /* Type Python 'BufferCache' */
+ PyTypeObject *type; /* Type Python 'BufferCache' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_buffer_cache_type = get_python_buffer_cache_type();
+ type = get_python_buffer_cache_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.glibext");
+
+ dict = PyModule_GetDict(module);
- dict = PyModule_GetDict(module);
+ if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_CACHE, type, &PyGObject_Type))
+ return false;
- if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_CACHE, py_buffer_cache_type, &PyGObject_Type))
- return false;
+ }
return true;
diff --git a/plugins/pychrysalide/glibext/buffercache.h b/plugins/pychrysalide/glibext/buffercache.h
index dd41cfe..728acd7 100644
--- a/plugins/pychrysalide/glibext/buffercache.h
+++ b/plugins/pychrysalide/glibext/buffercache.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_buffer_cache_type(void);
/* Prend en charge l'objet 'pychrysalide.glibext.CodeBuffer'. */
-bool register_python_buffer_cache(PyObject *);
+bool ensure_python_buffer_cache_is_registered(void);
diff --git a/plugins/pychrysalide/glibext/bufferline.c b/plugins/pychrysalide/glibext/bufferline.c
index bfb894b..5bc8449 100644
--- a/plugins/pychrysalide/glibext/bufferline.c
+++ b/plugins/pychrysalide/glibext/bufferline.c
@@ -35,6 +35,7 @@
#include <glibext/gbufferline.h>
+#include "../access.h"
#include "../helpers.h"
#include "../arch/vmpa.h"
@@ -353,20 +354,27 @@ PyTypeObject *get_python_buffer_line_type(void)
* *
******************************************************************************/
-bool register_python_buffer_line(PyObject *module)
+bool ensure_python_buffer_line_is_registered(void)
{
- PyTypeObject *py_buffer_line_type; /* Type Python 'BufferLine' */
+ PyTypeObject *type; /* Type Python 'BufferLine' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_buffer_line_type = get_python_buffer_line_type();
+ type = get_python_buffer_line_type();
- dict = PyModule_GetDict(module);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.glibext");
+
+ dict = PyModule_GetDict(module);
- if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_LINE, py_buffer_line_type, &PyGObject_Type))
- return false;
+ if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_LINE, type, &PyGObject_Type))
+ return false;
- if (!py_buffer_line_define_constants(py_buffer_line_type))
- return false;
+ if (!py_buffer_line_define_constants(type))
+ return false;
+
+ }
return true;
diff --git a/plugins/pychrysalide/glibext/bufferline.h b/plugins/pychrysalide/glibext/bufferline.h
index d905de3..9fbebe5 100644
--- a/plugins/pychrysalide/glibext/bufferline.h
+++ b/plugins/pychrysalide/glibext/bufferline.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_buffer_line_type(void);
/* Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. */
-bool register_python_buffer_line(PyObject *);
+bool ensure_python_buffer_line_is_registered(void);
diff --git a/plugins/pychrysalide/glibext/configuration.c b/plugins/pychrysalide/glibext/configuration.c
index a780f73..18ed5db 100644
--- a/plugins/pychrysalide/glibext/configuration.c
+++ b/plugins/pychrysalide/glibext/configuration.c
@@ -31,6 +31,7 @@
#include <glibext/configuration.h>
+#include "../access.h"
#include "../helpers.h"
@@ -575,20 +576,27 @@ static bool py_config_param_define_constants(PyObject *dict)
* *
******************************************************************************/
-bool register_python_config_param(PyObject *module)
+bool ensure_python_config_param_is_registered(void)
{
- PyTypeObject *py_config_param_type; /* Type Python 'ConfigParam' */
+ PyTypeObject *type; /* Type Python 'ConfigParam' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_config_param_type = get_python_config_param_type();
+ type = get_python_config_param_type();
- dict = PyModule_GetDict(module);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.glibext");
+
+ dict = PyModule_GetDict(module);
- if (!register_class_for_pygobject(dict, G_TYPE_CFG_PARAM, py_config_param_type, &PyGObject_Type))
- return false;
+ if (!register_class_for_pygobject(dict, G_TYPE_CFG_PARAM, type, &PyGObject_Type))
+ return false;
- if (!py_config_param_define_constants(py_config_param_type->tp_dict))
- return false;
+ if (!py_config_param_define_constants(type->tp_dict))
+ return false;
+
+ }
return true;
@@ -770,21 +778,30 @@ PyTypeObject *get_python_config_param_iterator_type(void)
* *
******************************************************************************/
-bool register_python_config_param_iterator(PyObject *module)
+bool ensure_python_config_param_iterator_is_registered(void)
{
- PyTypeObject *py_config_param_iterator_type;/* Type Python 'Cnf...Iter'*/
+ PyTypeObject *type; /* Type Python 'Cnf...Iter'*/
+ PyObject *module; /* Module à recompléter */
int ret; /* Bilan d'un appel */
- py_config_param_iterator_type = get_python_config_param_iterator_type();
+ type = get_python_config_param_iterator_type();
+
+ type->tp_base = &PyBaseObject_Type;
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.glibext");
- py_config_param_iterator_type->tp_base = &PyBaseObject_Type;
+ if (PyType_Ready(type) != 0)
+ return false;
- if (PyType_Ready(py_config_param_iterator_type) != 0)
- return false;
+ Py_INCREF(type);
+ ret = PyModule_AddObject(module, "ConfigParamIterator", (PyObject *)type);
- Py_INCREF(py_config_param_iterator_type);
- ret = PyModule_AddObject(module, "ConfigParamIterator", (PyObject *)py_config_param_iterator_type);
- if (ret != 0) return false;
+ if (ret != 0)
+ return false;
+
+ }
return true;
@@ -1148,17 +1165,24 @@ PyTypeObject *get_python_generic_config_type(void)
* *
******************************************************************************/
-bool register_python_generic_config(PyObject *module)
+bool ensure_python_generic_config_is_registered(void)
{
- PyTypeObject *py_generic_config_type; /* Type Python 'GenConfig' */
+ PyTypeObject *type; /* Type Python 'GenConfig' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_generic_config_type = get_python_generic_config_type();
+ type = get_python_generic_config_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.glibext");
+
+ dict = PyModule_GetDict(module);
- dict = PyModule_GetDict(module);
+ if (!register_class_for_pygobject(dict, G_TYPE_GEN_CONFIG, type, &PyGObject_Type))
+ return false;
- if (!register_class_for_pygobject(dict, G_TYPE_GEN_CONFIG, py_generic_config_type, &PyGObject_Type))
- return false;
+ }
return true;
diff --git a/plugins/pychrysalide/glibext/configuration.h b/plugins/pychrysalide/glibext/configuration.h
index a34d8c2..7a85548 100644
--- a/plugins/pychrysalide/glibext/configuration.h
+++ b/plugins/pychrysalide/glibext/configuration.h
@@ -38,7 +38,7 @@
PyTypeObject *get_python_config_param_type(void);
/* Prend en charge l'objet 'pychrysalide.glibext.ConfigParam'. */
-bool register_python_config_param(PyObject *);
+bool ensure_python_config_param_is_registered(void);
@@ -49,7 +49,7 @@ bool register_python_config_param(PyObject *);
PyTypeObject *get_python_config_param_iterator_type(void);
/* Prend en charge l'objet 'pychrysalide.glibext.ConfigParamIterator'. */
-bool register_python_config_param_iterator(PyObject *);
+bool ensure_python_config_param_iterator_is_registered(void);
/* ----------------------- GESTION GENERIQUE DE CONFIGURATION ----------------------- */
@@ -59,7 +59,7 @@ bool register_python_config_param_iterator(PyObject *);
PyTypeObject *get_python_generic_config_type(void);
/* Prend en charge l'objet 'pychrysalide.glibext.GenConfig'. */
-bool register_python_generic_config(PyObject *);
+bool ensure_python_generic_config_is_registered(void);
diff --git a/plugins/pychrysalide/glibext/linegen.c b/plugins/pychrysalide/glibext/linegen.c
index 8368548..7b93f7e 100644
--- a/plugins/pychrysalide/glibext/linegen.c
+++ b/plugins/pychrysalide/glibext/linegen.c
@@ -32,6 +32,7 @@
#include <glibext/linegen.h>
+#include "../access.h"
#include "../helpers.h"
#include "../analysis/content.h"
#include "../arch/vmpa.h"
@@ -393,15 +394,22 @@ PyTypeObject *get_python_line_generator_type(void)
* *
******************************************************************************/
-bool register_python_line_generator(PyObject *module)
+bool ensure_python_line_generator_is_registered(void)
{
- PyTypeObject *py_line_generator_type; /* Type Python 'LineGenerator' */
+ PyTypeObject *type; /* Type Python 'LineGenerator' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_line_generator_type = get_python_line_generator_type();
+ type = get_python_line_generator_type();
- dict = PyModule_GetDict(module);
- pyg_register_interface(dict, "LineGenerator", G_TYPE_LINE_GENERATOR, py_line_generator_type);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.glibext");
+
+ dict = PyModule_GetDict(module);
+ pyg_register_interface(dict, "LineGenerator", G_TYPE_LINE_GENERATOR, type);
+
+ }
return true;
diff --git a/plugins/pychrysalide/glibext/linegen.h b/plugins/pychrysalide/glibext/linegen.h
index 6c2d161..3665d5e 100644
--- a/plugins/pychrysalide/glibext/linegen.h
+++ b/plugins/pychrysalide/glibext/linegen.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_line_generator_type(void);
/* Prend en charge l'objet 'pychrysalide.glibext.LineGenerator'. */
-bool register_python_line_generator(PyObject *);
+bool ensure_python_line_generator_is_registered(void);
diff --git a/plugins/pychrysalide/glibext/loadedpanel.c b/plugins/pychrysalide/glibext/loadedpanel.c
index ba4ced0..44f7ce6 100644
--- a/plugins/pychrysalide/glibext/loadedpanel.c
+++ b/plugins/pychrysalide/glibext/loadedpanel.c
@@ -31,6 +31,7 @@
#include <glibext/gloadedpanel.h>
+#include "../access.h"
#include "../helpers.h"
@@ -229,18 +230,25 @@ PyTypeObject *get_python_loaded_panel_type(void)
* *
******************************************************************************/
-bool register_python_loaded_panel(PyObject *module)
+bool ensure_python_loaded_panel_is_registered(void)
{
- PyTypeObject *py_loaded_panel_type; /* Type Python 'LineGenerator' */
+ PyTypeObject *type; /* Type Python 'LineGenerator' */
+ PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- py_loaded_panel_type = get_python_loaded_panel_type();
+ type = get_python_loaded_panel_type();
- dict = PyModule_GetDict(module);
- pyg_register_interface(dict, "LoadedPanel", G_TYPE_LOADED_PANEL, py_loaded_panel_type);
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.glibext");
- if (!py_loaded_panel_define_constants(py_loaded_panel_type))
- return false;
+ dict = PyModule_GetDict(module);
+ pyg_register_interface(dict, "LoadedPanel", G_TYPE_LOADED_PANEL, type);
+
+ if (!py_loaded_panel_define_constants(type))
+ return false;
+
+ }
return true;
diff --git a/plugins/pychrysalide/glibext/loadedpanel.h b/plugins/pychrysalide/glibext/loadedpanel.h
index 84f1741..35a76d1 100644
--- a/plugins/pychrysalide/glibext/loadedpanel.h
+++ b/plugins/pychrysalide/glibext/loadedpanel.h
@@ -35,7 +35,7 @@
PyTypeObject *get_python_loaded_panel_type(void);
/* Prend en charge l'objet 'pychrysalide.glibext.LoadedPanel'. */
-bool register_python_loaded_panel(PyObject *);
+bool ensure_python_loaded_panel_is_registered(void);
diff --git a/plugins/pychrysalide/glibext/module.c b/plugins/pychrysalide/glibext/module.c
index a3b0a25..45c92e8 100644
--- a/plugins/pychrysalide/glibext/module.c
+++ b/plugins/pychrysalide/glibext/module.c
@@ -33,27 +33,26 @@
#include "configuration.h"
#include "linegen.h"
#include "loadedpanel.h"
-#include "../access.h"
+#include "../helpers.h"
/******************************************************************************
* *
-* Paramètres : module = module dont la définition est à compléter. *
+* Paramètres : super = module dont la définition est à compléter. *
* *
-* Description : Ajoute le module 'glibext' au module Python. *
+* Description : Ajoute le module 'glibext' à un module Python. *
* *
-* Retour : - *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool add_glibext_module_to_python_module(PyObject *super)
+bool add_glibext_module(PyObject *super)
{
bool result; /* Bilan à retourner */
PyObject *module; /* Sous-module mis en place */
- int ret; /* Bilan d'un appel */
static PyModuleDef py_chrysalide_glibext_module = {
@@ -66,35 +65,40 @@ bool add_glibext_module_to_python_module(PyObject *super)
};
- result = false;
+ module = build_python_module(super, &py_chrysalide_glibext_module);
- module = PyModule_Create(&py_chrysalide_glibext_module);
- if (module == NULL) return false;
+ result = (module != NULL);
- ret = PyState_AddModule(super, &py_chrysalide_glibext_module);
- if (ret != 0) goto agmtpm_exit;
+ return result;
- ret = _PyImport_FixupBuiltin(module, "pychrysalide.glibext");
- if (ret != 0) goto agmtpm_exit;
+}
- Py_INCREF(module);
- ret = PyModule_AddObject(super, "glibext", module);
- if (ret != 0) goto agmtpm_exit;
- result = true;
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Intègre les objets du module 'glibext'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- result &= register_python_buffer_cache(module);
- result &= register_python_buffer_line(module);
- result &= register_python_config_param(module);
- result &= register_python_config_param_iterator(module);
- result &= register_python_generic_config(module);
- result &= register_python_line_generator(module);
- result &= register_python_loaded_panel(module);
+bool populate_glibext_module(void)
+{
+ bool result; /* Bilan à retourner */
- if (result)
- register_access_to_python_module("pychrysalide.glibext", module);
+ result = true;
- agmtpm_exit:
+ if (result) result = ensure_python_buffer_cache_is_registered();
+ if (result) result = ensure_python_buffer_line_is_registered();
+ if (result) result = ensure_python_config_param_is_registered();
+ if (result) result = ensure_python_config_param_iterator_is_registered();
+ if (result) result = ensure_python_generic_config_is_registered();
+ if (result) result = ensure_python_line_generator_is_registered();
+ if (result) result = ensure_python_loaded_panel_is_registered();
assert(result);
diff --git a/plugins/pychrysalide/glibext/module.h b/plugins/pychrysalide/glibext/module.h
index f5ec0b4..4ba5d61 100644
--- a/plugins/pychrysalide/glibext/module.h
+++ b/plugins/pychrysalide/glibext/module.h
@@ -31,8 +31,11 @@
-/* Ajoute le module 'glibext' au module Python. */
-bool add_glibext_module_to_python_module(PyObject *);
+/* Ajoute le module 'glibext' à un module Python. */
+bool add_glibext_module(PyObject *);
+
+/* Intègre les objets du module 'glibext'. */
+bool populate_glibext_module(void);