diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2022-08-18 19:05:33 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2022-08-18 19:05:33 (GMT) |
commit | f22f73bcbdb6510169c8b7c7c3fea842750c6fe5 (patch) | |
tree | c621257695d9f132dff88b9149ee86d3b0888236 /plugins/pychrysalide/gui | |
parent | 429b54556283116a29c5d699af0cf891bb1c1055 (diff) |
Handle the Python Global Interpreter Lock with more care.
Diffstat (limited to 'plugins/pychrysalide/gui')
-rw-r--r-- | plugins/pychrysalide/gui/item.c | 60 |
1 files changed, 20 insertions, 40 deletions
diff --git a/plugins/pychrysalide/gui/item.c b/plugins/pychrysalide/gui/item.c index 2046587..eb140fb 100644 --- a/plugins/pychrysalide/gui/item.c +++ b/plugins/pychrysalide/gui/item.c @@ -291,19 +291,16 @@ static GtkWidget *py_editor_item_get_widget_wrapper(const GEditorItem *item) static void py_editor_item_change_content_wrapper(GEditorItem *item, GLoadedContent *old, GLoadedContent *new) { + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ PyObject *pyobj; /* Objet Python concerné */ - PyThreadState *tstate; /* Contexte d'environnement */ PyObject *pyold; /* Conversion ou None */ PyObject *pynew; /* Conversion ou None */ PyObject *args; /* Arguments pour l'appel */ PyObject *pyret; /* Retour de Python */ - pyobj = pygobject_new(G_OBJECT(item)); - - tstate = get_pychrysalide_main_tstate(); + gstate = PyGILState_Ensure(); - if (tstate != NULL) - PyEval_RestoreThread(tstate); + pyobj = pygobject_new(G_OBJECT(item)); if (has_python_method(pyobj, "_change_content")) { @@ -334,8 +331,7 @@ static void py_editor_item_change_content_wrapper(GEditorItem *item, GLoadedCont } - if (tstate != NULL) - PyEval_SaveThread(); + PyGILState_Release(gstate); } @@ -356,19 +352,16 @@ static void py_editor_item_change_content_wrapper(GEditorItem *item, GLoadedCont static void py_editor_item_change_view_wrapper(GEditorItem *item, GLoadedPanel *old, GLoadedPanel *new) { + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ PyObject *pyobj; /* Objet Python concerné */ - PyThreadState *tstate; /* Contexte d'environnement */ PyObject *pyold; /* Conversion ou None */ PyObject *pynew; /* Conversion ou None */ PyObject *args; /* Arguments pour l'appel */ PyObject *pyret; /* Retour de Python */ - pyobj = pygobject_new(G_OBJECT(item)); - - tstate = get_pychrysalide_main_tstate(); + gstate = PyGILState_Ensure(); - if (tstate != NULL) - PyEval_RestoreThread(tstate); + pyobj = pygobject_new(G_OBJECT(item)); if (has_python_method(pyobj, "_change_view")) { @@ -399,8 +392,7 @@ static void py_editor_item_change_view_wrapper(GEditorItem *item, GLoadedPanel * } - if (tstate != NULL) - PyEval_SaveThread(); + PyGILState_Release(gstate); } @@ -420,17 +412,14 @@ static void py_editor_item_change_view_wrapper(GEditorItem *item, GLoadedPanel * static void py_editor_item_update_view_wrapper(GEditorItem *item, GLoadedPanel *panel) { + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ PyObject *pyobj; /* Objet Python concerné */ - PyThreadState *tstate; /* Contexte d'environnement */ PyObject *args; /* Arguments pour l'appel */ PyObject *pyret; /* Retour de Python */ - pyobj = pygobject_new(G_OBJECT(item)); - - tstate = get_pychrysalide_main_tstate(); + gstate = PyGILState_Ensure(); - if (tstate != NULL) - PyEval_RestoreThread(tstate); + pyobj = pygobject_new(G_OBJECT(item)); if (has_python_method(pyobj, "_update_view")) { @@ -444,8 +433,7 @@ static void py_editor_item_update_view_wrapper(GEditorItem *item, GLoadedPanel * } - if (tstate != NULL) - PyEval_SaveThread(); + PyGILState_Release(gstate); } @@ -466,17 +454,14 @@ static void py_editor_item_update_view_wrapper(GEditorItem *item, GLoadedPanel * static void py_editor_item_track_cursor_wrapper(GEditorItem *item, GLoadedPanel *panel, const GLineCursor *cursor) { + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ PyObject *pyobj; /* Objet Python concerné */ - PyThreadState *tstate; /* Contexte d'environnement */ PyObject *args; /* Arguments pour l'appel */ PyObject *pyret; /* Retour de Python */ - pyobj = pygobject_new(G_OBJECT(item)); - - tstate = get_pychrysalide_main_tstate(); + gstate = PyGILState_Ensure(); - if (tstate != NULL) - PyEval_RestoreThread(tstate); + pyobj = pygobject_new(G_OBJECT(item)); if (has_python_method(pyobj, "_track_cursor")) { @@ -491,8 +476,7 @@ static void py_editor_item_track_cursor_wrapper(GEditorItem *item, GLoadedPanel } - if (tstate != NULL) - PyEval_SaveThread(); + PyGILState_Release(gstate); } @@ -513,17 +497,14 @@ static void py_editor_item_track_cursor_wrapper(GEditorItem *item, GLoadedPanel static void py_editor_item_focus_cursor_wrapper(GEditorItem *item, GLoadedContent *content, const GLineCursor *cursor) { + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ PyObject *pyobj; /* Objet Python concerné */ - PyThreadState *tstate; /* Contexte d'environnement */ PyObject *args; /* Arguments pour l'appel */ PyObject *pyret; /* Retour de Python */ - pyobj = pygobject_new(G_OBJECT(item)); - - tstate = get_pychrysalide_main_tstate(); + gstate = PyGILState_Ensure(); - if (tstate != NULL) - PyEval_RestoreThread(tstate); + pyobj = pygobject_new(G_OBJECT(item)); if (has_python_method(pyobj, "_focus_cursor")) { @@ -538,8 +519,7 @@ static void py_editor_item_focus_cursor_wrapper(GEditorItem *item, GLoadedConten } - if (tstate != NULL) - PyEval_SaveThread(); + PyGILState_Release(gstate); } |