A while ago I applied a patch that avoided calling certain X code when the
corresponding XEmacs device was being deleted. At the time my impression was
that the X code in general called ABORT() in contexts where it should rather
check if any frames exist on other devices, and delete the X device and
throw to top level if so.
That’s not true. The X code, while filled with calls to ABORT(), only calls
it in truly exceptional conditions, that indicate programming errors
somewhere, the sort of place where an assertion would be a better choice
since the check can be turned off in a production build. This patch changes
them to assertions; I’d especially like any commentary on it from Jerry,
since you’ve been looking at this code in detail recently.
src/ChangeLog addition:
2006-06-25 Aidan Kehoe <kehoea(a)parhasard.net>
* event-Xt.c (x_event_to_emacs_event):
Fix my spelling.
* device-x.c (get_device_from_display):
* device-x.c (x_get_visual_depth):
* event-Xt.c (Xt_process_to_emacs_event):
* frame-x.c (x_wm_mark_shell_size_user_specified):
* frame-x.c (x_wm_mark_shell_position_user_specified):
* frame-x.c (x_wm_set_shell_iconic_p):
* frame-x.c (x_wm_set_cell_size):
* frame-x.c (x_wm_set_variable_size):
* frame-x.c (x_wm_store_class_hints):
* frame-x.c (x_wm_maybe_store_wm_command):
* frame-x.c (x_initialize_frame_size):
* glyphs-x.c (extract_xpm_color_names):
* menubar-x.c (set_frame_menubar):
* scrollbar-x.c (x_update_scrollbar_instance_status):
* xgccache.c (gc_cache_lookup):
Change various checks followed by ABORT() to assertions instead,
since they are, semantically, checks of conditions that will only
fail in the event of a bug or a ridiculously exceptional
condition.
XEmacs Trunk source patch:
Diff command: cvs -q diff -u
Files affected: src/xgccache.c src/scrollbar-x.c src/menubar-x.c src/glyphs-x.c src/frame-x.c src/event-Xt.c src/device-x.c
Index: src/device-x.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/device-x.c,v
retrieving revision 1.67
diff -u -u -r1.67 device-x.c
--- src/device-x.c 2006/06/21 17:30:35 1.67
+++ src/device-x.c 2006/06/25 10:13:08
@@ -152,24 +152,8 @@
{
struct device *d = get_device_from_display_1 (dpy);
-#if !defined(INFODOCK)
-# define FALLBACK_RESOURCE_NAME "xemacs"
-# else
-# define FALLBACK_RESOURCE_NAME "infodock"
-#endif
-
- if (!d)
- {
- /* This isn't one of our displays. Let's crash? */
- stderr_out
- ("\n%s: Fatal X Condition. Asked about display we don't own: \"%s\"\n",
- (STRINGP (Vinvocation_name) ?
- (char *) XSTRING_DATA (Vinvocation_name) : FALLBACK_RESOURCE_NAME),
- DisplayString (dpy) ? DisplayString (dpy) : "???");
- ABORT();
- }
-
-#undef FALLBACK_RESOURCE_NAME
+ /* This needs to be one of our displays. */
+ assert(d);
return d;
}
@@ -469,7 +453,8 @@
vi_in.visualid = XVisualIDFromVisual (visual);
vi_out = XGetVisualInfo (dpy, /*VisualScreenMask|*/VisualIDMask,
&vi_in, &out_count);
- if (! vi_out) ABORT ();
+ assert(vi_out);
+
d = vi_out [0].depth;
XFree ((char *) vi_out);
return d;
Index: src/event-Xt.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/event-Xt.c,v
retrieving revision 1.91
diff -u -u -r1.91 event-Xt.c
--- src/event-Xt.c 2005/12/24 19:54:01 1.91
+++ src/event-Xt.c 2006/06/25 10:13:10
@@ -1122,7 +1122,7 @@
This _might_ be possible within an XKB framework, changing
the keyboard to a US XKB layout for a moment at startup,
- storing the correspondance, and changing it back. But that
+ storing the correspondence, and changing it back. But that
won't work on non-XKB servers, it makes our already slow
startup slower, and it's not clear that it's really any
easier or more maintainable than storing a correspondence in
@@ -2419,7 +2419,8 @@
return;
}
}
- ABORT ();
+
+ assert (0);
}
static void
Index: src/frame-x.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/frame-x.c,v
retrieving revision 1.75
diff -u -u -r1.75 frame-x.c
--- src/frame-x.c 2006/06/19 18:49:23 1.75
+++ src/frame-x.c 2006/06/25 10:13:11
@@ -230,14 +230,14 @@
void
x_wm_mark_shell_size_user_specified (Widget wmshell)
{
- if (! XtIsWMShell (wmshell)) ABORT ();
+ assert (XtIsWMShell (wmshell));
EmacsShellSetSizeUserSpecified (wmshell);
}
void
x_wm_mark_shell_position_user_specified (Widget wmshell)
{
- if (! XtIsWMShell (wmshell)) ABORT ();
+ assert (XtIsWMShell (wmshell));
EmacsShellSetPositionUserSpecified (wmshell);
}
@@ -246,7 +246,7 @@
void
x_wm_set_shell_iconic_p (Widget shell, int iconic_p)
{
- if (! XtIsWMShell (shell)) ABORT ();
+ assert (XtIsWMShell (shell));
/* Because of questionable logic in Shell.c, this sequence can't work:
@@ -275,10 +275,8 @@
{
Arg al [2];
- if (!XtIsWMShell (wmshell))
- ABORT ();
- if (cw <= 0 || ch <= 0)
- ABORT ();
+ assert (XtIsWMShell (wmshell));
+ assert (!(cw <= 0 || ch <= 0));
XtSetArg (al[0], XtNwidthInc, cw);
XtSetArg (al[1], XtNheightInc, ch);
@@ -290,8 +288,8 @@
{
Arg al [2];
- if (!XtIsWMShell (wmshell))
- ABORT ();
+ assert (XtIsWMShell (wmshell));
+
#ifdef DEBUG_GEOMETRY_MANAGEMENT
/* See comment in EmacsShell.c */
printf ("x_wm_set_variable_size: %d %d\n", width, height);
@@ -359,8 +357,7 @@
Extbyte *app_name, *app_class;
XClassHint classhint;
- if (!XtIsWMShell (shell))
- ABORT ();
+ assert (XtIsWMShell (shell));
XtGetApplicationNameAndClass (dpy, &app_name, &app_class);
classhint.res_name = frame_name;
@@ -376,8 +373,7 @@
Widget w = FRAME_X_SHELL_WIDGET (f);
struct device *d = XDEVICE (FRAME_DEVICE (f));
- if (!XtIsWMShell (w))
- ABORT ();
+ assert (XtIsWMShell (w));
if (NILP (DEVICE_X_WM_COMMAND_FRAME (d)))
{
@@ -1573,8 +1569,7 @@
/* OK, we're a top-level shell. */
- if (!XtIsWMShell (wmshell))
- ABORT ();
+ assert (XtIsWMShell (wmshell));
/* If the EmacsFrame doesn't have a geometry but the shell does,
treat that as the geometry of the frame.
Index: src/glyphs-x.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/glyphs-x.c,v
retrieving revision 1.84
diff -u -u -r1.84 glyphs-x.c
--- src/glyphs-x.c 2005/11/26 11:46:08 1.84
+++ src/glyphs-x.c 2006/06/25 10:13:13
@@ -1328,10 +1328,13 @@
{
Lisp_Object cons = XCAR (results);
color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
+ Status alloced;
/* Duplicate the pixel value so that we still have a lock on it if
the pixel we were passed is later freed. */
- if (! XAllocColor (dpy, cmap, &color))
- ABORT (); /* it must be allocable since we're just duplicating it */
+
+ alloced = XAllocColor (dpy, cmap, &color);
+ assert (alloced); /* it must be allocable since we're just
+ duplicating it */
TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (cons), C_STRING_MALLOC,
symbols[i].name, Qctext);
Index: src/menubar-x.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/menubar-x.c,v
retrieving revision 1.46
diff -u -u -r1.46 menubar-x.c
--- src/menubar-x.c 2005/10/25 11:16:26 1.46
+++ src/menubar-x.c 2006/06/25 10:13:13
@@ -575,8 +575,8 @@
menubar_visible = !NILP (w->menubar_visible_p);
data = compute_menubar_data (f, menubar, deep_p);
- if (!data || (!data->next && !data->contents))
- ABORT ();
+
+ assert (!(!data || (!data->next && !data->contents)));
if (!FRAME_X_MENUBAR_ID (f))
FRAME_X_MENUBAR_ID (f) = new_lwlib_id ();
Index: src/scrollbar-x.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/scrollbar-x.c,v
retrieving revision 1.32
diff -u -u -r1.32 scrollbar-x.c
--- src/scrollbar-x.c 2006/06/19 18:19:38 1.32
+++ src/scrollbar-x.c 2006/06/25 10:13:13
@@ -283,7 +283,7 @@
}
}
- if (!wv->scrollbar_data) ABORT ();
+ assert (wv->scrollbar_data);
free_widget_value_tree (wv);
}
else if (managed)
Index: src/xgccache.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/xgccache.c,v
retrieving revision 1.14
diff -u -u -r1.14 xgccache.c
--- src/xgccache.c 2006/02/17 11:19:19 1.14
+++ src/xgccache.c 2006/06/25 10:13:13
@@ -162,8 +162,8 @@
(void) describe_gc_cache (cache, DGCCFLAG_DISABLE);
#endif
- if ((!!cache->head) != (!!cache->tail)) ABORT ();
- if (cache->head && (cache->head->prev || cache->tail->next)) ABORT ();
+ assert ((!!cache->head) == (!!cache->tail));
+ assert(!((cache->head && (cache->head->prev || cache->tail->next))));
gcvm.mask = mask;
gcvm.gcv = *gcv; /* this copies... */
@@ -215,10 +215,12 @@
cell->prev = cache->tail;
cache->tail->next = cell;
cache->tail = cell;
- if (cache->head == cell) ABORT ();
- if (cell->next) ABORT ();
- if (cache->head->prev) ABORT ();
- if (cache->tail->next) ABORT ();
+
+ assert (cache->head != cell);
+ assert (!(cell->next));
+ assert (!(cache->head->prev));
+ assert (!(cache->tail->next));
+
return cell->gc;
}
@@ -242,10 +244,10 @@
remhash (&cell->gcvm, cache->table);
#endif
}
- else if (cache->size > GC_CACHE_SIZE)
- ABORT ();
else
{
+ assert (!(cache->size > GC_CACHE_SIZE));
+
/* Allocate a new cell (don't put it in the list or table yet). */
cell = xnew (struct gc_cache_cell);
cache->size++;
--
Santa Maradona, priez pour moi!