-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve safety of BIO api #751
Conversation
The bio extension methods _erroneously_ assume that the buffer is an input-buffer; this is blatantly false with delimited input buffers, and also alternative implementations of buffers if someone is so inclined. This fixes the problem by checking the exact type and only apply the dangerous stuff if it is an exact instance; otherwise fallback to generic methods. This applies for the inline methods and also read-char/peek-char. This in turn necessitated the introduction of a `put-back` method to the BufferedReader interface, otherwise generic read-char and peek-char implementations are impossible to implement correctly. I reckon this will be generally useful for parsers, so it's not abstraction leakage. It also fixes the issue with get-buffer-output-* not flushing the buffer before retrieving the output.
So that we can't cast from one to the other, which would be a disaster as the file is open in different directions.
- add notes for put-back behavior. - add thread safety notes for general Reader/Writer behavior.
(bio-read-u8 bio)))))) | ||
(if (is-input-buffer? reader) | ||
(let () | ||
(declare (not interrupts-enabled)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a without-interrupts
macro would be useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, i prefer to see the declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont want to encourage people to disable interrupts right and left.
(begin | ||
(put-back! buf 0 previous-input) | ||
(set! (&input-buffer-rhi bio) prevlen) | ||
(void)))))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes consecutive put-backs expensive. Maybe worth noting in the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, thats why the list.
Maybe worth adding a note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, it is not really deterministic on how much it will cost; it is usually cheap, but sometimes it can be expensive.
The bio extension methods erroneously assume that the buffer is an input-buffer; this is blatantly false with delimited input buffers, and also alternative implementations of buffers if someone is so inclined.
This fixes the problem by checking the exact type and only apply the dangerous stuff if it is an exact instance; otherwise fallback to generic methods. This applies for the inline methods and also read-char/peek-char.
This in turn necessitated the introduction of a
put-back
method to the BufferedReader interface, otherwise generic read-char and peek-char implementations are impossible to implement correctly. I reckon this will be generally useful for parsers, so it's not abstraction leakage.It also fixes the issue with get-buffer-output-* not flushing the buffer before retrieving the output.
And while at it, it separates input from output file io so that we can't cast one to the other; the file is open in different directions.