public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Phil Muldoon <pmuldoon@redhat.com>
To: Project Archer <archer@sourceware.org>
Subject: [patch] Fix PR python/10806
Date: Wed, 21 Oct 2009 11:47:00 -0000	[thread overview]
Message-ID: <4ADEF4A5.7070200@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 700 bytes --]

This patch addresses PR python/10806. It is mechanical replacement of 
the PyGILState_Ensure/Release with the more recently introduced 
ensure_python_env.

OK?

Cheers,

Phil

2009-10-21  Phil Muldoon <pmuldoon@redhat.com>

     PR python/10806

     * python/python.c (run_python_script): Use ensure_python_env over
     PyGILState_Ensure.
     (gdbpy_run_events): Likewise.
     (run_python_script): Likewise.
     (source_python_script): Likewise.
     * python/py-breakpoint.c (gdbpy_breakpoint_created): Likewise.
     (gdbpy_breakpoint_deleted): Likewise.
     * python/py-inferior.c (delete_inferior_object): Likewise.
     (add_thread_objet): Likewise.
     (delete_thread_object): Likewise.

[-- Attachment #2: pr10806.patch --]
[-- Type: text/plain, Size: 5459 bytes --]

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);
 }
 
 \f
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);
 }
 
 \f

             reply	other threads:[~2009-10-21 11:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-21 11:47 Phil Muldoon [this message]
2009-10-21 21:02 ` Tom Tromey
2009-10-22  7:40   ` Phil Muldoon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ADEF4A5.7070200@redhat.com \
    --to=pmuldoon@redhat.com \
    --cc=archer@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).