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/analysis/db | |
parent | 36945bffa2ca648b58c99905ebf9b1b536a9188a (diff) |
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/analysis/db')
-rw-r--r-- | plugins/pychrysalide/analysis/db/certs.c | 29 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/certs.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/collection.c | 20 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/collection.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/item.c | 20 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/item.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/items/comment.c | 23 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/items/comment.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/items/module.c | 48 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/items/module.h | 7 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/module.c | 59 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/db/module.h | 7 |
12 files changed, 139 insertions, 82 deletions
diff --git a/plugins/pychrysalide/analysis/db/certs.c b/plugins/pychrysalide/analysis/db/certs.c index e0358d1..385e277 100644 --- a/plugins/pychrysalide/analysis/db/certs.c +++ b/plugins/pychrysalide/analysis/db/certs.c @@ -33,6 +33,7 @@ #include <analysis/db/certs.h> +#include "../../access.h" #include "../../helpers.h" @@ -307,21 +308,31 @@ PyTypeObject *get_python_certs_type(void) * * ******************************************************************************/ -bool register_python_certs(PyObject *module) +bool ensure_python_certs_is_registered(void) { - PyTypeObject *py_certs_type; /* Type Python pour 'certs' */ + PyTypeObject *type; /* Type Python pour 'certs' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_certs_type = get_python_certs_type(); + type = get_python_certs_type(); - py_certs_type->tp_new = PyType_GenericNew; + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + type->tp_new = PyType_GenericNew; - if (PyType_Ready(py_certs_type) != 0) - return false; + if (PyType_Ready(type) != 0) + return false; - Py_INCREF(py_certs_type); - ret = PyModule_AddObject(module, "certs", (PyObject *)py_certs_type); + module = get_access_to_python_module("pychrysalide.analysis.db"); - return (ret == 0); + Py_INCREF(type); + ret = PyModule_AddObject(module, "certs", (PyObject *)type); + + if (ret != 0) + return false; + + } + + return true; } diff --git a/plugins/pychrysalide/analysis/db/certs.h b/plugins/pychrysalide/analysis/db/certs.h index 2e90778..c9769b9 100644 --- a/plugins/pychrysalide/analysis/db/certs.h +++ b/plugins/pychrysalide/analysis/db/certs.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_certs_type(void); /* Prend en charge l'objet 'pychrysalide.analysis.db.certs'. */ -bool register_python_certs(PyObject *); +bool ensure_python_certs_is_registered(void); diff --git a/plugins/pychrysalide/analysis/db/collection.c b/plugins/pychrysalide/analysis/db/collection.c index 80fcfc2..7f8ac2d 100644 --- a/plugins/pychrysalide/analysis/db/collection.c +++ b/plugins/pychrysalide/analysis/db/collection.c @@ -32,6 +32,7 @@ #include <analysis/db/collection.h> +#include "../../access.h" #include "../../helpers.h" @@ -93,17 +94,24 @@ PyTypeObject *get_python_db_collection_type(void) * * ******************************************************************************/ -bool register_python_db_collection(PyObject *module) +bool ensure_python_db_collection_is_registered(void) { - PyTypeObject *py_db_collection_type; /* Type Python 'DbCollection' */ + PyTypeObject *type; /* Type Python 'DbCollection' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_db_collection_type = get_python_db_collection_type(); + type = get_python_db_collection_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.format"); - if (!register_class_for_pygobject(dict, G_TYPE_DB_COLLECTION, py_db_collection_type, &PyGObject_Type)) - return false; + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_DB_COLLECTION, type, &PyGObject_Type)) + return false; + + } return true; diff --git a/plugins/pychrysalide/analysis/db/collection.h b/plugins/pychrysalide/analysis/db/collection.h index 76256bc..9fa3c8a 100644 --- a/plugins/pychrysalide/analysis/db/collection.h +++ b/plugins/pychrysalide/analysis/db/collection.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_db_collection_type(void); /* Prend en charge l'objet 'pychrysalide.analysis.db.DbCollection'. */ -bool register_python_db_collection(PyObject *); +bool ensure_python_db_collection_is_registered(void); diff --git a/plugins/pychrysalide/analysis/db/item.c b/plugins/pychrysalide/analysis/db/item.c index 27b5bac..23e6933 100644 --- a/plugins/pychrysalide/analysis/db/item.c +++ b/plugins/pychrysalide/analysis/db/item.c @@ -32,6 +32,7 @@ #include <analysis/db/item.h> +#include "../../access.h" #include "../../helpers.h" @@ -165,17 +166,24 @@ PyTypeObject *get_python_db_item_type(void) * * ******************************************************************************/ -bool register_python_db_item(PyObject *module) +bool ensure_python_db_item_is_registered(void) { - PyTypeObject *py_db_item_type; /* Type Python 'DbItem' */ + PyTypeObject *type; /* Type Python 'DbItem' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_db_item_type = get_python_db_item_type(); + type = get_python_db_item_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.format"); + + dict = PyModule_GetDict(module); - if (!register_class_for_pygobject(dict, G_TYPE_DB_ITEM, py_db_item_type, &PyGObject_Type)) - return false; + if (!register_class_for_pygobject(dict, G_TYPE_DB_ITEM, type, &PyGObject_Type)) + return false; + + } return true; diff --git a/plugins/pychrysalide/analysis/db/item.h b/plugins/pychrysalide/analysis/db/item.h index 96122e6..376371b 100644 --- a/plugins/pychrysalide/analysis/db/item.h +++ b/plugins/pychrysalide/analysis/db/item.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_db_item_type(void); /* Prend en charge l'objet 'pychrysalide.analysis.db.DbItem'. */ -bool register_python_db_item(PyObject *); +bool ensure_python_db_item_is_registered(void); diff --git a/plugins/pychrysalide/analysis/db/items/comment.c b/plugins/pychrysalide/analysis/db/items/comment.c index 28886f5..cae866f 100644 --- a/plugins/pychrysalide/analysis/db/items/comment.c +++ b/plugins/pychrysalide/analysis/db/items/comment.c @@ -34,6 +34,7 @@ #include "../item.h" +#include "../../../access.h" #include "../../../helpers.h" #include "../../../arch/vmpa.h" @@ -224,17 +225,27 @@ PyTypeObject *get_python_db_comment_type(void) * * ******************************************************************************/ -bool register_python_db_comment(PyObject *module) +bool ensure_python_db_comment_is_registered(void) { - PyTypeObject *py_db_comment_type; /* Type Python 'DbComment' */ + PyTypeObject *type; /* Type Python 'DbComment' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - py_db_comment_type = get_python_db_comment_type(); + type = get_python_db_comment_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.analysis.db.items"); + + dict = PyModule_GetDict(module); + + if (!ensure_python_db_item_is_registered()) + return false; - if (!register_class_for_pygobject(dict, G_TYPE_DB_COMMENT, py_db_comment_type, get_python_db_item_type())) - return false; + if (!register_class_for_pygobject(dict, G_TYPE_DB_COMMENT, type, get_python_db_item_type())) + return false; + + } return true; diff --git a/plugins/pychrysalide/analysis/db/items/comment.h b/plugins/pychrysalide/analysis/db/items/comment.h index 2b4f130..9c598b1 100644 --- a/plugins/pychrysalide/analysis/db/items/comment.h +++ b/plugins/pychrysalide/analysis/db/items/comment.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_db_comment_type(void); /* Prend en charge l'objet 'pychrysalide.analysis.db.items.DbComment'. */ -bool register_python_db_comment(PyObject *); +bool ensure_python_db_comment_is_registered(void); diff --git a/plugins/pychrysalide/analysis/db/items/module.c b/plugins/pychrysalide/analysis/db/items/module.c index cf0fe56..1f9e580 100644 --- a/plugins/pychrysalide/analysis/db/items/module.c +++ b/plugins/pychrysalide/analysis/db/items/module.c @@ -29,29 +29,28 @@ #include "comment.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 'items' au module Python. * +* Description : Ajoute le module 'analysis.db.items' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_analysis_db_items_module_to_python_module(PyObject *super) +bool add_analysis_db_items_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - static PyModuleDef py_chrysalide_items_module = { + static PyModuleDef py_chrysalide_analysis_db_items_module = { .m_base = PyModuleDef_HEAD_INIT, @@ -62,29 +61,34 @@ bool add_analysis_db_items_module_to_python_module(PyObject *super) }; - result = false; + module = build_python_module(super, &py_chrysalide_analysis_db_items_module); - module = PyModule_Create(&py_chrysalide_items_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_items_module); - if (ret != 0) goto loading_failed; + return result; - ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.db.items"); - if (ret != 0) goto loading_failed; +} - Py_INCREF(module); - ret = PyModule_AddObject(super, "items", module); - if (ret != 0) goto loading_failed; - result = true; +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'analysis.db.items'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - result &= register_python_db_comment(module); +bool populate_analysis_db_items_module(void) +{ + bool result; /* Bilan à retourner */ - if (result) - register_access_to_python_module("pychrysalide.analysis.db.items", module); + result = true; - loading_failed: + if (result) result = ensure_python_db_comment_is_registered(); assert(result); diff --git a/plugins/pychrysalide/analysis/db/items/module.h b/plugins/pychrysalide/analysis/db/items/module.h index 1382226..d5112b0 100644 --- a/plugins/pychrysalide/analysis/db/items/module.h +++ b/plugins/pychrysalide/analysis/db/items/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'items' au module Python. */ -bool add_analysis_db_items_module_to_python_module(PyObject *); +/* Ajoute le module 'analysis.db.items' à un module Python. */ +bool add_analysis_db_items_module(PyObject *); + +/* Intègre les objets du module 'analysis.db.items'. */ +bool populate_analysis_db_items_module(void); diff --git a/plugins/pychrysalide/analysis/db/module.c b/plugins/pychrysalide/analysis/db/module.c index 1c4da25..33af35f 100644 --- a/plugins/pychrysalide/analysis/db/module.c +++ b/plugins/pychrysalide/analysis/db/module.c @@ -32,29 +32,28 @@ #include "collection.h" #include "item.h" #include "items/module.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 'db' au module Python. * +* Description : Ajoute le module 'analysis.db' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_analysis_db_module_to_python_module(PyObject *super) +bool add_analysis_db_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - static PyModuleDef py_chrysalide_db_module = { + static PyModuleDef py_chrysalide_analysis_db_module = { .m_base = PyModuleDef_HEAD_INIT, @@ -65,33 +64,43 @@ bool add_analysis_db_module_to_python_module(PyObject *super) }; - result = false; + module = build_python_module(super, &py_chrysalide_analysis_db_module); - module = PyModule_Create(&py_chrysalide_db_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_db_module); - if (ret != 0) goto loading_failed; + if (result) result = add_analysis_db_items_module(module); - ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.db"); - if (ret != 0) goto loading_failed; + if (!result) + Py_XDECREF(module); - Py_INCREF(module); - ret = PyModule_AddObject(super, "db", module); - if (ret != 0) goto loading_failed; + return result; - result = true; +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'analysis.db'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - result &= register_python_certs(module); - result &= register_python_db_collection(module); - result &= register_python_db_item(module); +bool populate_analysis_db_module(void) +{ + bool result; /* Bilan à retourner */ - result &= add_analysis_db_items_module_to_python_module(module); + result = true; - if (result) - register_access_to_python_module("pychrysalide.analysis.db", module); + if (result) result = ensure_python_certs_is_registered(); + if (result) result = ensure_python_db_collection_is_registered(); + if (result) result = ensure_python_db_item_is_registered(); - loading_failed: + if (result) result = populate_analysis_db_items_module(); assert(result); diff --git a/plugins/pychrysalide/analysis/db/module.h b/plugins/pychrysalide/analysis/db/module.h index d545ecb..80ee1f5 100644 --- a/plugins/pychrysalide/analysis/db/module.h +++ b/plugins/pychrysalide/analysis/db/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'db' au module Python. */ -bool add_analysis_db_module_to_python_module(PyObject *); +/* Ajoute le module 'analysis.db' à un module Python. */ +bool add_analysis_db_module(PyObject *); + +/* Intègre les objets du module 'analysis.db'. */ +bool populate_analysis_db_module(void); |