diff options
Diffstat (limited to 'src/xterm.c')
| -rw-r--r-- | src/xterm.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/xterm.c b/src/xterm.c index f52ff6133fe..0d1ea7636f2 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* X Communication module for terminals which understand the X protocol. | 1 | /* X Communication module for terminals which understand the X protocol. |
| 2 | Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, | 2 | Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
| 3 | 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | 3 | 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| 6 | 6 | ||
| @@ -7438,7 +7438,12 @@ x_text_icon (f, icon_name) | |||
| 7438 | /* If non-nil, this should be a string. | 7438 | /* If non-nil, this should be a string. |
| 7439 | It means catch X errors and store the error message in this string. */ | 7439 | It means catch X errors and store the error message in this string. */ |
| 7440 | 7440 | ||
| 7441 | static Lisp_Object x_error_message_string; | 7441 | struct x_error_message_stack { |
| 7442 | char string[X_ERROR_MESSAGE_SIZE]; | ||
| 7443 | Display *dpy; | ||
| 7444 | struct x_error_message_stack *prev; | ||
| 7445 | }; | ||
| 7446 | static struct x_error_message_stack *x_error_message; | ||
| 7442 | 7447 | ||
| 7443 | /* An X error handler which stores the error message in | 7448 | /* An X error handler which stores the error message in |
| 7444 | x_error_message_string. This is called from x_error_handler if | 7449 | x_error_message_string. This is called from x_error_handler if |
| @@ -7450,7 +7455,7 @@ x_error_catcher (display, error) | |||
| 7450 | XErrorEvent *error; | 7455 | XErrorEvent *error; |
| 7451 | { | 7456 | { |
| 7452 | XGetErrorText (display, error->error_code, | 7457 | XGetErrorText (display, error->error_code, |
| 7453 | SDATA (x_error_message_string), | 7458 | x_error_message->string, |
| 7454 | X_ERROR_MESSAGE_SIZE); | 7459 | X_ERROR_MESSAGE_SIZE); |
| 7455 | } | 7460 | } |
| 7456 | 7461 | ||
| @@ -7475,16 +7480,23 @@ x_catch_errors (dpy) | |||
| 7475 | Display *dpy; | 7480 | Display *dpy; |
| 7476 | { | 7481 | { |
| 7477 | int count = SPECPDL_INDEX (); | 7482 | int count = SPECPDL_INDEX (); |
| 7483 | struct x_error_message_stack *data = malloc (sizeof (*data)); | ||
| 7484 | Lisp_Object dummy; | ||
| 7485 | #ifdef ENABLE_CHECKING | ||
| 7486 | dummy = make_number ((EMACS_INT)dpy + (EMACS_INT)x_error_message); | ||
| 7487 | #else | ||
| 7488 | dummy = Qnil; | ||
| 7489 | #endif | ||
| 7478 | 7490 | ||
| 7479 | /* Make sure any errors from previous requests have been dealt with. */ | 7491 | /* Make sure any errors from previous requests have been dealt with. */ |
| 7480 | XSync (dpy, False); | 7492 | XSync (dpy, False); |
| 7481 | 7493 | ||
| 7482 | record_unwind_protect (x_catch_errors_unwind, | 7494 | data->dpy = dpy; |
| 7483 | Fcons (make_save_value (dpy, 0), | 7495 | data->string[0] = 0; |
| 7484 | x_error_message_string)); | 7496 | data->prev = x_error_message; |
| 7497 | x_error_message = data; | ||
| 7485 | 7498 | ||
| 7486 | x_error_message_string = make_uninit_string (X_ERROR_MESSAGE_SIZE); | 7499 | record_unwind_protect (x_catch_errors_unwind, dummy); |
| 7487 | SSET (x_error_message_string, 0, 0); | ||
| 7488 | 7500 | ||
| 7489 | return count; | 7501 | return count; |
| 7490 | } | 7502 | } |
| @@ -7492,11 +7504,11 @@ x_catch_errors (dpy) | |||
| 7492 | /* Unbind the binding that we made to check for X errors. */ | 7504 | /* Unbind the binding that we made to check for X errors. */ |
| 7493 | 7505 | ||
| 7494 | static Lisp_Object | 7506 | static Lisp_Object |
| 7495 | x_catch_errors_unwind (old_val) | 7507 | x_catch_errors_unwind (dummy) |
| 7496 | Lisp_Object old_val; | 7508 | Lisp_Object dummy; |
| 7497 | { | 7509 | { |
| 7498 | Lisp_Object first = XCAR (old_val); | 7510 | Display *dpy = x_error_message->dpy; |
| 7499 | Display *dpy = XSAVE_VALUE (first)->pointer; | 7511 | struct x_error_message_stack *tmp; |
| 7500 | 7512 | ||
| 7501 | /* The display may have been closed before this function is called. | 7513 | /* The display may have been closed before this function is called. |
| 7502 | Check if it is still open before calling XSync. */ | 7514 | Check if it is still open before calling XSync. */ |
| @@ -7507,7 +7519,13 @@ x_catch_errors_unwind (old_val) | |||
| 7507 | UNBLOCK_INPUT; | 7519 | UNBLOCK_INPUT; |
| 7508 | } | 7520 | } |
| 7509 | 7521 | ||
| 7510 | x_error_message_string = XCDR (old_val); | 7522 | tmp = x_error_message; |
| 7523 | x_error_message = x_error_message->prev; | ||
| 7524 | free (tmp); | ||
| 7525 | |||
| 7526 | eassert (EQ (dummy, | ||
| 7527 | make_number ((EMACS_INT)dpy + (EMACS_INT)x_error_message))); | ||
| 7528 | |||
| 7511 | return Qnil; | 7529 | return Qnil; |
| 7512 | } | 7530 | } |
| 7513 | 7531 | ||
| @@ -7523,8 +7541,8 @@ x_check_errors (dpy, format) | |||
| 7523 | /* Make sure to catch any errors incurred so far. */ | 7541 | /* Make sure to catch any errors incurred so far. */ |
| 7524 | XSync (dpy, False); | 7542 | XSync (dpy, False); |
| 7525 | 7543 | ||
| 7526 | if (SREF (x_error_message_string, 0)) | 7544 | if (x_error_message->string[0]) |
| 7527 | error (format, SDATA (x_error_message_string)); | 7545 | error (format, x_error_message->string); |
| 7528 | } | 7546 | } |
| 7529 | 7547 | ||
| 7530 | /* Nonzero if we had any X protocol errors | 7548 | /* Nonzero if we had any X protocol errors |
| @@ -7537,7 +7555,7 @@ x_had_errors_p (dpy) | |||
| 7537 | /* Make sure to catch any errors incurred so far. */ | 7555 | /* Make sure to catch any errors incurred so far. */ |
| 7538 | XSync (dpy, False); | 7556 | XSync (dpy, False); |
| 7539 | 7557 | ||
| 7540 | return SREF (x_error_message_string, 0) != 0; | 7558 | return x_error_message->string[0] != 0; |
| 7541 | } | 7559 | } |
| 7542 | 7560 | ||
| 7543 | /* Forget about any errors we have had, since we did x_catch_errors on DPY. */ | 7561 | /* Forget about any errors we have had, since we did x_catch_errors on DPY. */ |
| @@ -7546,7 +7564,7 @@ void | |||
| 7546 | x_clear_errors (dpy) | 7564 | x_clear_errors (dpy) |
| 7547 | Display *dpy; | 7565 | Display *dpy; |
| 7548 | { | 7566 | { |
| 7549 | SSET (x_error_message_string, 0, 0); | 7567 | x_error_message->string[0] = 0; |
| 7550 | } | 7568 | } |
| 7551 | 7569 | ||
| 7552 | /* Stop catching X protocol errors and let them make Emacs die. | 7570 | /* Stop catching X protocol errors and let them make Emacs die. |
| @@ -7728,7 +7746,7 @@ x_error_handler (display, error) | |||
| 7728 | Display *display; | 7746 | Display *display; |
| 7729 | XErrorEvent *error; | 7747 | XErrorEvent *error; |
| 7730 | { | 7748 | { |
| 7731 | if (! NILP (x_error_message_string)) | 7749 | if (x_error_message) |
| 7732 | x_error_catcher (display, error); | 7750 | x_error_catcher (display, error); |
| 7733 | else | 7751 | else |
| 7734 | x_error_quitter (display, error); | 7752 | x_error_quitter (display, error); |
| @@ -10970,8 +10988,7 @@ x_initialize () | |||
| 10970 | void | 10988 | void |
| 10971 | syms_of_xterm () | 10989 | syms_of_xterm () |
| 10972 | { | 10990 | { |
| 10973 | staticpro (&x_error_message_string); | 10991 | x_error_message = NULL; |
| 10974 | x_error_message_string = Qnil; | ||
| 10975 | 10992 | ||
| 10976 | staticpro (&x_display_name_list); | 10993 | staticpro (&x_display_name_list); |
| 10977 | x_display_name_list = Qnil; | 10994 | x_display_name_list = Qnil; |