vicare
vicare copied to clipboard
run-time crash when using a combination of unsafe core primitives (compiler error, most likely)
The following program crashes at run-time:
#!r6rs
(import (vicare)
(vicare checks)
(vicare system $fx)
(vicare system $strings))
(define ($string-reverse! str start past)
(do ((i ($fxsub1 past) ($fxsub1 i))
(j start ($fxadd1 j)))
(($fx<= i j)
str)
(let ((ci ($string-ref str i)))
($string-set! str i ($string-ref str j))
($string-set! str j ci))))
(check
(let ((S (string-copy "ciao")))
($string-reverse! S 0 4)
S)
=> "oaic")
the crash does not occur if we change some unsafe core primitive application with the corresponding safe core primitive. For example, changing $fx<=
to fx<=?
avoids the error.
Notice that the following code with vectors works fine:
(internal-body
(define ($vector-reverse! str start past)
(do ((i ($fxsub1 past) ($fxsub1 i))
(j start ($fxadd1 j)))
(($fx<= i j)
str)
(let ((ci ($vector-ref str i)))
($vector-set! str i ($vector-ref str j))
($vector-set! str j ci))))
(check
(let ((S (vector-copy '#(c i a o))))
($vector-reverse! S 0 4)
S)
=> '#(o a i c)))
It appears to me that this code fails only on 64-bit platforms. So maybe it is an error in CPU registers allocation.