summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/core/formats.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/core/formats.c')
-rw-r--r--plugins/pychrysalide/core/formats.c33
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;
}