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/formats.c | |
parent | 36945bffa2ca648b58c99905ebf9b1b536a9188a (diff) |
Reorganized the Python plugin code.
Diffstat (limited to 'plugins/pychrysalide/core/formats.c')
-rw-r--r-- | plugins/pychrysalide/core/formats.c | 33 |
1 files changed, 22 insertions, 11 deletions
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; } |