Bug in interaction of closures, set! and `fxarithmetic-shift-right'
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Ikarus Scheme |
Fix Committed
|
High
|
Abdulaziz Ghuloum |
Bug Description
The following program produces a bogus result:
;; -------
(import (rnrs))
(define-syntax trace
(syntax-rules ()
((_ . args)
(begin
(for-each display (list . args))
(newline)))
#;
((_ . args) (begin))))
(define (make-bit-reader port)
(let ((buf 61) (buflen 8))
(lambda (count)
(let ((v (fxbit-field buf 0 count)))
(trace "BEFORE READ (c=" count "): buf=" buf ", buflen=" buflen)
(set! buf (fxarithmetic-
(set! buflen (fx- buflen count))
(trace "AFTER READ: buf=" buf ", buflen=" buflen)
v))))
(let ((get-bits (make-bit-reader
(get-bits 3))
;;-----
Running this with "ikarus --r6rs-script ikarus-set-bug.scm" results in
the following output:
BEFORE READ (c=3): buf=61, buflen=8
AFTER READ: buf=61, buflen=5
Note that the value of `buf' is unchanged after the `set!', even
though the shift amount `count' is 3. When one changes
`fxarithmetic-
problem goes away and the correct output is displayed:
BEFORE READ (c=3): buf=61, buflen=8
AFTER READ: buf=7, buflen=5
This is all with: Ikarus Scheme version 0.0.4-rc1+, 64-bit (revision
1856, build 2009-09-29).
I suspect this is some kind of compiler bug.
Fixed in revision 1859. Thanks.
It had nothing to do with closures and set!. It was just fxarithmetic- shift-right that was broken when the second argument is not a constant value (it was missing a shift of 3 bits).
You can test this by just saying shift-right 61 x)
> (define x 3)
> (fxarithmetic-
61
Thanks.