refill-bv-buffer setting wrong index
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Ikarus Scheme |
Fix Committed
|
High
|
Abdulaziz Ghuloum |
Bug Description
Running the below program either raises an &i/o-decoding (but never &i/o-encoding it seems) or the read-back-in string is not equal to the original written-out string. What the program does is create a random-sized string filled with random characters, write it to a file, and read it back in and compare it. If creating such arbitrary random strings and writing them out works, shouldn't reading them work and shouldn't they always be equal for every possible random string? Playing with the value of max-string-size alters if it raises an exception or if the strings aren't equal and how long it will go before one of those happens. [This is similar to what I'm pumping through my forked-workers sockets test.]
;;;;;;;
(import (ikarus))
(define max-string-size #e1e5)
(define (make-test-string)
(let ([s (make-string (+ 1 (random max-string-
(do ([i 0 (+ 1 i)])
[(fx=? i (string-length s))
s]
(let loop ()
(let ([x (random #x110000)])
(if (fx<=? #xd800 x #xdfff)
(loop)
(define transcoder
(make-transcoder (utf-8-codec) (eol-style none) (error-
(define tmp-file "/tmp/random-
(let loop ()
(let ([fop (open-file-
[s (make-test-
(put-string fop s)
(close-
(let ([r (call-with-port (open-file-
(if (string=? r s)
(display ".")
(loop))
;;;;;;;
It's a bug in reading from files (refilling the buffers in the middle of a multibyte character) I believe since it does not show up if you read the file as a bytevector and decode the bytevector as in:
(let ([r (call-with-port
(transcoded- port
(open- bytevector- input-port
(call-with- port
(open- file-input- port tmp-file (file-options)
(buffer- mode block)
#f)
get-bytevecto r-all))
transcoder )
get- string- all)])