Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

run-time crash when using a combination of unsafe core primitives (compiler error, most likely) #86

Open
marcomaggi opened this issue Dec 6, 2015 · 1 comment

Comments

@marcomaggi
Copy link
Owner

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)))
@marcomaggi
Copy link
Owner Author

It appears to me that this code fails only on 64-bit platforms. So maybe it is an error in CPU registers allocation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant