diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index afa9526..783385e 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -26,7 +26,8 @@ #include "gdbcmd.h" #include "gdbthread.h" #include "observer.h" - +#include "arch-utils.h" +#include "language.h" /* From breakpoint.c. */ extern struct breakpoint *breakpoint_chain; @@ -494,7 +495,7 @@ gdbpy_breakpoint_created (int num) { breakpoint_object *newbp; struct breakpoint *bp; - PyGILState_STATE state; + struct cleanup *cleanup; if (num < 0) return; @@ -519,7 +520,7 @@ gdbpy_breakpoint_created (int num) ++bppy_live; - state = PyGILState_Ensure (); + cleanup = ensure_python_env (get_current_arch (), current_language); if (bppy_pending_object) { @@ -552,7 +553,7 @@ gdbpy_breakpoint_created (int num) /* Just ignore errors here. */ PyErr_Clear (); - PyGILState_Release (state); + do_cleanups (cleanup); } /* Callback that is used when a breakpoint is deleted. This will @@ -560,9 +561,9 @@ gdbpy_breakpoint_created (int num) static void gdbpy_breakpoint_deleted (int num) { - PyGILState_STATE state; + struct cleanup *cleanup; - state = PyGILState_Ensure (); + cleanup = ensure_python_env (get_current_arch (), current_language); if (BPPY_VALID_P (num)) { bppy_breakpoints[num]->bp = NULL; @@ -570,7 +571,7 @@ gdbpy_breakpoint_deleted (int num) bppy_breakpoints[num] = NULL; --bppy_live; } - PyGILState_Release (state); + do_cleanups (cleanup); } diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 5e90cc2..6d970a1 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -136,7 +136,7 @@ add_inferior_object (int pid) static void delete_inferior_object (int pid) { - PyGILState_STATE state; + struct cleanup *cleanup; struct inflist_entry **inf_entry, *inf_tmp; struct threadlist_entry *th_entry, *th_tmp; @@ -149,7 +149,7 @@ delete_inferior_object (int pid) if (!*inf_entry) return; - state = PyGILState_Ensure (); + cleanup = ensure_python_env (get_current_arch (), current_language); inf_tmp = *inf_entry; inf_tmp->inf_obj->inferior = NULL; @@ -172,7 +172,7 @@ delete_inferior_object (int pid) ninferiors--; - PyGILState_Release (state); + do_cleanups (cleanup); } /* Finds the Python Inferior object for the given pid. Returns a borrowed @@ -215,19 +215,19 @@ find_thread_object (ptid_t ptid) static void add_thread_object (struct thread_info *tp) { - PyGILState_STATE state; + struct cleanup *cleanup; thread_object *thread_obj; inferior_object *inf_obj; struct threadlist_entry *entry; - state = PyGILState_Ensure (); + cleanup = ensure_python_env (get_current_arch (), current_language); thread_obj = create_thread_object (tp); if (!thread_obj) { warning (_("Can't create Python InferiorThread object.")); gdbpy_print_stack (); - PyGILState_Release (state); + do_cleanups (cleanup); return; } @@ -240,13 +240,13 @@ add_thread_object (struct thread_info *tp) inf_obj->threads = entry; inf_obj->nthreads++; - PyGILState_Release (state); + do_cleanups (cleanup); } static void delete_thread_object (struct thread_info *tp, int ignore) { - PyGILState_STATE state; + struct cleanup *cleanup; inferior_object *inf_obj; thread_object *thread_obj; struct threadlist_entry **entry, *tmp; @@ -263,7 +263,7 @@ delete_thread_object (struct thread_info *tp, int ignore) if (!*entry) return; - state = PyGILState_Ensure (); + cleanup = ensure_python_env (get_current_arch (), current_language); tmp = *entry; tmp->thread_obj->thread = NULL; @@ -275,7 +275,7 @@ delete_thread_object (struct thread_info *tp, int ignore) xfree (tmp); - PyGILState_Release (state); + do_cleanups (cleanup); } static PyObject * diff --git a/gdb/python/python.c b/gdb/python/python.c index 5a2a9ae..707b700 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -474,11 +474,11 @@ static int gdbpy_event_fds[2]; static void gdbpy_run_events (int err, gdb_client_data ignore) { - PyGILState_STATE state; + struct cleanup *cleanup; char buffer[100]; int r; - state = PyGILState_Ensure (); + cleanup = ensure_python_env (get_current_arch (), current_language); /* Just read whatever is available on the fd. It is relatively harmless if there are any bytes left over. */ @@ -500,7 +500,7 @@ gdbpy_run_events (int err, gdb_client_data ignore) xfree (item); } - PyGILState_Release (state); + do_cleanups (cleanup); } /* Submit an event to the gdb thread. */ @@ -622,10 +622,9 @@ void run_python_script (int argc, char **argv) { FILE *input; - PyGILState_STATE state; /* We never free this, since we plan to exit at the end. */ - state = PyGILState_Ensure (); + ensure_python_env (get_current_arch (), current_language); running_python_script = 1; PySys_SetArgv (argc - 1, argv + 1); @@ -643,14 +642,13 @@ run_python_script (int argc, char **argv) void source_python_script (FILE *stream, char *file) { - PyGILState_STATE state; - - state = PyGILState_Ensure (); + struct cleanup *cleanup; + cleanup = ensure_python_env (get_current_arch (), current_language); PyRun_SimpleFile (stream, file); fclose (stream); - PyGILState_Release (state); + do_cleanups (cleanup); }