Ar an t-aonú lá is triochad de mí na Nollaig, scríobh Aidan Kehoe:
Ar an t-ochtú lá is fiche de mí na Nollaig, scríobh Jerry James:
> [...] This is causing the following practical problem. With an X11 build
> and Debug on Signal active, clicking on the menubar causes an immediate
> crash due to an assertion failure. A little debugger work shows the
> following sequence. Inside of button_item_to_widget_value (src/gui-x.c),
> the default-menubar from lisp/menubar-items.el is evaluated, down to one
> of the calls to:
>
> (truncate-string-to-width (abbrev-string-to-be-defined nil) 40 nil nil t)
>
> The abbrev-string-to-be-defined call returns "j.\n\n" (which doesn't
> seem right; where did that come from?).
That’s mostly OK, #'abbrev-string-to-be-defined just looks at the word at
point, and that’s the string in question. Though maybe it shouldn’t be
looking at the word at point.
> Evaluating
> truncate-string-to-width triggers the args_out_of_range, thereby
> unwinding the stack up to the call_trapping_problems call in
> menu_item_descriptor_to_widget_value (menubar-x.c). Since retval is
> unbound, this function returns NULL, and therefore
> compute_menubar_data also returns NULL. This triggers the assert() in
> set_frame_menubar (menubar-x.c) just after the call to
> compute_menubar_data and *boom* goes XEmacs.
This is interesting, and what to do isn’t particularly clear.
(setq debug-on-signal t) is supposed to enter the debugger even if the
signal is caught, so in design terms nothing is wrong here. Except that we
crash, and that’s clearly wrong ...
It *is* a bit of an infelicity in the implementation of
#'truncate-string-to-width that it signals as a matter of course, so this
patch is probably appropriate anyway. But should call_trapping_problems()
just bind Vdebug_on_signal to a non-nil value?
Thinking about this a bit more--
-- call_trapping_problems() shouldn’t bind debug-on-signal to a non-nil
value, that makes debug-on-signal less useful.
-- Since we’ve decided it’s the responsibility of Lisp to create menu items,
it is permitted behaviour--it shouldn’t trigger an assertion failure--for
that Lisp code to error. The C code should make sure the menu isn’t in a
wedged state, and then treat it as it does other Lisp errors.
-- Independent of this, #'truncate-string-to-width shouldn’t signal
args-out-of-range errors, as a UI thing it makes debug-on-signal much less
useful given that #'truncate-string-to-width is called so often from the
menu code (and was always intended to be called often from the menu code).
I’ve committed the below to address this.
APPROVE COMMIT
NOTE: This patch has been committed.
# HG changeset patch
# User Aidan Kehoe <kehoea(a)parhasard.net>
# Date 1336842733 -3600
# Node ID 8593e614573a4a167af4d3e73201dfa46c7e30a8
# Parent 00fd55d635fb2db4fb3b4647b1380769536f921c
Avoid signalling args-out-of-range errors, #'truncate-string-to-width
lisp/ChangeLog addition:
Avoid args-out-of-range errors, this function is regularly called
from menu code and with debug-on-signal non-nil, this can be very
irritating.
Don't bind ellipsis-len, we don't use it.
diff -r 00fd55d635fb -r 8593e614573a lisp/ChangeLog
--- a/lisp/ChangeLog Sat May 12 17:51:05 2012 +0100
+++ b/lisp/ChangeLog Sat May 12 18:12:13 2012 +0100
@@ -3,6 +3,10 @@
* subr.el:
* subr.el (truncate-string-to-width):
Sync with GNU's version, use its test suite in mule-tests.el.
+ Avoid args-out-of-range errors, this function is regularly called
+ from menu code and with debug-on-signal non-nil, this can be very
+ irritating.
+ Don't bind ellipsis-len, we don't use it.
2012-05-12 Aidan Kehoe <kehoea(a)parhasard.net>
diff -r 00fd55d635fb -r 8593e614573a lisp/subr.el
--- a/lisp/subr.el Sat May 12 17:51:05 2012 +0100
+++ b/lisp/subr.el Sat May 12 18:12:13 2012 +0100
@@ -1062,18 +1062,15 @@
(setq ellipsis "..."))
(let ((str-len (length str))
(str-width (string-width str))
- (ellipsis-len (if ellipsis (length ellipsis) 0))
(ellipsis-width (if ellipsis (string-width ellipsis) 0))
(idx 0)
(column 0)
(head-padding "") (tail-padding "")
ch last-column last-idx from-idx)
- (condition-case nil
- (while (< column start-column)
- (setq ch (aref str idx)
- column (+ column (char-width ch))
- idx (1+ idx)))
- (args-out-of-range (setq idx str-len)))
+ (while (and (< column start-column) (< idx str-len))
+ (setq ch (aref str idx)
+ column (+ column (char-width ch))
+ idx (1+ idx)))
(if (< column start-column)
(if padding (make-string end-column padding) "")
(when (and padding (> column start-column))
@@ -1084,14 +1081,12 @@
(> str-width ellipsis-width))
(setq end-column (- end-column ellipsis-width))
(setq ellipsis ""))
- (condition-case nil
- (while (< column end-column)
- (setq last-column column
- last-idx idx
- ch (aref str idx)
- column (+ column (char-width ch))
- idx (1+ idx)))
- (args-out-of-range (setq idx str-len)))
+ (while (and (< column end-column) (< idx str-len))
+ (setq last-column column
+ last-idx idx
+ ch (aref str idx)
+ column (+ column (char-width ch))
+ idx (1+ idx)))
(when (> column end-column)
(setq column last-column
idx last-idx))
--
‘Iodine deficiency was endemic in parts of the UK until, through what has been
described as “an unplanned and accidental public health triumph”, iodine was
added to cattle feed to improve milk production in the 1930s.’
(EN Pearce, Lancet, June 2011)
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta