diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-08-16 09:16:53 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-08-16 09:16:53 (GMT) |
commit | fb315963527f6412273829f09513325e446eb6c9 (patch) | |
tree | 361f19767812a8f758545e8daa2973fe0b3c9de7 /plugins/pychrysalide/mangling | |
parent | 36945bffa2ca648b58c99905ebf9b1b536a9188a (diff) |
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/mangling')
-rw-r--r-- | plugins/pychrysalide/mangling/demangler.c | 20 | ||||
-rw-r--r-- | plugins/pychrysalide/mangling/demangler.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/mangling/module.c | 46 | ||||
-rw-r--r-- | plugins/pychrysalide/mangling/module.h | 7 |
4 files changed, 46 insertions, 29 deletions
diff --git a/plugins/pychrysalide/mangling/demangler.c b/plugins/pychrysalide/mangling/demangler.c index 37935c9..15c9c62 100644 --- a/plugins/pychrysalide/mangling/demangler.c +++ b/plugins/pychrysalide/mangling/demangler.c @@ -31,6 +31,7 @@ #include <mangling/demangler.h> +#include "../access.h" #include "../helpers.h" @@ -202,17 +203,24 @@ PyTypeObject *get_python_compiler_demangler_type(void) * * ******************************************************************************/ -bool register_python_compiler_demangler(PyObject *module) +bool ensure_python_compiler_demangler_is_registered(void) { - PyTypeObject *py_comp_demangler_type; /* Type Python 'CompDemangler' */ + PyTypeObject *type; /* Type Python 'CompDemangler' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_comp_demangler_type = get_python_compiler_demangler_type(); + type = get_python_compiler_demangler_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.mangling"); + + dict = PyModule_GetDict(module); - if (!register_class_for_pygobject(dict, G_TYPE_COMP_DEMANGLER, py_comp_demangler_type, &PyGObject_Type)) - return false; + if (!register_class_for_pygobject(dict, G_TYPE_COMP_DEMANGLER, type, &PyGObject_Type)) + return false; + + } return true; diff --git a/plugins/pychrysalide/mangling/demangler.h b/plugins/pychrysalide/mangling/demangler.h index c2094b7..0c31f7c 100644 --- a/plugins/pychrysalide/mangling/demangler.h +++ b/plugins/pychrysalide/mangling/demangler.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_compiler_demangler_type(void); /* Prend en charge l'objet 'pychrysalide.format.elf.ElfFormat'. */ -bool register_python_compiler_demangler(PyObject *); +bool ensure_python_compiler_demangler_is_registered(void); diff --git a/plugins/pychrysalide/mangling/module.c b/plugins/pychrysalide/mangling/module.c index a462e3e..2b2aef7 100644 --- a/plugins/pychrysalide/mangling/module.c +++ b/plugins/pychrysalide/mangling/module.c @@ -29,27 +29,26 @@ #include "demangler.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 'mangling' au module Python. * +* Description : Ajoute le module 'mangling' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_mangling_module_to_python_module(PyObject *super) +bool add_mangling_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ static PyModuleDef py_chrysalide_mangling_module = { @@ -62,27 +61,34 @@ bool add_mangling_module_to_python_module(PyObject *super) }; - result = false; + module = build_python_module(super, &py_chrysalide_mangling_module); - module = PyModule_Create(&py_chrysalide_mangling_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_mangling_module); - if (ret != 0) goto loading_failed; + return result; - ret = _PyImport_FixupBuiltin(module, "pychrysalide.mangling"); - if (ret != 0) goto loading_failed; +} - Py_INCREF(module); - ret = PyModule_AddObject(super, "mangling", module); - if (ret != 0) goto loading_failed; - result = register_python_compiler_demangler(module); +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'mangling'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool populate_mangling_module(void) +{ + bool result; /* Bilan à retourner */ - if (result) - register_access_to_python_module("pychrysalide.mangling", module); + result = true; - loading_failed: + if (result) result = ensure_python_compiler_demangler_is_registered(); assert(result); diff --git a/plugins/pychrysalide/mangling/module.h b/plugins/pychrysalide/mangling/module.h index 126aa7e..27c7353 100644 --- a/plugins/pychrysalide/mangling/module.h +++ b/plugins/pychrysalide/mangling/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'mangling' au module Python. */ -bool add_mangling_module_to_python_module(PyObject *); +/* Ajoute le module 'mangling' à un module Python. */ +bool add_mangling_module(PyObject *); + +/* Intègre les objets du module 'mangling'. */ +bool populate_mangling_module(void); |