Ar an deichiú lá de mí Feabhra, scríobh Stephen J. Turnbull:
VETO
Michael Sperber writes:
>
> Aidan, could you look at this?
>
> search.c, about line 1441:
>
> do
> {
> translated = TRANSLATE (inverse_trt, translated);
>
> if (charset_base == (translated & ~ICHAR_FIELD3_MASK))
> break;
>
> } while (starting_ch != translated);
>
> assert (starting_ch != translated);
>
> It seems to me (not really understanding the details of all this
> translation and inverse translation business) that the assertion is
> bogus: It mirrors the loop condition, yet there's a break statement in
> the loop right before. (And that's exactly what's getting triggered for
> me.) So I suggest just zapping it. At least what used to crash my
> XEmacs now works.
The pseudo-code is something like this
if this translation is inappropriate for Boyer-Moore then
do
get next candidate translation
if it is appropriate
break
while we haven't run out of candidates
assert we found a usable translation
So maybe the code works for you, but it's not working according to
theory.
At the least, I think the assert should be replaced with
if (starting_ch != translated) { boyer_moore_ok = 0; break; }
I believe that's safe. Aidan?
No, the assertion is well-founded when it comes to the algorithms used. It
doesn’t take into account the (new) feature characters may have been ignored
because they were unrepresentable in the buffer, though; had they not been,
simple_search would have been chosen earlier and this code wouldn’t be
relevant.
The below patch fails immediately when it encounters characters in the
search string that are not possible in the buffer, and avoids this
assertion. Another way to avoid the assertion failure would be to check
explicitly if the character being searched for and its translations are not
representable in the buffer.
Sorry about my delay in responding; this code takes a good bit of thought
and time to get one’s head around it.
changeset: 4420:69b803c646cd
tag: tip
user: Aidan Kehoe <kehoea(a)parhasard.net>
date: Mon Feb 11 22:34:51 2008 +0100
summary: Fail searches immediately if searching for non-representable characters.
diff -r eb82fbb675ea -r 69b803c646cd src/ChangeLog
--- a/src/ChangeLog Thu Feb 07 10:03:49 2008 +0100
+++ b/src/ChangeLog Mon Feb 11 22:34:51 2008 +0100
@@ -1,3 +1,11 @@ 2008-02-03 Jerry James <james(a)xemacs.o
+2008-02-11 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * search.c (search_buffer):
+ In the event that a character is not representable in the buffer,
+ fail immediately. Prevents an assertion failure in the code to
+ deal with whether Boyer-Moore search can be used for such
+ characters.
+
2008-02-03 Jerry James <james(a)xemacs.org>
* redisplay.c (generate_displayable_area): If a line has been
diff -r eb82fbb675ea -r 69b803c646cd src/search.c
--- a/src/search.c Thu Feb 07 10:03:49 2008 +0100
+++ b/src/search.c Mon Feb 11 22:34:51 2008 +0100
@@ -1385,7 +1385,7 @@ search_buffer (struct buffer *buf, Lisp_
&& (translated != c || inverse != c))
{
Ichar starting_c = c;
- int charset_base_code;
+ int charset_base_code, checked = 0;
do
{
@@ -1398,6 +1398,8 @@ search_buffer (struct buffer *buf, Lisp_
if (c > 0xFF && nothing_greater_than_0xff)
continue;
+
+ checked = 1;
if (-1 == charset_base) /* No charset yet specified. */
{
@@ -1424,6 +1426,23 @@ search_buffer (struct buffer *buf, Lisp_
}
}
} while (c != starting_c);
+
+ if (!checked)
+ {
+#ifdef DEBUG_XEMACS
+ if (debug_xemacs_searches)
+ {
+ Lisp_Symbol *sym = XSYMBOL (Qsearch_algorithm_used);
+ sym->value = Qnil;
+ }
+#endif
+ /* The "continue" clauses were used above, for every
+ translation of the character. As such, this character
+ is not to be found in the buffer and neither is the
+ string as a whole. Return immediately; also avoid
+ triggering the assertion a few lines down. */
+ return n > 0 ? -n : n;
+ }
if (boyer_moore_ok && charset_base != -1 &&
charset_base != (translated & ~ICHAR_FIELD3_MASK))
diff -r eb82fbb675ea -r 69b803c646cd tests/ChangeLog
--- a/tests/ChangeLog Thu Feb 07 10:03:49 2008 +0100
+++ b/tests/ChangeLog Mon Feb 11 22:34:51 2008 +0100
@@ -1,3 +1,8 @@ 2008-01-30 Aidan Kehoe <kehoea@parhasa
+2008-02-11 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * automated/case-tests.el (Assert):
+ New test case; thank you Michael Sperber.
+
2008-01-30 Aidan Kehoe <kehoea(a)parhasard.net>
* automated/case-tests.el (pristine-case-table):
diff -r eb82fbb675ea -r 69b803c646cd tests/automated/case-tests.el
--- a/tests/automated/case-tests.el Thu Feb 07 10:03:49 2008 +0100
+++ b/tests/automated/case-tests.el Mon Feb 11 22:34:51 2008 +0100
@@ -284,6 +284,9 @@
(goto-char (point-min))
(Assert (search-forward "Flei\xdf")))
+(with-temp-buffer
+ (Assert (search-forward "M\xe9zard" nil t)))
+
(Skip-Test-Unless
(boundp 'debug-xemacs-searches) ; normal when we have DEBUG_XEMACS
"not a DEBUG_XEMACS build"
--
¿Dónde estará ahora mi sobrino Yoghurtu Nghé, que tuvo que huir
precipitadamente de la aldea por culpa de la escasez de rinocerontes?
_______________________________________________
XEmacs-Patches mailing list
XEmacs-Patches(a)xemacs.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/xemacs-patches