mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-17 11:10:18 +02:00
Fix bytevector and custom binary ports to actually use ISO-8859-1 encoding.
Fixes <http://bugs.gnu.org/20200>, introduced in
commit 337edc591f
.
Reported by David Kastrup <dak@gnu.org>.
* libguile/r6rs-ports.c (make_bip, make_cbip, make_bop, make_cbop):
After setting port encoding = NULL, update 'encoding_mode'
accordingly.
* libguile/ports.c (scm_i_set_port_encoding_x): Add warning comment.
* test-suite/tests/r6rs-ports.test: Add tests.
This commit is contained in:
parent
2c032c2215
commit
d574d96f87
3 changed files with 59 additions and 0 deletions
|
@ -357,6 +357,11 @@
|
|||
(with-fluids ((%default-port-encoding "UTF-8"))
|
||||
(binary-port? (open-bytevector-input-port #vu8(1 2 3)))))
|
||||
|
||||
(pass-if-equal "bytevector-input-port uses ISO-8859-1 (Guile extension)"
|
||||
"©©"
|
||||
(with-fluids ((%default-port-encoding "UTF-8"))
|
||||
(get-string-all (open-bytevector-input-port #vu8(194 169 194 169)))))
|
||||
|
||||
(pass-if-exception "bytevector-input-port is read-only"
|
||||
exception:wrong-type-arg
|
||||
|
||||
|
@ -417,6 +422,23 @@
|
|||
(input-port? port)
|
||||
(bytevector=? (get-bytevector-all port) source))))
|
||||
|
||||
(pass-if-equal "make-custom-binary-input-port uses ISO-8859-1 (Guile extension)"
|
||||
"©©"
|
||||
(with-fluids ((%default-port-encoding "UTF-8"))
|
||||
(let* ((source #vu8(194 169 194 169))
|
||||
(read! (let ((pos 0)
|
||||
(len (bytevector-length source)))
|
||||
(lambda (bv start count)
|
||||
(let ((amount (min count (- len pos))))
|
||||
(if (> amount 0)
|
||||
(bytevector-copy! source pos
|
||||
bv start amount))
|
||||
(set! pos (+ pos amount))
|
||||
amount))))
|
||||
(port (make-custom-binary-input-port "the port" read!
|
||||
#f #f #f)))
|
||||
(get-string-all port))))
|
||||
|
||||
(pass-if "custom binary input port does not support `port-position'"
|
||||
(let* ((str "Hello Port!")
|
||||
(source (open-bytevector-input-port
|
||||
|
@ -717,6 +739,14 @@ not `set-port-position!'"
|
|||
(pass-if "bytevector-output-port is binary"
|
||||
(binary-port? (open-bytevector-output-port)))
|
||||
|
||||
(pass-if-equal "bytevector-output-port uses ISO-8859-1 (Guile extension)"
|
||||
#vu8(194 169 194 169)
|
||||
(with-fluids ((%default-port-encoding "UTF-8"))
|
||||
(let-values (((port get-content)
|
||||
(open-bytevector-output-port)))
|
||||
(put-string port "©©")
|
||||
(get-content))))
|
||||
|
||||
(pass-if "open-bytevector-output-port [extract after close]"
|
||||
(let-values (((port get-content)
|
||||
(open-bytevector-output-port)))
|
||||
|
@ -818,6 +848,22 @@ not `set-port-position!'"
|
|||
(not eof?)
|
||||
(bytevector=? sink source))))
|
||||
|
||||
(pass-if-equal "custom-binary-output-port uses ISO-8859-1 (Guile extension)"
|
||||
'(194 169 194 169)
|
||||
(with-fluids ((%default-port-encoding "UTF-8"))
|
||||
(let* ((sink '())
|
||||
(write! (lambda (bv start count)
|
||||
(if (= 0 count) ; EOF
|
||||
0
|
||||
(let ((u8 (bytevector-u8-ref bv start)))
|
||||
;; Get one byte at a time.
|
||||
(set! sink (cons u8 sink))
|
||||
1))))
|
||||
(port (make-custom-binary-output-port "cbop" write!
|
||||
#f #f #f)))
|
||||
(put-string port "©©")
|
||||
(reverse sink))))
|
||||
|
||||
(pass-if "standard-output-port is binary"
|
||||
(with-fluids ((%default-port-encoding "UTF-8"))
|
||||
(binary-port? (standard-output-port))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue