public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-swagiaal-oguz: Copy listeners list in emit function.
@ 2010-12-07 16:58 swagiaal
  0 siblings, 0 replies; only message in thread
From: swagiaal @ 2010-12-07 16:58 UTC (permalink / raw)
  To: archer-commits

The branch, archer-swagiaal-oguz has been updated
       via  13aea7308f94d103830d0d3ffcd807764c8e4778 (commit)
       via  084266175cd512286857410592c15cefdf63028d (commit)
      from  b1c0beba3bf927d0f22c4db603f4223834dff305 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 13aea7308f94d103830d0d3ffcd807764c8e4778
Author: Sami Wagiaalla <swagiaal@redhat.com>
Date:   Tue Dec 7 11:57:41 2010 -0500

    Copy listeners list in emit function.

commit 084266175cd512286857410592c15cefdf63028d
Author: Sami Wagiaalla <swagiaal@redhat.com>
Date:   Tue Dec 7 11:23:00 2010 -0500

    Consolodate emit functions.

-----------------------------------------------------------------------

Summary of changes:
 gdb/python/py-breakpointstopevent.c |   30 ++-----------------------
 gdb/python/py-continueevent.c       |   17 ++------------
 gdb/python/py-event.c               |   36 ++++++++++++++++++++++++++++---
 gdb/python/py-event.h               |   40 +++++++++++++++++++++++++++++++++++
 gdb/python/py-exitedevent.c         |   17 ++------------
 gdb/python/py-infthread.c           |    2 -
 gdb/python/py-signalstopevent.c     |   18 ++-------------
 gdb/python/py-stopevent.c           |   17 ++------------
 gdb/python/py-stopevent.h           |   23 ++++++++++++++++++++
 gdb/python/python-internal.h        |   18 +--------------
 gdb/python/python.c                 |   17 ++++++++++++++
 11 files changed, 129 insertions(+), 106 deletions(-)
 create mode 100644 gdb/python/py-event.h
 create mode 100644 gdb/python/py-stopevent.h

First 500 lines of diff:
diff --git a/gdb/python/py-breakpointstopevent.c b/gdb/python/py-breakpointstopevent.c
index 7d8dc7b..96719fb 100644
--- a/gdb/python/py-breakpointstopevent.c
+++ b/gdb/python/py-breakpointstopevent.c
@@ -17,10 +17,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "defs.h"
-#include "command.h"
-#include "python-internal.h"
-#include "inferior.h"
+#include "py-event.h"
 
 static PyTypeObject breakpoint_stop_event_object_type;
 
@@ -105,10 +102,6 @@ void
 emit_breakpoint_stop_event (struct bpstats *bs)
 {
   thread_object *inferior_thread;
-  PyObject *callback_list;
-  PyObject *args_tuple;
-  PyObject *result;
-  Py_ssize_t i;
   breakpoint_object *breakpoint;
   breakpoint_stop_event_object *breakpoint_stop_event_obj;
 
@@ -118,25 +111,8 @@ emit_breakpoint_stop_event (struct bpstats *bs)
 
   breakpoint_stop_event_obj = create_breakpoint_stop_event_object (breakpoint);
 
-  // Get the list of listeners.
-  callback_list = (PyObject *)
-    (inferior_thread->breakpoint_stop_event->callbacks);
-
-  // Prepare argument tuple.
-  args_tuple = PyTuple_New ((Py_ssize_t) 1);
-  PyTuple_SetItem (args_tuple, (Py_ssize_t) 0,
-                   (PyObject *) breakpoint_stop_event_obj);
-
-  // Notify listeners.
-  for (i = 0; i < PyList_Size (callback_list); i++)
-    {
-      result = PyObject_CallObject (PyList_GET_ITEM (callback_list, i),
-                                    args_tuple);
-
-      if (result == NULL)
-	error (_("Event call back failed."));
-
-    }
+  evpy_emit_event ((event_object *) breakpoint_stop_event_obj,
+                   inferior_thread->breakpoint_stop_event);
 }
 
 static PyGetSetDef breakpoint_stop_event_object_getset[] =
diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c
index f2e31e4..6352bdb 100644
--- a/gdb/python/py-continueevent.c
+++ b/gdb/python/py-continueevent.c
@@ -17,10 +17,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "defs.h"
-#include "command.h"
-#include "python-internal.h"
-#include "inferior.h"
+#include "py-event.h"
 
 static PyTypeObject continue_event_object_type;
 
