>>>> "KY" == Katsumi Yamaoka
<yamaoka(a)jpl.org> writes:
KY> Hi,
KY> KANEMATSU Daiji <kanematu(a)sra.co.jp> reported in xemacs-beta-ja that
KY> there is a bug in the byte-compiled math function under XEmacs 21.2
KY> as follows:
Thanks for finding this bug. I prefer the following fix, which also
adds some tests to the test suite:
Index: lisp/ChangeLog
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/lisp/ChangeLog,v
retrieving revision 1.156.2.533
diff -u -w -U0 -r1.156.2.533 ChangeLog
--- lisp/ChangeLog 2001/03/16 10:37:29 1.156.2.533
+++ lisp/ChangeLog 2001/03/23 07:33:30
@@ -0,0 +1,5 @@
+2001-03-23 Martin Buchholz <martin(a)xemacs.org>
+
+ * byte-optimize.el (byte-optimize-minus):
+ Fix mis-byte-compilation of (- 0 x) --> (- (- x))
+
Index: tests/ChangeLog
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/tests/Attic/ChangeLog,v
retrieving revision 1.1.2.86
diff -u -w -U0 -r1.1.2.86 ChangeLog
--- tests/ChangeLog 2001/03/15 16:28:54 1.1.2.86
+++ tests/ChangeLog 2001/03/23 07:33:50
@@ -0,0 +1,10 @@
+2001-03-23 Martin Buchholz <martin(a)xemacs.org>
+
+ * automated/lisp-tests.el:
+ Add test for mis-byte-compilation of (- 0 x).
+
+2001-03-14 Martin Buchholz <martin(a)xemacs.org>
+
+ * automated/hash-table-tests.el:
+ Add test with maphash mapping function calling puthash.
+
Index: tests/automated/lisp-tests.el
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/tests/automated/Attic/lisp-tests.el,v
retrieving revision 1.1.2.22
diff -u -w -r1.1.2.22 lisp-tests.el
--- tests/automated/lisp-tests.el 2000/12/28 10:19:00 1.1.2.22
+++ tests/automated/lisp-tests.el 2001/03/23 07:33:54
@@ -243,6 +243,8 @@
(Assert (= (- one) -1))
(Assert (= (- one one) 0))
(Assert (= (- one one one) -1))
+ (Assert (= (- 0 one) -1))
+ (Assert (= (- 0 one one) -2))
(Assert (= (+ one 1) 2))
(dolist (zero '(0 0.0 ?\0))
(Assert (= (+ 1 zero) 1))
Index: lisp/byte-optimize.el
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/lisp/byte-optimize.el,v
retrieving revision 1.5.2.17
diff -u -w -r1.5.2.17 byte-optimize.el
--- lisp/byte-optimize.el 2001/01/15 13:42:45 1.5.2.17
+++ lisp/byte-optimize.el 2001/03/23 07:34:10
@@ -729,9 +729,15 @@
(decf (nth 1 form) last)
(butlast form))
- ;; (- 0 x ...) --> (- (- x) ...)
- ((and (eq 0 (nth 1 form)) (>= (length form) 3))
- `(- (- ,(nth 2 form)) ,@(nthcdr 3 form)))
+ ;; (- 0 ...) -->
+ ((eq 0 (nth 1 form))
+ (case (length form)
+ ;; (- 0) --> 0
+ (2 0)
+ ;; (- 0 x) --> (- x)
+ (3 `(- ,(nth 2 form)))
+ ;; (- 0 x y ...) --> (- (- x) y ...)
+ (t `(- (- ,(nth 2 form)) ,@(nthcdr 3 form)))))
(t (byte-optimize-predicate form)))))
>>>> In <x2t8zlzlx9p.fsf(a)ext294.sra.co.jp>
>>>>> KANEMATSU Daiji <kanematu(a)sra.co.jp> wrote:
> (defun my-test1 (num)
> (- 0 num))
> (my-test1 10);; not compiled
> => -10
> (byte-compile 'my-test1)
> (my-test1 10);; compiled
> => 10
KY> I found the cause of this in the function `byte-optimize-minus'.
KY> Here is a patch for it.
KY> 2001-03-21 Katsumi Yamaoka <yamaoka(a)jpl.org>
KY> * byte-optimize.el (byte-optimize-minus): Fix.
KY> --- byte-optimize.el~ Mon Jan 15 22:05:01 2001
KY> +++ byte-optimize.el Wed Mar 21 09:09:02 2001
KY> @@ -729,8 +729,12 @@
KY> (decf (nth 1 form) last)
KY> (butlast form))
KY> + ;; (- 0 x) --> (- x)
KY> + ((and (eq 0 (nth 1 form)) (= (length form) 3))
KY> + `(- ,(nth 2 form)))
KY> +
KY> ;; (- 0 x ...) --> (- (- x) ...)
KY> - ((and (eq 0 (nth 1 form)) (>= (length form) 3))
KY> + ((and (eq 0 (nth 1 form)) (> (length form) 3))
KY> `(- (- ,(nth 2 form)) ,@(nthcdr 3 form)))
KY> (t (byte-optimize-predicate form)))))
KY> --
KY> Katsumi Yamaoka <yamaoka(a)jpl.org>