diff src/xselect.c @ 83484:a380ca43a190

Merged from emacs@sv.gnu.org Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-128 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-129 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-130 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-131 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-132 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-133 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-134 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-135 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-43 Munge arch explicit ids in etc/images to match Emacs * emacs@sv.gnu.org/gnus--rel--5.10--patch-44 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-45 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-46 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-47 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-48 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-524
author Karoly Lorentey <lorentey@elte.hu>
date Sat, 04 Mar 2006 23:07:13 +0000
parents 8976b9f5eda1 b9ad41f39bf6
children 414faf8dce4e
line wrap: on
line diff
--- a/src/xselect.c	Tue Feb 28 17:35:08 2006 +0000
+++ b/src/xselect.c	Sat Mar 04 23:07:13 2006 +0000
@@ -55,6 +55,7 @@
 static Lisp_Object x_selection_request_lisp_error P_ ((Lisp_Object));
 static Lisp_Object queue_selection_requests_unwind P_ ((Lisp_Object));
 static Lisp_Object some_frame_on_display P_ ((struct x_display_info *));
+static Lisp_Object x_catch_errors_unwind P_ ((Lisp_Object));
 static void x_reply_selection_request P_ ((struct input_event *, int,
 					   unsigned char *, int, Atom));
 static int waiting_for_other_props_on_window P_ ((Display *, Window));
@@ -618,6 +619,15 @@
     x_decline_selection_request (x_selection_current_request);
   return Qnil;
 }
+
+static Lisp_Object
+x_catch_errors_unwind (dummy)
+     Lisp_Object dummy;
+{
+  BLOCK_INPUT;
+  x_uncatch_errors ();
+  UNBLOCK_INPUT;
+}
 
 
 /* This stuff is so that INCR selections are reentrant (that is, so we can
@@ -711,8 +721,11 @@
   if (reply.property == None)
     reply.property = reply.target;
 
-  /* #### XChangeProperty can generate BadAlloc, and we must handle it! */
   BLOCK_INPUT;
+  /* The protected block contains wait_for_property_change, which can
+     run random lisp code (process handlers) or signal.  Therefore, we
+     put the x_uncatch_errors call in an unwind.  */
+  record_unwind_protect (x_catch_errors_unwind, Qnil);
   x_catch_errors (display);
 
 #ifdef TRACE_SELECTION
@@ -866,9 +879,8 @@
      UNBLOCK to enter the event loop and get possible errors delivered,
      and then BLOCK again because x_uncatch_errors requires it.  */
   BLOCK_INPUT;
-
+  /* This calls x_uncatch_errors.  */
   unbind_to (count, Qnil);
-  x_uncatch_errors ();
   UNBLOCK_INPUT;
 }
 
@@ -1378,7 +1390,7 @@
   Atom selection_atom;
   Atom type_atom;
   int secs, usecs;
-  int count;
+  int count = SPECPDL_INDEX ();
   Lisp_Object frame;
 
   if (! FRAME_X_P (sf))
@@ -1409,6 +1421,10 @@
 
   BLOCK_INPUT;
 
+  /* The protected block contains wait_reading_process_output, which
+     can run random lisp code (process handlers) or signal.
+     Therefore, we put the x_uncatch_errors call in an unwind.  */
+  record_unwind_protect (x_catch_errors_unwind, Qnil);
   x_catch_errors (display);
 
   TRACE2 ("Get selection %s, type %s",
@@ -1426,8 +1442,6 @@
 
   frame = some_frame_on_display (dpyinfo);
 
-  count = SPECPDL_INDEX ();
-
   /* If the display no longer has frames, we can't expect
      to get many more selection requests from it, so don't
      bother trying to queue them.  */
@@ -1449,9 +1463,10 @@
   TRACE1 ("  Got event = %d", !NILP (XCAR (reading_selection_reply)));
 
   BLOCK_INPUT;
+  if (x_had_errors_p (display))
+    error ("Cannot get selection");
+  /* This calls x_uncatch_errors.  */
   unbind_to (count, Qnil);
-  x_check_errors (display, "Cannot get selection: %s");
-  x_uncatch_errors ();
   UNBLOCK_INPUT;
 
   if (NILP (XCAR (reading_selection_reply)))
@@ -2687,6 +2702,7 @@
   Lisp_Object ret = Qnil;
   Display *dpy = FRAME_X_DISPLAY (f);
   Atom atom;
+  int had_errors;
 
   if (INTEGERP (value))
     atom = (Atom) XUINT (value);
@@ -2699,14 +2715,13 @@
 
   BLOCK_INPUT;
   x_catch_errors (dpy);
-
   name = atom ? XGetAtomName (dpy, atom) : "";
-
-  if (! x_had_errors_p (dpy))
+  had_errors = x_had_errors_p (dpy);
+  x_uncatch_errors ();
+
+  if (!had_errors)
     ret = make_string (name, strlen (name));
 
-  x_uncatch_errors ();
-
   if (atom && name) XFree (name);
   if (NILP (ret)) ret = make_string ("", 0);