Skip to content

Commit

Permalink
stdio: implement cooked port adapters (#929)
Browse files Browse the repository at this point in the history
Completes the port adapter zoo

Closes #867
  • Loading branch information
vyzo authored Sep 26, 2023
1 parent 7cf0670 commit fc904ca
Show file tree
Hide file tree
Showing 6 changed files with 735 additions and 43 deletions.
7 changes: 7 additions & 0 deletions src/std/error.ss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Timeout Timeout? raise-timeout timeout-error?
UnboundKey UnboundKey? raise-unbound-key unbound-key-error?
ContextError ContextError? raise-context-error context-error?
UnsupportedMethod? raise-unsupported-method unsupported-method-error?
(rename: raise-bug BUG)
is-it-bug?
with-exception-stack-trace
Expand Down Expand Up @@ -75,6 +76,9 @@
;; key lookup errors
(deferror-class UnboundKey () unbound-key-error?)

;; unsupported interface methods
(deferror-class UnsupportedMethod () unsupported-method-error?)

;; utility macros
(defsyntax (exception-context stx)
(syntax-case stx ()
Expand Down Expand Up @@ -138,6 +142,9 @@
(defraise/context (raise-unbound-key where irritants ...)
(UnboundKey "no value associated with key" irritants: [irritants ...]))

(defraise/context (raise-unsupported-method where)
(UnsupportedMethod "unsupported method" irritants: []))

;; it's a bug
(deferror-class BUG () is-it-bug?)

Expand Down
4 changes: 2 additions & 2 deletions src/std/io/bio/api.ss
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
(reader (Reader pre-reader)))
(BufferedReader (make-input-buffer reader buffer 0 0 #f))))
((input-port? pre-reader)
(BufferedReader (raw-port pre-reader))) ;; TODO: use a cooked-port instead
(BufferedReader (make-cooked-binary-input-port pre-reader)))
(else
(raise-bad-argument open-buffered-reader "Reader instance or u8vector" pre-reader))))

Expand All @@ -61,7 +61,7 @@
(buffer (make-u8vector-buffer buffer-or-size)))
(BufferedWriter (make-output-buffer writer buffer 0 #f))))
((output-port? pre-writer)
(BufferedWriter (raw-port pre-writer))) ;; TODO: use a cooked-port instead
(BufferedWriter (make-raw-binary-output-port pre-writer)))
(else
(raise-bad-argument open-buffered-writer "Writer instance or #f" pre-writer))))

Expand Down
Loading

0 comments on commit fc904ca

Please sign in to comment.