diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-07-27 17:13:19 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-07-27 17:13:19 (GMT) |
commit | 77f88a59bfb9296df7e995e99218d27862136588 (patch) | |
tree | 6e9897f690b50da53d77266095eccb358912a1cb /plugins/pychrysa/pychrysa.c | |
parent | 359055e28bcd195fb03fd0deb1a30e5a04d5ce58 (diff) |
Fixed several mistakes in the Python bindings.
Diffstat (limited to 'plugins/pychrysa/pychrysa.c')
-rw-r--r-- | plugins/pychrysa/pychrysa.c | 86 |
1 files changed, 79 insertions, 7 deletions
diff --git a/plugins/pychrysa/pychrysa.c b/plugins/pychrysa/pychrysa.c index 45e32b4..f09c234 100644 --- a/plugins/pychrysa/pychrysa.c +++ b/plugins/pychrysa/pychrysa.c @@ -40,6 +40,7 @@ #include <plugins/plugin-int.h> +#include "helpers.h" #include "plugin.h" #include "quirks.h" #include "analysis/module.h" @@ -72,6 +73,9 @@ static PyObject *py_chrysalide_get_global_gobject(PyObject *, PyObject *); /* Détermine si l'interpréteur lancé est celui pris en compte. */ static bool is_current_abi_suitable(void); +/* Définit la version attendue de GTK à charger dans Python. */ +static bool set_version_for_gtk_namespace(const char *); + /* Charge autant de greffons composés en Python que possible. */ static bool load_python_plugins(GPluginModule *plugin, GObject *); @@ -251,6 +255,55 @@ static bool is_current_abi_suitable(void) /****************************************************************************** * * +* Paramètres : version = idenfiant de la version de GTK à stipuler. * +* * +* Description : Définit la version attendue de GTK à charger dans Python. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool set_version_for_gtk_namespace(const char *version) +{ + bool result; /* Bilan à retourner */ + PyObject *gi_mod; /* Module Python-GObject */ + PyObject *args; /* Arguments à fournir */ + + result = false; + + /** + * On cherche ici à éviter le message suivant si on charge 'gi.repository.Gtk' directement : + * + * + * PyGIWarning: Gtk was imported without specifying a version first. \ + * Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded. + * + */ + + gi_mod = PyImport_ImportModule("gi"); + + if (gi_mod != NULL) + { + args = Py_BuildValue("ss", "Gtk", "3.0"); + + run_python_method(gi_mod, "require_version", args); + + result = (PyErr_Occurred() == NULL); + + Py_DECREF(args); + Py_DECREF(gi_mod); + + } + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : - * * * * Description : Point d'entrée pour l'initialisation de Python. * @@ -362,6 +415,9 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) return NULL; } + if (!set_version_for_gtk_namespace("3.0")) + return NULL; + if (!load_all_basic_components()) { PyErr_SetString(PyExc_SystemError, "unable to load all basic components."); @@ -386,15 +442,16 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) result = PyModule_Create(&py_chrysalide_module); - status = register_python_plugin_module(result); + /* Interface 'LineGenerator' en premier... */ + status = add_glibext_module_to_python_module(result); + status &= register_python_plugin_module(result); status &= add_analysis_module_to_python_module(result); status &= add_arch_module_to_python_module(result); status &= add_common_module_to_python_module(result); status &= add_core_module_to_python_module(result); status &= add_debug_module_to_python_module(result); status &= add_format_module_to_python_module(result); - status &= add_glibext_module_to_python_module(result); status &= add_gtkext_module_to_python_module(result); status &= add_gui_module_to_python_module(result); @@ -439,9 +496,9 @@ static bool load_python_plugins(GPluginModule *plugin, GObject *ref) save = NULL; /* gcc... */ - for (path = strtok_r(paths, ";", &save); + for (path = strtok_r(paths, ":", &save); path != NULL; - path = strtok_r(NULL, ";", &save)) + path = strtok_r(NULL, ":", &save)) { dir = opendir(path); if (dir == NULL) @@ -514,6 +571,7 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin, GObject *ref) { bool result; /* Bilan à retourner */ DIR *dir; /* Répertoire à parcourir */ + int ret; /* Bilan de préparatifs */ define_internal_ref(ref); @@ -524,15 +582,27 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin, GObject *ref) if (dir != NULL) { closedir(dir); - add_to_env_var("PYTHONPATH", PLUGINS_DIR G_DIR_SEPARATOR_S "python", ";"); + add_to_env_var("PYTHONPATH", PLUGINS_DIR G_DIR_SEPARATOR_S "python", ":"); } else add_to_env_var("PYTHONPATH", PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "plugins" \ - G_DIR_SEPARATOR_S "python", ";"); + G_DIR_SEPARATOR_S "python", ":"); + + g_plugin_module_log_variadic_message(plugin, LMT_INFO, + _("PYTHONPATH environment variable set to '%s'"), + getenv("PYTHONPATH")); /* Chargement du module pour Python */ - PyImport_AppendInittab("pychrysalide", &PyInit_pychrysalide); + ret = PyImport_AppendInittab("pychrysalide", &PyInit_pychrysalide); + + if (ret == -1) + { + g_plugin_module_log_variadic_message(plugin, LMT_ERROR, + _("Can not extend the existing table of Python built-in modules.")); + result = false; + goto cpi_done; + } Py_Initialize(); @@ -540,6 +610,8 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin, GObject *ref) result = load_python_plugins(plugin, ref); + cpi_done: + return result; } |