diff src/xterm.c @ 83483:8976b9f5eda1

Merged from emacs@sv.gnu.org Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-120 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-121 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-122 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-123 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-124 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-125 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-126 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-127 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-40 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-41 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-42 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-523
author Karoly Lorentey <lorentey@elte.hu>
date Tue, 28 Feb 2006 17:35:08 +0000
parents d08a7ef0cb8a fdee8318ddc9
children 0cdee8b991e1
line wrap: on
line diff
--- a/src/xterm.c	Sat Feb 25 01:07:18 2006 +0000
+++ b/src/xterm.c	Tue Feb 28 17:35:08 2006 +0000
@@ -327,8 +327,8 @@
 void x_delete_display P_ ((struct x_display_info *));
 
 static int x_io_error_quitter P_ ((Display *));
-int x_catch_errors P_ ((Display *));
-void x_uncatch_errors P_ ((Display *, int));
+void x_catch_errors P_ ((Display *));
+void x_uncatch_errors P_ ((void));
 void x_lower_frame P_ ((struct frame *));
 void x_scroll_bar_clear P_ ((struct frame *));
 int x_had_errors_p P_ ((Display *));
@@ -3726,7 +3726,6 @@
 	Window win, child;
 	int win_x, win_y;
 	int parent_x = 0, parent_y = 0;
-	int count;
 
 	win = root;
 
@@ -3734,7 +3733,7 @@
 	   structure is changing at the same time this function
 	   is running.  So at least we must not crash from them.  */
 
-	count = x_catch_errors (FRAME_X_DISPLAY (*fp));
+	x_catch_errors (FRAME_X_DISPLAY (*fp));
 
 	if (FRAME_X_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame
 	    && FRAME_LIVE_P (last_mouse_frame))
@@ -3803,7 +3802,7 @@
 	if (x_had_errors_p (FRAME_X_DISPLAY (*fp)))
 	  f1 = 0;
 
-	x_uncatch_errors (FRAME_X_DISPLAY (*fp), count);
+	x_uncatch_errors ();
 
 	/* If not, is it one of our scroll bars?  */
 	if (! f1)
@@ -5726,7 +5725,7 @@
                     Display *d = event.xclient.display;
                     /* Catch and ignore errors, in case window has been
                        iconified by a window manager such as GWM.  */
-                    int count = x_catch_errors (d);
+                    x_catch_errors (d);
                     XSetInputFocus (d, event.xclient.window,
                                     /* The ICCCM says this is
                                        the only valid choice.  */
@@ -5735,7 +5734,7 @@
                     /* This is needed to detect the error
                        if there is an error.  */
                     XSync (d, False);
-                    x_uncatch_errors (d, count);
+                    x_uncatch_errors ();
                   }
                 /* Not certain about handling scroll bars here */
 #endif /* 0 */
