Fix miscompilation of non-ASCII Latin-1 strings.
authorLudovic Courtès <ludo@gnu.org>
Sun, 7 Mar 2010 22:45:14 +0000 (23:45 +0100)
committerLudovic Courtès <ludo@gnu.org>
Sun, 7 Mar 2010 22:45:14 +0000 (23:45 +0100)
The bug was introduced dad6817f ("Use the R6RS I/O API in
`write-bytecode'.").

* module/language/assembly/compile-bytecode.scm
  (write-bytecode)[write-string]: Rename to...
  [write-latin1-string]: ... this.  Add the `write-loader-len' call.
  Write each character individually instead of using `string->utf8'.
  [write-loader]: Remove.

* test-suite/tests/asm-to-bytecode.test ("compiler")[load-string "æ"]:
  New test.

module/language/assembly/compile-bytecode.scm
test-suite/tests/asm-to-bytecode.test

index 5c0e115..0423b96 100644 (file)
@@ -50,8 +50,9 @@
     (let ((start (port-position port)))
       (lambda ()
         (+ address (- (port-position port) start)))))
-  (define (write-string s)
-    (put-bytevector port (string->utf8 s)))
+  (define (write-latin1-string s)
+    (write-loader-len (string-length s))
+    (string-for-each (lambda (c) (write-byte (char->integer c))) s))
   (define (write-int24-be x)
     (bytevector-s32-set! u32-bv 0 x (endianness big))
     (put-bytevector port u32-bv 1 3))
@@ -68,9 +69,6 @@
     (write-byte (ash len -16))
     (write-byte (logand (ash len -8) 255))
     (write-byte (logand len 255)))
-  (define (write-loader str)
-    (write-loader-len (string-length str))
-    (write-string str))
   (define (write-bytevector bv)
     (write-loader-len (bytevector-length bv))
     (put-bytevector port bv))
              ;; assembly)'.
              (write-bytecode meta port '() 0 #f)))
         ((make-char32 ,x) (write-uint32-be x))
-        ((load-number ,str) (write-loader str))
-        ((load-string ,str) (write-loader str))
+        ((load-number ,str) (write-latin1-string str))
+        ((load-string ,str) (write-latin1-string str))
         ((load-wide-string ,str) (write-wide-string str))
-        ((load-symbol ,str) (write-loader str))
+        ((load-symbol ,str) (write-latin1-string str))
         ((load-array ,bv) (write-bytevector bv))
         ((br ,l) (write-break l))
         ((br-if ,l) (write-break l))
index 6e89d86..1f01636 100644 (file)
@@ -1,4 +1,4 @@
-;;;; test assembly to bytecode compilation -*- scheme -*-
+;;;; Assembly to bytecode compilation -*- mode: scheme; coding: iso-8859-1; -*-
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
     (comp-test '(load-symbol "foo")
                (vector 'load-symbol 0 0 3 (char->integer #\f) (char->integer #\o)
                        (char->integer #\o)))
-    
+
+    (comp-test '(load-string "æ") ;; a non-ASCII Latin-1 string
+               (vector 'load-string 0 0 1 230))
+
     (comp-test '(load-program () 3 #f (make-int8 3) (return))
                #(load-program
                  (uint32 3)     ;; len