diff --git a/scheme/ikarus.io.ss b/scheme/ikarus.io.ss index 8fcfcbc..20a842f 100644 --- a/scheme/ikarus.io.ss +++ b/scheme/ikarus.io.ss @@ -1863,15 +1863,15 @@ [else ($bytevector-set! s i x) (let f ([p p] [s s] [start i] [i 1] [c c]) - (let ([x (get-u8 p)]) - (cond - [(eof-object? x) i] - [else - ($bytevector-set! s ($fx+ start i) x) - (let ([i ($fxadd1 i)]) - (if ($fx= i c) - i - (f p s start i c)))])))])))] + (cond + [($fx= i c) i] + [else + (let ([x (get-u8 p)]) + (cond + [(eof-object? x) i] + [else + ($bytevector-set! s ($fx+ start i) x) + (f p s start ($fx+ i 1) c)]))]))])))] [($fx= c 0) 0] [else (die 'get-bytevector-n! "count is negative" c)]))) diff --git a/scheme/last-revision b/scheme/last-revision index 41cca09..2e5f524 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1815 +1817 diff --git a/scheme/tests/io.ss b/scheme/tests/io.ss index d022eea..364aa9c 100755 --- a/scheme/tests/io.ss +++ b/scheme/tests/io.ss @@ -706,8 +706,21 @@ (put-bytevector p '#vu8(0))) (assert (equal? (e) (make-bytevector (* 86 2) 0)))))) + (define (test-get-bytevector-n) + (let ((p (open-bytevector-input-port '#vu8(1 2 3 4 5 6 7 8 9))) + (buf (make-bytevector 10 #xff))) + (let ([buf1 + (begin + (printf "going to read 5 bytes: ~s\n" (get-bytevector-n! p buf 0 5)) + (printf "result: ~s\n" buf) + (bytevector-copy buf))]) + (printf "going to read 1 byte: ~s\n" (get-bytevector-n! p buf 5 1)) + (printf "result: ~s\n" buf) + (unless (bytevector=? buf '#vu8(1 2 3 4 5 6 #xff #xff #xff #xff)) + (error 'test "the data is not correct" buf1 buf))))) (define (run-tests) + (test-get-bytevector-n) (test-custom-binary-input-ports) (test-custom-binary-output-ports) (run-exhaustive-tests)