1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 22:10:21 +02:00

Fix miscompilation of non-ASCII Latin-1 strings.

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.
This commit is contained in:
Ludovic Courtès 2010-03-07 23:45:14 +01:00
parent bd5a75dcd8
commit 1caa6341b0
2 changed files with 11 additions and 10 deletions

View 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))
@ -103,10 +101,10 @@
;; 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))

View 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
@ -78,7 +78,10 @@
(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