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/core | |
parent | 36945bffa2ca648b58c99905ebf9b1b536a9188a (diff) |
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/core')
-rw-r--r-- | plugins/pychrysalide/core/demanglers.c | 29 | ||||
-rw-r--r-- | plugins/pychrysalide/core/demanglers.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/core/formats.c | 33 | ||||
-rw-r--r-- | plugins/pychrysalide/core/formats.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/core/global.c | 29 | ||||
-rw-r--r-- | plugins/pychrysalide/core/global.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/core/logs.c | 33 | ||||
-rw-r--r-- | plugins/pychrysalide/core/logs.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/core/module.c | 54 | ||||
-rw-r--r-- | plugins/pychrysalide/core/module.h | 7 | ||||
-rw-r--r-- | plugins/pychrysalide/core/params.c | 33 | ||||
-rw-r--r-- | plugins/pychrysalide/core/params.h | 2 |
12 files changed, 145 insertions, 83 deletions
diff --git a/plugins/pychrysalide/core/demanglers.c b/plugins/pychrysalide/core/demanglers.c index c3c1881..2c98ee1 100644 --- a/plugins/pychrysalide/core/demanglers.c +++ b/plugins/pychrysalide/core/demanglers.c @@ -31,6 +31,7 @@ #include <core/demanglers.h> +#include "../access.h" #include "../helpers.h" @@ -140,21 +141,31 @@ PyTypeObject *get_python_demanglers_type(void) * * ******************************************************************************/ -bool register_python_demanglers(PyObject *module) +bool ensure_python_demanglers_is_registered(void) { - PyTypeObject *py_demanglers_type; /* Type Python de 'demanglers' */ + PyTypeObject *type; /* Type Python de 'demanglers' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_demanglers_type = get_python_demanglers_type(); + type = get_python_demanglers_type(); - py_demanglers_type->tp_new = PyType_GenericNew; + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + type->tp_new = PyType_GenericNew; + + if (PyType_Ready(type) != 0) + return false; + + module = get_access_to_python_module("pychrysalide.core"); - if (PyType_Ready(py_demanglers_type) != 0) - return false; + Py_INCREF(type); + ret = PyModule_AddObject(module, "demanglers", (PyObject *)type); - Py_INCREF(py_demanglers_type); - ret = PyModule_AddObject(module, "demanglers", (PyObject *)py_demanglers_type); + if (ret != 0) + return false; + + } - return (ret == 0); + return true; } diff --git a/plugins/pychrysalide/core/demanglers.h b/plugins/pychrysalide/core/demanglers.h index b17c4cb..5fc1cf0 100644 --- a/plugins/pychrysalide/core/demanglers.h +++ b/plugins/pychrysalide/core/demanglers.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_demanglers_type(void); /* Prend en charge l'objet 'pychrysalide.core.demanglers'. */ -bool register_python_demanglers(PyObject *); +bool ensure_python_demanglers_is_registered(void); diff --git a/plugins/pychrysalide/core/formats.c b/plugins/pychrysalide/core/formats.c index 4f7c33a..f11bb46 100644 --- a/plugins/pychrysalide/core/formats.c +++ b/plugins/pychrysalide/core/formats.c @@ -31,6 +31,7 @@ #include <core/formats.h> +#include "../access.h" #include "../helpers.h" @@ -167,24 +168,34 @@ static bool py_formats_define_constants(PyTypeObject *obj_type) * * ******************************************************************************/ -bool register_python_formats(PyObject *module) +bool ensure_python_formats_is_registered(void) { - PyTypeObject *py_formats_type; /* Type Python pour 'formats' */ + PyTypeObject *type; /* Type Python pour 'formats' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_formats_type = get_python_formats_type(); + type = get_python_formats_type(); - py_formats_type->tp_new = PyType_GenericNew; + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + type->tp_new = PyType_GenericNew; + + if (PyType_Ready(type) != 0) + return false; + + if (!py_formats_define_constants(type)) + return false; - if (PyType_Ready(py_formats_type) != 0) - return false; + module = get_access_to_python_module("pychrysalide.core"); - if (!py_formats_define_constants(py_formats_type)) - return false; + Py_INCREF(type); + ret = PyModule_AddObject(module, "formats", (PyObject *)type); - Py_INCREF(py_formats_type); - ret = PyModule_AddObject(module, "formats", (PyObject *)py_formats_type); + if (ret != 0) + return false; + + } - return (ret == 0); + return true; } diff --git a/plugins/pychrysalide/core/formats.h b/plugins/pychrysalide/core/formats.h index ca12c3e..55d948a 100644 --- a/plugins/pychrysalide/core/formats.h +++ b/plugins/pychrysalide/core/formats.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_formats_type(void); /* Prend en charge l'objet 'pychrysalide.core.formats'. */ -bool register_python_formats(PyObject *); +bool ensure_python_formats_is_registered(void); diff --git a/plugins/pychrysalide/core/global.c b/plugins/pychrysalide/core/global.c index 0fe767f..e84af68 100644 --- a/plugins/pychrysalide/core/global.c +++ b/plugins/pychrysalide/core/global.c @@ -31,6 +31,7 @@ #include <core/global.h> +#include "../access.h" #include "../helpers.h" #include "../analysis/project.h" @@ -260,21 +261,31 @@ PyTypeObject *get_python_global_type(void) * * ******************************************************************************/ -bool register_python_global(PyObject *module) +bool ensure_python_global_is_registered(void) { - PyTypeObject *py_global_type; /* Type Python de 'global' */ + PyTypeObject *type; /* Type Python de 'global' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_global_type = get_python_global_type(); + type = get_python_global_type(); - py_global_type->tp_new = PyType_GenericNew; + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + type->tp_new = PyType_GenericNew; + + if (PyType_Ready(type) != 0) + return false; + + module = get_access_to_python_module("pychrysalide.core"); - if (PyType_Ready(py_global_type) != 0) - return false; + Py_INCREF(type); + ret = PyModule_AddObject(module, "_global", (PyObject *)type); - Py_INCREF(py_global_type); - ret = PyModule_AddObject(module, "_global", (PyObject *)py_global_type); + if (ret != 0) + return false; + + } - return (ret == 0); + return true; } diff --git a/plugins/pychrysalide/core/global.h b/plugins/pychrysalide/core/global.h index b136cdb..3246947 100644 --- a/plugins/pychrysalide/core/global.h +++ b/plugins/pychrysalide/core/global.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_global_type(void); /* Prend en charge l'objet 'pychrysalide.core._global'. */ -bool register_python_global(PyObject *); +bool ensure_python_global_is_registered(void); diff --git a/plugins/pychrysalide/core/logs.c b/plugins/pychrysalide/core/logs.c index 6476ed0..c0caddb 100644 --- a/plugins/pychrysalide/core/logs.c +++ b/plugins/pychrysalide/core/logs.c @@ -31,6 +31,7 @@ #include <core/logs.h> +#include "../access.h" #include "../helpers.h" @@ -255,24 +256,34 @@ static bool define_python_log_constants(PyTypeObject *obj_type) * * ******************************************************************************/ -bool register_python_logs(PyObject *module) +bool ensure_python_logs_is_registered(void) { - PyTypeObject *py_logs_type; /* Type Python pour 'logs' */ + PyTypeObject *type; /* Type Python pour 'logs' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_logs_type = get_python_logs_type(); + type = get_python_logs_type(); - py_logs_type->tp_new = PyType_GenericNew; + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + type->tp_new = PyType_GenericNew; + + if (PyType_Ready(type) != 0) + return false; + + if (!define_python_log_constants(type)) + return false; - if (PyType_Ready(py_logs_type) != 0) - return false; + module = get_access_to_python_module("pychrysalide.core"); - if (!define_python_log_constants(py_logs_type)) - return false; + Py_INCREF(type); + ret = PyModule_AddObject(module, "logs", (PyObject *)type); - Py_INCREF(py_logs_type); - ret = PyModule_AddObject(module, "logs", (PyObject *)py_logs_type); + if (ret != 0) + return false; + + } - return (ret == 0); + return true; } diff --git a/plugins/pychrysalide/core/logs.h b/plugins/pychrysalide/core/logs.h index a43d9ca..3165897 100644 --- a/plugins/pychrysalide/core/logs.h +++ b/plugins/pychrysalide/core/logs.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_logs_type(void); /* Prend en charge l'objet 'pychrysalide.core.logs'. */ -bool register_python_logs(PyObject *); +bool ensure_python_logs_is_registered(void); diff --git a/plugins/pychrysalide/core/module.c b/plugins/pychrysalide/core/module.c index 22d9a48..6171e18 100644 --- a/plugins/pychrysalide/core/module.c +++ b/plugins/pychrysalide/core/module.c @@ -33,27 +33,26 @@ #include "global.h" #include "logs.h" #include "params.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 'core' au module Python. * +* Description : Ajoute le module 'core' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_core_module_to_python_module(PyObject *super) +bool add_core_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ static PyModuleDef py_chrysalide_core_module = { @@ -66,33 +65,38 @@ bool add_core_module_to_python_module(PyObject *super) }; - result = false; + module = build_python_module(super, &py_chrysalide_core_module); - module = PyModule_Create(&py_chrysalide_core_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_core_module); - if (ret != 0) goto loading_failed; + return result; - ret = _PyImport_FixupBuiltin(module, "pychrysalide.core"); - if (ret != 0) goto loading_failed; +} - Py_INCREF(module); - ret = PyModule_AddObject(super, "core", module); - if (ret != 0) goto loading_failed; - result = true; +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'core'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - result &= register_python_demanglers(module); - result &= register_python_formats(module); - result &= register_python_global(module); - result &= register_python_logs(module); - result &= register_python_params(module); +bool populate_core_module(void) +{ + bool result; /* Bilan à retourner */ - if (result) - register_access_to_python_module("pychrysalide.core", module); + result = true; - loading_failed: + if (result) result = ensure_python_demanglers_is_registered(); + if (result) result = ensure_python_formats_is_registered(); + if (result) result = ensure_python_global_is_registered(); + if (result) result = ensure_python_logs_is_registered(); + if (result) result = ensure_python_params_is_registered(); assert(result); diff --git a/plugins/pychrysalide/core/module.h b/plugins/pychrysalide/core/module.h index 8581425..c625c82 100644 --- a/plugins/pychrysalide/core/module.h +++ b/plugins/pychrysalide/core/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'core' au module Python. */ -bool add_core_module_to_python_module(PyObject *); +/* Ajoute le module 'core' à un module Python. */ +bool add_core_module(PyObject *); + +/* Intègre les objets du module 'core'. */ +bool populate_core_module(void); diff --git a/plugins/pychrysalide/core/params.c b/plugins/pychrysalide/core/params.c index df71a88..4a55a2b 100644 --- a/plugins/pychrysalide/core/params.c +++ b/plugins/pychrysalide/core/params.c @@ -31,6 +31,7 @@ #include <core/params.h> +#include "../access.h" #include "../helpers.h" @@ -156,24 +157,34 @@ static bool py_params_define_constants(PyTypeObject *obj_type) * * ******************************************************************************/ -bool register_python_params(PyObject *module) +bool ensure_python_params_is_registered(void) { - PyTypeObject *py_params_type; /* Type Python pour 'params' */ + PyTypeObject *type; /* Type Python pour 'params' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_params_type = get_python_params_type(); + type = get_python_params_type(); - py_params_type->tp_new = PyType_GenericNew; + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + type->tp_new = PyType_GenericNew; - if (PyType_Ready(py_params_type) != 0) - return false; + if (PyType_Ready(type) != 0) + return false; - if (!py_params_define_constants(py_params_type)) - return false; + if (!py_params_define_constants(type)) + return false; - Py_INCREF(py_params_type); - ret = PyModule_AddObject(module, "params", (PyObject *)py_params_type); + module = get_access_to_python_module("pychrysalide.core"); - return (ret == 0); + Py_INCREF(type); + ret = PyModule_AddObject(module, "params", (PyObject *)type); + + if (ret != 0) + return false; + + } + + return true; } diff --git a/plugins/pychrysalide/core/params.h b/plugins/pychrysalide/core/params.h index e7297b3..b3bcece 100644 --- a/plugins/pychrysalide/core/params.h +++ b/plugins/pychrysalide/core/params.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_params_type(void); /* Prend en charge l'objet 'pychrysalide.core.params'. */ -bool register_python_params(PyObject *); +bool ensure_python_params_is_registered(void); |