@@ -90,16 +87,8 @@ emit_continue_event (ptid_t ptid)
 
   continue_event_obj = create_continue_event_object();
 
-  callback_list = (PyObject *)
-    (inferior_thread->continue_event->callbacks);
-
-  args_tuple = PyTuple_New ((Py_ssize_t) 1);
-  PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) continue_event_obj);
-
-  for (i = 0; i < PyList_Size (callback_list); i++)
-    {
-      PyObject_CallObject (PyList_GET_ITEM (callback_list, i), args_tuple);
-    }
+  evpy_emit_event ((event_object *) continue_event_obj,
+                   inferior_thread->continue_event);
 }
 
 static PyTypeObject continue_event_object_type =
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index 8030bbb..5dab2ce 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -17,10 +17,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "defs.h"
-#include "command.h"
-#include "python-internal.h"
-#include "inferior.h"
+#include "py-event.h"
 
 event_object *
 create_event_object (const char *event_type)
@@ -84,6 +81,37 @@ gdbpy_initialize_event (void)
   PyModule_AddObject (gdb_module, "Event", (PyObject *) &event_object_type);
 }
 
+/* Notify the list of listens that the given EVENT has occured.  */
+
+void
+evpy_emit_event (event_object *event, eventregistry_object *registry)
+{
+  PyObject *callback_list;
+  PyObject *callback_list_copy;
+  PyObject *args_tuple;
+  Py_ssize_t i;
+
+  callback_list = (PyObject *) (registry->callbacks);
+
+  /* Create a copy of call back list and use that for
+     notifying listeners to avoid skipping callbacks
+     in the case of a callback being disconnected during
+     a notification.  */
+  callback_list_copy = copy_py_list (callback_list);
+  if (!callback_list_copy)
+    error(_("Cannot copy callback list."));
+
+  args_tuple = PyTuple_New ((Py_ssize_t) 1);
+  PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) event);
+
+  for (i = 0; i < PyList_Size (callback_list_copy); i++)
+    {
+      PyObject_CallObject (PyList_GET_ITEM (callback_list_copy, i), args_tuple);
+    }
+
+
+}
+
 static PyGetSetDef event_object_getset[] =
 {
   { "inferior_thread", evpy_get_inferior_thread, NULL, 
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
new file mode 100644
index 0000000..5f4e8bc
--- /dev/null
+++ b/gdb/python/py-event.h
@@ -0,0 +1,40 @@
+/* Python interface to inferior events.
+
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "command.h"
+#include "python-internal.h"
+#include "inferior.h"
+
+typedef struct
+{
+  PyObject_HEAD
+
+  thread_object *inferior_thread;
+  PyStringObject *event_type;
+} event_object;
+
+typedef struct
+{
+  event_object event;
+  PyStringObject *stop_reason;
+} stop_event_object;
+
+extern void evpy_emit_event (event_object *event,
+                             eventregistry_object *registry);
diff --git a/gdb/python/py-exitedevent.c b/gdb/python/py-exitedevent.c
index b0e8329..f56c7ed 100644
--- a/gdb/python/py-exitedevent.c
+++ b/gdb/python/py-exitedevent.c
@@ -17,10 +17,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "defs.h"
-#include "command.h"
-#include "python-internal.h"
-#include "inferior.h"
+#include "py-event.h"
 
 static PyTypeObject exited_event_object_type;
 
@@ -91,16 +88,8 @@ emit_exited_event (thread_object *inferior_thread, LONGEST *exit_code)
 
   exited_event_obj = create_exited_event_object (inferior_thread, exit_code);
 
-  callback_list = (PyObject *)
-(inferior_thread->exited_event->callbacks);
-
-  args_tuple = PyTuple_New ((Py_ssize_t) 1);
-  PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) exited_event_obj);
-
-  for (i = 0; i < PyList_Size (callback_list); i++)
-    {
-      PyObject_CallObject (PyList_GET_ITEM (callback_list, i), args_tuple);
-    }
+  evpy_emit_event ((event_object *) exited_event_obj,
+                   inferior_thread->exited_event);
 }
 
 static PyGetSetDef exited_event_object_getset[] =
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 69b4a01..8732e5e 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -236,8 +236,6 @@ thpy_is_exited (PyObject *self, PyObject *args)
   Py_RETURN_FALSE;
 }
 
-
-
 /* Implementation of gdb.selected_thread () -> gdb.InferiorThread.
    Returns the selected thread object.  */
 
diff --git a/gdb/python/py-signalstopevent.c b/gdb/python/py-signalstopevent.c
index cafff96..5a5994e 100644
--- a/gdb/python/py-signalstopevent.c
+++ b/gdb/python/py-signalstopevent.c
@@ -17,10 +17,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "defs.h"
-#include "command.h"
-#include "python-internal.h"
-#include "inferior.h"
+#include "py-event.h"
 
 static PyTypeObject signal_stop_event_object_type;
 
@@ -100,17 +97,8 @@ emit_signal_stop_event (const char *stop_signal)
 
   signal_stop_event_obj = create_signal_stop_event_object (stop_signal);
 
-  callback_list = (PyObject *)
-(inferior_thread->signal_stop_event->callbacks);
-
-  args_tuple = PyTuple_New ((Py_ssize_t) 1);
-  PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *)
-signal_stop_event_obj);
-
-  for (i = 0; i < PyList_Size (callback_list); i++)
-    {
-      PyObject_CallObject (PyList_GET_ITEM (callback_list, i), args_tuple);
-    }
+  evpy_emit_event ((event_object *) signal_stop_event_obj,
+                   inferior_thread->signal_stop_event);
 }
 
 static PyGetSetDef signal_stop_event_object_getset[] =
diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c
index a188992..ea3329b 100644
--- a/gdb/python/py-stopevent.c
+++ b/gdb/python/py-stopevent.c
@@ -17,10 +17,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "defs.h"
-#include "command.h"
-#include "python-internal.h"
-#include "inferior.h"
+#include "py-event.h"
 
 static void
 stop_evpy_dealloc (PyObject *self)
@@ -101,16 +98,8 @@ emit_stop_event (struct bpstats *bs, const char *stop_signal)
   if (!stop_event_obj)
     stop_event_obj = create_stop_event_object ("unknown");
 
-  callback_list = (PyObject *) (inferior_thread->stop_event->callbacks);
-
-  args_tuple = PyTuple_New ((Py_ssize_t) 1);
-  PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) stop_event_obj);
-
-  for (i = 0; i < PyList_Size (callback_list); i++)
-    {
-      PyObject_CallObject (PyList_GET_ITEM (callback_list, i), args_tuple);
-    }
-
+  evpy_emit_event ((event_object *) stop_event_obj,
+                   inferior_thread->stop_event);
 }
 
 static PyGetSetDef stop_event_object_getset[] =
diff --git a/gdb/python/py-stopevent.h b/gdb/python/py-stopevent.h
new file mode 100644
index 0000000..2f57a03
--- /dev/null
+++ b/gdb/python/py-stopevent.h
@@ -0,0 +1,23 @@
+/* Python interface to inferior stop events.
+
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "command.h"
+#include "python-internal.h"
+#include "inferior.h"
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index c308554..9c92c67 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -125,22 +125,6 @@ typedef struct
   PyObject *inf_obj;
 } thread_object;
 
-/* Used in python-event.c */
-typedef struct
-{
-  PyObject_HEAD
-
-  thread_object *inferior_thread;
-  PyStringObject *event_type;
-} event_object;
-
-/* Used in python-stopevent.c */
-typedef struct
-{
-  event_object event;
-  PyStringObject *stop_reason;
-} stop_event_object;
-
 extern struct cmd_list_element *set_python_list;
 extern struct cmd_list_element *show_python_list;
 
@@ -226,6 +210,8 @@ struct cleanup *make_cleanup_py_decref (PyObject *py);
 struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
 				   const struct language_defn *language);
 
+PyObject *copy_py_list (PyObject *list);
+
 extern struct gdbarch *python_gdbarch;
 extern const struct language_defn *python_language;
 
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 6e5c695..e444e7d 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -162,6 +162,23 @@ compute_python_string (struct command_line *l)
   return script;
 }
 
+/* Returns a a copy of the give LIST.
+   Creates a new reference which must be handeld by the caller.  */
+
+PyObject *
+copy_py_list (PyObject *list){
+  int i;
+
+  PyObject *new_list = PyList_New (0);
+  if (!new_list)
+    return NULL;
+
+  for (i = 0; i < PyList_Size (list); i++)
+    PyList_Append (new_list, PyList_GET_ITEM (list, i));
+
+  return new_list;
+}
+
 /* Take a command line structure representing a 'python' command, and
    evaluate its body using the Python interpreter.  */
 


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-07 16:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-07 16:58 [SCM] archer-swagiaal-oguz: Copy listeners list in emit function swagiaal

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).