cs & io: fix read on closed byte-string input port

Closes #3770
This commit is contained in:
Matthew Flatt 2021-04-11 12:28:13 -06:00
parent 413f09aaaa
commit a808eb042b
3 changed files with 37 additions and 4 deletions

View File

@ -934,6 +934,35 @@
(check-all void)
(check-all port-count-lines!))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; attempting to read from or write to a closed byte-string port
(let ()
(define (check proc)
(define p (open-input-bytes #"x"))
(close-input-port p)
(err/rt-test (proc p) exn:fail:contract? #rx"closed"))
(check read-byte)
(check peek-byte)
(check (lambda (p) (peek-byte p 10)))
(check (lambda (p) (read-bytes 10 p)))
(check read-char)
(check read-char-or-special)
(check peek-char)
(check (lambda (p) (read-string 10 p)))
(check read)
(check (lambda (p) (read-syntax (object-name p) p))))
(let ()
(define (check proc)
(define p (open-output-bytes))
(close-output-port p)
(err/rt-test (proc p) exn:fail:contract? #rx"closed"))
(check (lambda (p) (write-byte 10 p)))
(check (lambda (p) (write-bytes #"hello" p)))
(check (lambda (p) (write-char #\x p)))
(check (lambda (p) (write-string "hello" p))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; port-closed events

View File

@ -18500,9 +18500,11 @@
(set-bytes-input-port-bstr! this-id_0 #f)
(let ((b_0 (core-port-buffer this-id_0)))
(if (direct-bstr b_0)
(begin
(set-core-port-offset! this-id_0 (direct-pos b_0))
(set-direct-bstr! b_0 #f))
(let ((pos_0 (direct-pos b_0)))
(begin
(set-core-port-offset! this-id_0 pos_0)
(set-direct-end! b_0 pos_0)
(set-direct-bstr! b_0 #f)))
(void)))))))))
app_0
app_1

View File

@ -45,7 +45,9 @@
(set! bstr #f)
(define b buffer)
(when (direct-bstr b)
(set! offset (direct-pos b))
(define pos (direct-pos b))
(set! offset pos)
(set-direct-end! b pos)
(set-direct-bstr! b #f)))]
[file-position
(case-lambda