@@ -7483,7 +7482,11 @@
 #define X_ERROR_MESSAGE_SIZE 200
 
 /* If non-nil, this should be a string.
-   It means catch X errors  and store the error message in this string.  */
+   It means catch X errors  and store the error message in this string.
+
+   The reason we use a stack is that x_catch_error/x_uncatch_error can
+   be called from a signal handler.
+*/
 
 struct x_error_message_stack {
   char string[X_ERROR_MESSAGE_SIZE];
@@ -7520,20 +7523,12 @@
    Calling x_uncatch_errors resumes the normal error handling.  */
 
 void x_check_errors ();
-static Lisp_Object x_catch_errors_unwind ();
-
-int
+
+void
 x_catch_errors (dpy)
      Display *dpy;
 {
-  int count = SPECPDL_INDEX ();
   struct x_error_message_stack *data = xmalloc (sizeof (*data));
-  Lisp_Object dummy;
-#ifdef ENABLE_CHECKING
-  dummy = make_number ((EMACS_INT)dpy + (EMACS_INT)x_error_message);
-#else
-  dummy = Qnil;
-#endif
 
   /* Make sure any errors from previous requests have been dealt with.  */
   XSync (dpy, False);
@@ -7542,43 +7537,28 @@
   data->string[0] = 0;
   data->prev = x_error_message;
   x_error_message = data;
-
-  record_unwind_protect (x_catch_errors_unwind, dummy);
-
-  return count;
-}
-
-/* Unbind the binding that we made to check for X errors.  */
-
-static Lisp_Object
-x_catch_errors_unwind (dummy)
-     Lisp_Object dummy;
-{
-  Display *dpy;
+}
+
+/* Undo the last x_catch_errors call.
+   DPY should be the display that was passed to x_catch_errors.  */
+
+void
+x_uncatch_errors ()
+{
   struct x_error_message_stack *tmp;
 
-  if (!x_error_message)
-    abort ();
-
-  dpy = x_error_message->dpy;
-
   /* The display may have been closed before this function is called.
      Check if it is still open before calling XSync.  */
-  if (x_display_info_for_display (dpy) != 0)
+  if (x_display_info_for_display (x_error_message->dpy) != 0)
     {
       BLOCK_INPUT;
-      XSync (dpy, False);
+      XSync (x_error_message->dpy, False);
       UNBLOCK_INPUT;
     }
 
   tmp = x_error_message;
   x_error_message = x_error_message->prev;
-  free (tmp);
-
-  eassert (EQ (dummy,
-	       make_number ((EMACS_INT)dpy + (EMACS_INT)x_error_message)));
-
-  return Qnil;
+  xfree (tmp);
 }
 
 /* If any X protocol errors have arrived since the last call to
@@ -7594,7 +7574,12 @@
   XSync (dpy, False);
 
   if (x_error_message->string[0])
-    error (format, x_error_message->string);
+    {
+      char string[X_ERROR_MESSAGE_SIZE];
+      bcopy (x_error_message->string, string, X_ERROR_MESSAGE_SIZE);
+      x_uncatch_errors ();
+      error (format, string);
+    }
 }
 
 /* Nonzero if we had any X protocol errors
@@ -7619,19 +7604,6 @@
   x_error_message->string[0] = 0;
 }
 
-/* Stop catching X protocol errors and let them make Emacs die.
-   DPY should be the display that was passed to x_catch_errors.
-   COUNT should be the value that was returned by
-   the corresponding call to x_catch_errors.  */
-
-void
-x_uncatch_errors (dpy, count)
-     Display *dpy;
-     int count;
-{
-  unbind_to (count, Qnil);
-}
-
 #if 0
 static unsigned int x_wire_count;
 x_trace_wire ()
@@ -7688,7 +7660,6 @@
 {
   struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
   Lisp_Object frame, tail;
-  int count;
   int index = SPECPDL_INDEX ();
 
   error_msg = (char *) alloca (strlen (error_message) + 1);
@@ -7699,7 +7670,7 @@
      below.  Otherwise, we might end up with printing ``can't find per
      display information'' in the recursive call instead of printing
      the original message here.  */
-  count = x_catch_errors (dpy);
+  x_catch_errors (dpy);
 
   /* Inhibit redisplay while frames are being deleted. */
   specbind (Qinhibit_redisplay, Qt);
@@ -7785,7 +7756,7 @@
       x_delete_display (dpyinfo);
     }
 
-  x_uncatch_errors (dpy, count);
+  x_uncatch_errors ();
 
   if (terminal_list == 0)
     {
@@ -9393,7 +9364,6 @@
     = f ? FRAME_X_DISPLAY_INFO (f) : x_display_list;
   Display *dpy = dpyinfo->display;
   int try_XLoadQueryFont = 0;
-  int count;
   int allow_auto_scaled_font = 0;
 
   if (size < 0)
@@ -9433,7 +9403,7 @@
       /* At first, put PATTERN in the cache.  */
 
       BLOCK_INPUT;
-      count = x_catch_errors (dpy);
+      x_catch_errors (dpy);
 
       if (try_XLoadQueryFont)
 	{
@@ -9514,7 +9484,7 @@
 	    }
 	}
 
-      x_uncatch_errors (dpy, count);
+      x_uncatch_errors ();
       UNBLOCK_INPUT;
 
       if (names)
@@ -9605,7 +9575,7 @@
 	      XFontStruct *thisinfo;
 
 	      BLOCK_INPUT;
-	      count = x_catch_errors (dpy);
+	      x_catch_errors (dpy);
 	      thisinfo = XLoadQueryFont (dpy,
 					 SDATA (XCAR (tem)));
 	      if (x_had_errors_p (dpy))
@@ -9615,7 +9585,7 @@
 		  thisinfo = NULL;
 		  x_clear_errors (dpy);
 		}
-	      x_uncatch_errors (dpy, count);
+	      x_uncatch_errors ();
 	      UNBLOCK_INPUT;
 
 	      if (thisinfo)
@@ -9771,7 +9741,6 @@
 {
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
   Lisp_Object font_names;
-  int count;
 
   /* Get a list of all the fonts that match this name.  Once we
      have a list of matching fonts, we compare them against the fonts
@@ -9810,7 +9779,7 @@
       fontname = (char *) SDATA (XCAR (font_names));
 
     BLOCK_INPUT;
-    count = x_catch_errors (FRAME_X_DISPLAY (f));
+    x_catch_errors (FRAME_X_DISPLAY (f));
     font = (XFontStruct *) XLoadQueryFont (FRAME_X_DISPLAY (f), fontname);
     if (x_had_errors_p (FRAME_X_DISPLAY (f)))
       {
@@ -9819,7 +9788,7 @@
 	font = NULL;
 	x_clear_errors (FRAME_X_DISPLAY (f));
       }
-    x_uncatch_errors (FRAME_X_DISPLAY (f), count);
+    x_uncatch_errors ();
     UNBLOCK_INPUT;
     if (!font)
       return NULL;
@@ -10612,7 +10581,6 @@
     Display *dpy = dpyinfo->display;
     XrmValue d, fr, to;
     Font font;
-    int count;
 
     d.addr = (XPointer)&dpy;
     d.size = sizeof (Display *);
@@ -10620,12 +10588,12 @@
     fr.size = sizeof (XtDefaultFont);
     to.size = sizeof (Font *);
     to.addr = (XPointer)&font;
-    count = x_catch_errors (dpy);
+    x_catch_errors (dpy);
     if (!XtCallConverter (dpy, XtCvtStringToFont, &d, 1, &fr, &to, NULL))
       abort ();
     if (x_had_errors_p (dpy) || !XQueryFont (dpy, font))
       XrmPutLineResource (&xrdb, "Emacs.dialog.*.font: 9x15");
-    x_uncatch_errors (dpy, count);
+    x_uncatch_errors ();
   }
 #endif
 #endif