racket/port: fix read-bytes-evt' and read-string-evt'

As the documentation says, it's supposed to be ok to use the
same evt multiple times or in multiple threads, but an internal
buffer was allocated incorrectly, so that multiple/concurrent
uses could go wrong.

Closes PR 12860

original commit: d253b89ba87b4bb295fd652708642046f4b90676
This commit is contained in:
Matthew Flatt 2012-06-22 06:56:49 +08:00
parent bd352c8455
commit 2ec1929ff3

View File

@ -1032,13 +1032,15 @@
(-read-bytes!-evt bstr input-port peek-offset prog-evt))
(define (-read-bytes-evt len input-port peek-offset prog-evt)
(guard-evt
(lambda ()
(let ([bstr (make-bytes len)])
(wrap-evt
(-read-bytes!-evt bstr input-port peek-offset prog-evt)
(lambda (v)
(if (number? v)
(if (= v len) bstr (subbytes bstr 0 v))
v)))))
v)))))))
(define (read-bytes-evt len input-port)
(-read-bytes-evt len input-port #f #f))
@ -1049,6 +1051,8 @@
(define (-read-string-evt goal input-port peek-offset prog-evt)
(if (zero? goal)
(wrap-evt always-evt (lambda (x) ""))
(guard-evt
(lambda ()
(let ([bstr (make-bytes goal)]
[c (bytes-open-converter "UTF-8-permissive" "UTF-8")])
(wrap-evt
@ -1086,7 +1090,7 @@
[v (cdr bstr+v)])
(if (number? v)
(bytes->string/utf-8 bstr #\? 0 v)
v)))))))
v)))))))))
(define (read-string-evt goal input-port)
(-read-string-evt goal input-port #f #f))