fixed (read-bytes/partial! _ _ n n)
added (assert ... <calling procedure>) .
This commit is contained in:
parent
62ab061350
commit
cc2b4fe985
|
@ -26,16 +26,17 @@
|
||||||
;; Assume MIN <= UBERMAX and BUF length < START + UEBERMAX.
|
;; Assume MIN <= UBERMAX and BUF length < START + UEBERMAX.
|
||||||
;; Read at least MIN bytes from INPORT into BUF starting at index START,
|
;; Read at least MIN bytes from INPORT into BUF starting at index START,
|
||||||
;; possibly more if possible w/o blocking, but in toto less than UEBERMAX.
|
;; possibly more if possible w/o blocking, but in toto less than UEBERMAX.
|
||||||
;; Return the number of bytes (<= UEBERMAX) read into BUF, but eof if
|
;; Return the number of bytes (<= UEBERMAX) read into BUF, but eof if
|
||||||
;; min>0 and reading started at end of file.
|
;; min>0 and reading started at end of file.
|
||||||
;; [ Problem with the underlying READ-BLOCK: if we want to read (at most)
|
;; [ Problem with the underlying READ-BLOCK: if we want to read (at most)
|
||||||
;; n>0 bytes w/o blocking, we have to communicate the upper bound n by
|
;; n>0 bytes w/o blocking, we have to communicate the upper bound n by
|
||||||
;; the buffer size. READ-BOLLOCK prefers to read maybe less than
|
;; the buffer size. READ-BOLLOCK prefers to read maybe less than
|
||||||
;; available but to avoid allocating a temp buffer ]
|
;; available but to avoid allocating a temp buffer ]
|
||||||
(define (read-bollock buf start min uebermax inport)
|
(define (read-bollock buf start min uebermax inport)
|
||||||
(assert (<= 0 min uebermax))
|
(assert (<= 0 min uebermax) read-bollock)
|
||||||
(assert (<= (+ start uebermax)
|
(assert (<= (+ start uebermax)
|
||||||
(sequence-length buf)))
|
(sequence-length buf))
|
||||||
|
read-bollock)
|
||||||
(let* ((len (sequence-length buf))
|
(let* ((len (sequence-length buf))
|
||||||
(mean (if (= min 0) 0
|
(mean (if (= min 0) 0
|
||||||
(read-block buf start min inport)))
|
(read-block buf start min inport)))
|
||||||
|
@ -49,7 +50,7 @@
|
||||||
|
|
||||||
(if (eof-object? xtra) mean
|
(if (eof-object? xtra) mean
|
||||||
(+ mean xtra))))
|
(+ mean xtra))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; like READ-STRING!/PARTIAL with byte-vectors instead of strings
|
;; like READ-STRING!/PARTIAL with byte-vectors instead of strings
|
||||||
|
@ -58,28 +59,32 @@
|
||||||
(let-optionals args ((fd/port (current-input-port))
|
(let-optionals args ((fd/port (current-input-port))
|
||||||
(start 0)
|
(start 0)
|
||||||
(end (sequence-length bytes)))
|
(end (sequence-length bytes)))
|
||||||
(assert (<= 0 start end (sequence-length bytes)))
|
(assert (<= 0 start end (sequence-length bytes))
|
||||||
(if (integer? fd/port)
|
read-bytes!/partial)
|
||||||
(let ((port (fdes->inport fd/port)))
|
(cond ((= end start) 0)
|
||||||
(set-port-buffering port bufpol/block (- end start))
|
((integer? fd/port)
|
||||||
(read-bytes!/partial bytes port start end))
|
(let ((port (fdes->inport fd/port)))
|
||||||
(let ((blocking-i/o? (= 0 (bitwise-and open/non-blocking
|
(set-port-buffering port bufpol/block (- end start))
|
||||||
(fdes-status fd/port)))))
|
(read-bytes!/partial bytes port start end)))
|
||||||
(read-bollock bytes start
|
(else
|
||||||
(if blocking-i/o? 1 0) ; cond. forward progress
|
(let ((blocking-i/o? (= 0 (bitwise-and open/non-blocking
|
||||||
(- end start)
|
(fdes-status fd/port)))))
|
||||||
fd/port)))))
|
(read-bollock bytes start
|
||||||
|
(if blocking-i/o? 1 0) ; cond. forward progress
|
||||||
|
(- end start)
|
||||||
|
fd/port))))))
|
||||||
|
|
||||||
|
|
||||||
(define (read-bytes/partial len . maybe-fd/port)
|
(define (read-bytes/partial len . maybe-fd/port)
|
||||||
(assert (<= 0 len))
|
(assert (<= 0 len)
|
||||||
|
read-bytes/partial)
|
||||||
(let* ((fd/port (:optional maybe-fd/port (current-input-port)))
|
(let* ((fd/port (:optional maybe-fd/port (current-input-port)))
|
||||||
(buf (make-byte-vector len 0))
|
(buf (make-byte-vector len 0))
|
||||||
(nread (read-bytes!/partial buf fd/port 0 len)))
|
(nread (read-bytes!/partial buf fd/port 0 len)))
|
||||||
(cond ((not nread) #f)
|
(cond ((not nread) #f)
|
||||||
((= nread len) buf)
|
((= nread len) buf)
|
||||||
(else (subsequence buf 0 nread)))))
|
(else (subsequence buf 0 nread)))))
|
||||||
|
|
||||||
|
|
||||||
;; The implementation of READ-STRING! should work with byte-vectors but for
|
;; The implementation of READ-STRING! should work with byte-vectors but for
|
||||||
;; BOGUS-SUBSTRING-SPEC? -- which calls STRING-LENGTH
|
;; BOGUS-SUBSTRING-SPEC? -- which calls STRING-LENGTH
|
||||||
|
@ -88,7 +93,8 @@
|
||||||
(let-optionals args ((fd/port (current-input-port))
|
(let-optionals args ((fd/port (current-input-port))
|
||||||
(start 0)
|
(start 0)
|
||||||
(end (sequence-length bytes)))
|
(end (sequence-length bytes)))
|
||||||
(assert (<= 0 start end (sequence-length bytes)))
|
(assert (<= 0 start end (sequence-length bytes))
|
||||||
|
read-bytes!)
|
||||||
(if (integer? fd/port)
|
(if (integer? fd/port)
|
||||||
(let ((port (fdes->inport fd/port)))
|
(let ((port (fdes->inport fd/port)))
|
||||||
(set-port-buffering port bufpol/block (- end start))
|
(set-port-buffering port bufpol/block (- end start))
|
||||||
|
@ -99,10 +105,10 @@
|
||||||
|
|
||||||
|
|
||||||
(define (read-bytes len . maybe-fd/port)
|
(define (read-bytes len . maybe-fd/port)
|
||||||
(assert (<= 0 len))
|
(assert (<= 0 len) read-bytes)
|
||||||
(let* ((fd/port (:optional maybe-fd/port (current-input-port)))
|
(let* ((fd/port (:optional maybe-fd/port (current-input-port)))
|
||||||
(buf (make-byte-vector len 0))
|
(buf (make-byte-vector len 0))
|
||||||
(nread (read-bytes! buf fd/port 0 len)))
|
(nread (read-bytes! buf fd/port 0 len)))
|
||||||
(cond ((not nread) #f)
|
(cond ((not nread) #f)
|
||||||
((= nread len) buf)
|
((= nread len) buf)
|
||||||
(else (subsequence buf 0 nread)))))
|
(else (subsequence buf 0 nread)))))
|
||||||
|
@ -112,8 +118,9 @@
|
||||||
(let-optionals args ((fd/port (current-output-port))
|
(let-optionals args ((fd/port (current-output-port))
|
||||||
(start 0)
|
(start 0)
|
||||||
(end (sequence-length bytes)))
|
(end (sequence-length bytes)))
|
||||||
(assert (<= 0 start end (sequence-length bytes)))
|
(assert (<= 0 start end (sequence-length bytes))
|
||||||
(error
|
write-bytes/partial)
|
||||||
|
(error
|
||||||
"write-bytes/partial : behaves no better than write-string/partial.
|
"write-bytes/partial : behaves no better than write-string/partial.
|
||||||
The latter is dereleased, cf. the RELEASE notes."
|
The latter is dereleased, cf. the RELEASE notes."
|
||||||
)))
|
)))
|
||||||
|
@ -125,7 +132,8 @@ The latter is dereleased, cf. the RELEASE notes."
|
||||||
(let-optionals args ((fd/port (current-output-port))
|
(let-optionals args ((fd/port (current-output-port))
|
||||||
(start 0)
|
(start 0)
|
||||||
(end (sequence-length bytes)))
|
(end (sequence-length bytes)))
|
||||||
(assert (<= 0 start end (sequence-length bytes)))
|
(assert (<= 0 start end (sequence-length bytes))
|
||||||
|
write-bytes)
|
||||||
(let ((port (if (integer? fd/port)
|
(let ((port (if (integer? fd/port)
|
||||||
(let ((port (fdes->outport fd/port)))
|
(let ((port (fdes->outport fd/port)))
|
||||||
(set-port-buffering port bufpol/block (- end start))
|
(set-port-buffering port bufpol/block (- end start))
|
||||||
|
|
Loading…
Reference in New Issue