From cb23e316fbf507e4eebca1551ca25f5bcff9d56f Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 8 Oct 2018 01:12:34 +0200 Subject: Fixed again bugs with the Python global lock at exit. --- plugins/pychrysalide/plugin.c | 16 +++++++++++++--- plugins/pychrysalide/pychrysa.c | 29 ++++++++++++++++++++++++++++- plugins/pychrysalide/pychrysa.h | 3 +++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c index c42235a..eb6d00d 100644 --- a/plugins/pychrysalide/plugin.c +++ b/plugins/pychrysalide/plugin.c @@ -37,6 +37,7 @@ #include "access.h" #include "helpers.h" +#include "pychrysa.h" @@ -178,16 +179,25 @@ static void g_python_plugin_dispose(GPythonPlugin *plugin) * comme dépréciée depuis Python 3.2. * * Donc on choisit les alternatives officielles. + * + * Cependant, PyThreadState_Get() renvoit l'erreur suivante : + * + * Fatal Python error: PyThreadState_Get: no current thread + * + * Donc on se rabat sur une sauvegarde, qui n'est initialisée que lorsque l'interpréteur + * est intégré dans l'éditeur. */ - tstate = PyThreadState_Get(); + tstate = get_pychrysalide_main_tstate(); - PyEval_RestoreThread(tstate); + if (tstate != NULL) + PyEval_RestoreThread(tstate); Py_XDECREF(plugin->instance); plugin->instance = NULL; - PyEval_SaveThread(); + if (tstate != NULL) + PyEval_SaveThread(); G_OBJECT_CLASS(g_python_plugin_parent_class)->dispose(G_OBJECT(plugin)); diff --git a/plugins/pychrysalide/pychrysa.c b/plugins/pychrysalide/pychrysa.c index 200bdaa..c6a114f 100644 --- a/plugins/pychrysalide/pychrysa.c +++ b/plugins/pychrysalide/pychrysa.c @@ -70,6 +70,9 @@ static bool _standalone = true; /* Réceptacle pour le chargement forcé */ static PyObject *_chrysalide_module = NULL; +/* Conservation des informations du thread principal */ +static PyThreadState *_main_tstate = NULL; + /* Fournit la révision du programme global. */ static PyObject *py_chrysalide_revision(PyObject *, PyObject *); @@ -602,6 +605,8 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin) else result = load_python_plugins(plugin); + _main_tstate = PyThreadState_Get(); + PyEval_ReleaseLock(); cpi_done: @@ -611,7 +616,6 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin) } - /****************************************************************************** * * * Paramètres : plugin = greffon à manipuler. * @@ -629,3 +633,26 @@ G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *plugin) Py_XDECREF(_chrysalide_module); } + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit les informations du thread principal. * +* * +* Retour : Indications utiles à Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyThreadState *get_pychrysalide_main_tstate(void) +{ + PyThreadState *result; /* Indications à retourner */ + + result = _main_tstate; + + return result; + +} diff --git a/plugins/pychrysalide/pychrysa.h b/plugins/pychrysalide/pychrysa.h index e1fecd6..ef5c545 100644 --- a/plugins/pychrysalide/pychrysa.h +++ b/plugins/pychrysalide/pychrysa.h @@ -94,6 +94,9 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *); /* Prend acte du déchargement du greffon. */ G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *); +/* Fournit les informations du thread principal. */ +PyThreadState *get_pychrysalide_main_tstate(void); + #endif /* _PLUGINS_PYCHRYSALIDE_H */ -- cgit v0.11.2-87-g4458