From 6bd9264021e46b6d147afacd47a1991e0216979a Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 21 Feb 2008 16:51:07 +0000 Subject: [PATCH] (x_connection_closed): Consolidate identical tests. (x_delete_terminal): Don't crash if called via x_connection_closed. --- src/ChangeLog | 7 ++++++- src/xterm.c | 55 +++++++++++++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index e1b8d8a5cef..73e4f942a2e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,12 @@ +2008-02-21 Stefan Monnier + + * xterm.c (x_connection_closed): Consolidate identical tests. + (x_delete_terminal): Don't crash if called via x_connection_closed. + 2008-02-21 Kenichi Handa * xdisp.c (decode_mode_spec): New arg string. - (display_mode_element): Adjusted for the above change. + (display_mode_element): Adjust for the above change. 2008-02-19 Stefan Monnier diff --git a/src/xterm.c b/src/xterm.c index d9670fe4446..709be459b20 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -8103,25 +8103,23 @@ x_connection_closed (dpy, error_message) OpenWindows in certain situations. I suspect that is a bug in OpenWindows. I don't know how to circumvent it here. */ -#ifdef USE_X_TOOLKIT - /* If DPYINFO is null, this means we didn't open the display - in the first place, so don't try to close it. */ if (dpyinfo) { - extern void (*fatal_error_signal_hook) P_ ((void)); - fatal_error_signal_hook = x_fatal_error_signal; - XtCloseDisplay (dpy); - fatal_error_signal_hook = NULL; - } +#ifdef USE_X_TOOLKIT + /* If DPYINFO is null, this means we didn't open the display + in the first place, so don't try to close it. */ + { + extern void (*fatal_error_signal_hook) P_ ((void)); + fatal_error_signal_hook = x_fatal_error_signal; + XtCloseDisplay (dpy); + fatal_error_signal_hook = NULL; + } #endif #ifdef USE_GTK - if (dpyinfo) - xg_display_close (dpyinfo->display); + xg_display_close (dpyinfo->display); #endif - if (dpyinfo) - { /* Indicate that this display is dead. */ dpyinfo->display = 0; @@ -11834,30 +11832,35 @@ x_delete_terminal (struct terminal *terminal) return; BLOCK_INPUT; + /* If called from x_connection_closed, the display may already be closed + and dpyinfo->display was set to 0 to indicate that. */ + if (dpyinfo->display) + { #ifdef USE_FONT_BACKEND - if (enable_font_backend) - XFreeFont (dpyinfo->display, dpyinfo->font); - else + if (enable_font_backend) + XFreeFont (dpyinfo->display, dpyinfo->font); + else #endif - /* Free the fonts in the font table. */ - for (i = 0; i < dpyinfo->n_fonts; i++) - if (dpyinfo->font_table[i].name) - { - XFreeFont (dpyinfo->display, dpyinfo->font_table[i].font); - } + /* Free the fonts in the font table. */ + for (i = 0; i < dpyinfo->n_fonts; i++) + if (dpyinfo->font_table[i].name) + { + XFreeFont (dpyinfo->display, dpyinfo->font_table[i].font); + } - x_destroy_all_bitmaps (dpyinfo); - XSetCloseDownMode (dpyinfo->display, DestroyAll); + x_destroy_all_bitmaps (dpyinfo); + XSetCloseDownMode (dpyinfo->display, DestroyAll); #ifdef USE_GTK - xg_display_close (dpyinfo->display); + xg_display_close (dpyinfo->display); #else #ifdef USE_X_TOOLKIT - XtCloseDisplay (dpyinfo->display); + XtCloseDisplay (dpyinfo->display); #else - XCloseDisplay (dpyinfo->display); + XCloseDisplay (dpyinfo->display); #endif #endif /* ! USE_GTK */ + } x_delete_display (dpyinfo); UNBLOCK_INPUT; -- 2.39.2