summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/core
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/core')
-rw-r--r--plugins/pychrysa/core/module.c18
-rw-r--r--plugins/pychrysa/core/params.c29
2 files changed, 23 insertions, 24 deletions
diff --git a/plugins/pychrysa/core/module.c b/plugins/pychrysa/core/module.c
index 489f173..a866c05 100644
--- a/plugins/pychrysa/core/module.c
+++ b/plugins/pychrysa/core/module.c
@@ -25,6 +25,9 @@
#include "module.h"
+#include <assert.h>
+
+
#include "params.h"
@@ -64,27 +67,22 @@ bool add_core_module_to_python_module(PyObject *super)
if (module == NULL) return false;
ret = PyState_AddModule(super, &py_chrysalide_core_module);
- if (ret != 0) goto acmtpm_exit;
+ if (ret != 0) goto loading_failed;
ret = _PyImport_FixupBuiltin(module, "pychrysalide.core");
- if (ret != 0) goto acmtpm_exit;
+ if (ret != 0) goto loading_failed;
Py_INCREF(module);
ret = PyModule_AddObject(super, "core", module);
- if (ret != 0) goto acmtpm_exit;
+ if (ret != 0) goto loading_failed;
result = true;
result &= register_python_params(module);
- acmtpm_exit:
-
- if (!result)
- {
- printf("something went wrong in %s...\n", __FUNCTION__);
- /* ... */
+ loading_failed:
- }
+ assert(result);
return result;
diff --git a/plugins/pychrysa/core/params.c b/plugins/pychrysa/core/params.c
index 987bca6..5029304 100644
--- a/plugins/pychrysa/core/params.c
+++ b/plugins/pychrysa/core/params.c
@@ -31,12 +31,15 @@
#include <core/params.h>
+#include "../helpers.h"
+
+
/* Fournit la version du programme global. */
static PyObject *py_params_get_main_configuration(PyObject *, PyObject *);
/* Définit les constantes pour les paramètres. */
-static bool py_params_define_constants(PyObject *);
+static bool py_params_define_constants(PyTypeObject *);
@@ -114,7 +117,7 @@ PyTypeObject *get_python_params_type(void)
/******************************************************************************
* *
-* Paramètres : dict = dictionnaire à compléter. *
+* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
* *
* Description : Définit les constantes pour les paramètres. *
* *
@@ -124,21 +127,19 @@ PyTypeObject *get_python_params_type(void)
* *
******************************************************************************/
-static bool py_params_define_constants(PyObject *dict)
+static bool py_params_define_constants(PyTypeObject *obj_type)
{
- int ret; /* Bilan d'un ajout */
+ bool result; /* Bilan à retourner */
-#define DEF_STR_CONST(name) \
- ret = PyDict_SetItemString(dict, #name, PyUnicode_FromString(name)); \
- if (ret == -1) return false;
+ result = true;
- DEF_STR_CONST(MPK_LAST_PROJECT);
- DEF_STR_CONST(MPK_ELLIPSIS_HEADER);
- DEF_STR_CONST(MPK_ELLIPSIS_TAB);
- DEF_STR_CONST(MPK_KEYBINDINGS_EDIT);
- DEF_STR_CONST(MPK_AUTO_SAVE);
+ result &= PyDict_AddStringMacro(obj_type, MPK_LAST_PROJECT);
+ result &= PyDict_AddStringMacro(obj_type, MPK_ELLIPSIS_HEADER);
+ result &= PyDict_AddStringMacro(obj_type, MPK_ELLIPSIS_TAB);
+ result &= PyDict_AddStringMacro(obj_type, MPK_KEYBINDINGS_EDIT);
+ result &= PyDict_AddStringMacro(obj_type, MPK_AUTO_SAVE);
- return true;
+ return result;
}
@@ -167,7 +168,7 @@ bool register_python_params(PyObject *module)
if (PyType_Ready(py_params_type) != 0)
return false;
- if (!py_params_define_constants(py_params_type->tp_dict))
+ if (!py_params_define_constants(py_params_type))
return false;
Py_INCREF(py_params_type);