diff options
Diffstat (limited to 'plugins/pychrysalide/common')
-rw-r--r-- | plugins/pychrysalide/common/bits.c | 27 | ||||
-rw-r--r-- | plugins/pychrysalide/common/bits.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/common/fnv1a.c | 31 | ||||
-rw-r--r-- | plugins/pychrysalide/common/fnv1a.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/common/module.c | 57 | ||||
-rw-r--r-- | plugins/pychrysalide/common/module.h | 7 | ||||
-rw-r--r-- | plugins/pychrysalide/common/pathname.c | 31 | ||||
-rw-r--r-- | plugins/pychrysalide/common/pathname.h | 2 |
8 files changed, 99 insertions, 60 deletions
diff --git a/plugins/pychrysalide/common/bits.c b/plugins/pychrysalide/common/bits.c index 065f32e..e137213 100644 --- a/plugins/pychrysalide/common/bits.c +++ b/plugins/pychrysalide/common/bits.c @@ -25,6 +25,7 @@ #include "bits.h" +#include "../access.h" #include "../helpers.h" @@ -757,20 +758,30 @@ PyTypeObject *get_python_bitfield_type(void) * * ******************************************************************************/ -bool register_python_bitfield(PyObject *module) +bool ensure_python_bitfield_is_registered(void) { - PyTypeObject *py_bitfield_type; /* Type Python pour 'bitfield' */ + PyTypeObject *type; /* Type Python pour 'bitfield' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_bitfield_type = get_python_bitfield_type(); + type = get_python_bitfield_type(); + + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + if (PyType_Ready(type) != 0) + return false; - if (PyType_Ready(py_bitfield_type) != 0) - return false; + module = get_access_to_python_module("pychrysalide.common"); - Py_INCREF(py_bitfield_type); - ret = PyModule_AddObject(module, "bitfield", (PyObject *)py_bitfield_type); + Py_INCREF(type); + ret = PyModule_AddObject(module, "bitfield", (PyObject *)type); + + if (ret != 0) + return false; + + } - return (ret == 0); + return true; } diff --git a/plugins/pychrysalide/common/bits.h b/plugins/pychrysalide/common/bits.h index 3e2af73..54a4414 100644 --- a/plugins/pychrysalide/common/bits.h +++ b/plugins/pychrysalide/common/bits.h @@ -38,7 +38,7 @@ PyTypeObject *get_python_bitfield_type(void); /* Prend en charge l'objet 'pychrysalide.common.bitfield'. */ -bool register_python_bitfield(PyObject *); +bool ensure_python_bitfield_is_registered(void); /* Convertit une structure de type 'bitfield' en objet Python. */ PyObject *build_from_internal_bitfield(const bitfield_t *); diff --git a/plugins/pychrysalide/common/fnv1a.c b/plugins/pychrysalide/common/fnv1a.c index cc2c342..759c7ea 100644 --- a/plugins/pychrysalide/common/fnv1a.c +++ b/plugins/pychrysalide/common/fnv1a.c @@ -31,6 +31,9 @@ #include <common/fnv1a.h> +#include "../access.h" + + /* Détermine l'empreinte FNV1a d'une chaîne de caractères. */ static PyObject *py_fnv1a_hash(PyObject *, PyObject *); @@ -125,21 +128,31 @@ PyTypeObject *get_python_fnv1a_type(void) * * ******************************************************************************/ -bool register_python_fnv1a(PyObject *module) +bool ensure_python_fnv1a_is_registered(void) { - PyTypeObject *py_fnv1a_type; /* Type Python pour 'fnv1a' */ + PyTypeObject *type; /* Type Python pour 'fnv1a' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_fnv1a_type = get_python_fnv1a_type(); + type = get_python_fnv1a_type(); + + 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.common"); - //py_fnv1a_type->tp_new = PyType_GenericNew; + Py_INCREF(type); + ret = PyModule_AddObject(module, "fnv1a", (PyObject *)type); - if (PyType_Ready(py_fnv1a_type) != 0) - return false; + if (ret != 0) + return false; - Py_INCREF(py_fnv1a_type); - ret = PyModule_AddObject(module, "fnv1a", (PyObject *)py_fnv1a_type); + } - return (ret == 0); + return true; } diff --git a/plugins/pychrysalide/common/fnv1a.h b/plugins/pychrysalide/common/fnv1a.h index 0a40770..07a5c6c 100644 --- a/plugins/pychrysalide/common/fnv1a.h +++ b/plugins/pychrysalide/common/fnv1a.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_fnv1a_type(void); /* Prend en charge l'objet 'pychrysalide.common.fnv1a'. */ -bool register_python_fnv1a(PyObject *); +bool ensure_python_fnv1a_is_registered(void); diff --git a/plugins/pychrysalide/common/module.c b/plugins/pychrysalide/common/module.c index 7ff7528..9df257e 100644 --- a/plugins/pychrysalide/common/module.c +++ b/plugins/pychrysalide/common/module.c @@ -28,27 +28,26 @@ #include "bits.h" #include "fnv1a.h" #include "pathname.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 'common' au module Python. * +* Description : Ajoute le module 'common' à un module Python. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool add_common_module_to_python_module(PyObject *super) +bool add_common_module(PyObject *super) { bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ static PyModuleDef py_chrysalide_common_module = { @@ -61,38 +60,38 @@ bool add_common_module_to_python_module(PyObject *super) }; - result = false; + module = build_python_module(super, &py_chrysalide_common_module); - module = PyModule_Create(&py_chrysalide_common_module); - if (module == NULL) return false; + result = (module != NULL); - ret = PyState_AddModule(super, &py_chrysalide_common_module); - if (ret != 0) goto acmtpm_exit; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.common"); - if (ret != 0) goto acmtpm_exit; + return result; - Py_INCREF(module); - ret = PyModule_AddObject(super, "common", module); - if (ret != 0) goto acmtpm_exit; +} - result = true; - result &= register_python_bitfield(module); - result &= register_python_fnv1a(module); - result &= register_python_pathname(module); +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'common'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - if (result) - register_access_to_python_module("pychrysalide.common", module); +bool populate_common_module(void) +{ + bool result; /* Bilan à retourner */ - acmtpm_exit: + result = true; - if (!result) - { - printf("something went wrong in %s...\n", __FUNCTION__); - /* ... */ + if (result) result = ensure_python_bitfield_is_registered(); + if (result) result = ensure_python_fnv1a_is_registered(); + if (result) result = ensure_python_pathname_is_registered(); - } + assert(result); return result; diff --git a/plugins/pychrysalide/common/module.h b/plugins/pychrysalide/common/module.h index 446f6fe..ad25052 100644 --- a/plugins/pychrysalide/common/module.h +++ b/plugins/pychrysalide/common/module.h @@ -31,8 +31,11 @@ -/* Ajoute le module 'common' au module Python. */ -bool add_common_module_to_python_module(PyObject *); +/* Ajoute le module 'common' à un module Python. */ +bool add_common_module(PyObject *); + +/* Intègre les objets du module 'common'. */ +bool populate_common_module(void); diff --git a/plugins/pychrysalide/common/pathname.c b/plugins/pychrysalide/common/pathname.c index 40977df..c2d69c6 100644 --- a/plugins/pychrysalide/common/pathname.c +++ b/plugins/pychrysalide/common/pathname.c @@ -35,6 +35,9 @@ #include <common/pathname.h> +#include "../access.h" + + /* Calcule le chemin relatif entre deux fichiers donnés. */ static PyObject *py_build_relative_filename(PyObject *, PyObject *); @@ -183,21 +186,31 @@ PyTypeObject *get_python_pathname_type(void) * * ******************************************************************************/ -bool register_python_pathname(PyObject *module) +bool ensure_python_pathname_is_registered(void) { - PyTypeObject *py_pathname_type; /* Type Python pour 'pathname' */ + PyTypeObject *type; /* Type Python pour 'pathname' */ + PyObject *module; /* Module à recompléter */ int ret; /* Bilan d'un appel */ - py_pathname_type = get_python_pathname_type(); + type = get_python_pathname_type(); + + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + //type->tp_new = PyType_GenericNew; - //py_pathname_type->tp_new = PyType_GenericNew; + if (PyType_Ready(type) != 0) + return false; - if (PyType_Ready(py_pathname_type) != 0) - return false; + module = get_access_to_python_module("pychrysalide.common"); - Py_INCREF(py_pathname_type); - ret = PyModule_AddObject(module, "pathname", (PyObject *)py_pathname_type); + Py_INCREF(type); + ret = PyModule_AddObject(module, "pathname", (PyObject *)type); + + if (ret != 0) + return false; + + } - return (ret == 0); + return true; } diff --git a/plugins/pychrysalide/common/pathname.h b/plugins/pychrysalide/common/pathname.h index a3940c9..d571f2f 100644 --- a/plugins/pychrysalide/common/pathname.h +++ b/plugins/pychrysalide/common/pathname.h @@ -35,7 +35,7 @@ PyTypeObject *get_python_pathname_type(void); /* Prend en charge l'objet 'pychrysalide.common.pathname'. */ -bool register_python_pathname(PyObject *); +bool ensure_python_pathname_is_registered(void); |