-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
rework I/O stream abstractions #4710
Conversation
The main goal here is to make the function pointers comptime, so that we don't have to do the crazy stuff with async function frames. Since InStream, OutStream, and SeekableStream are already generic across error sets, it's not really worse to make them generic across the vtable as well. See #764 for the open issue acknowledging that using generics for these abstractions is a design flaw. See #130 for the efforts to make these abstractions non-generic. This commit also changes the OutStream API so that `write` returns number of bytes written, and `writeAll` is the one that loops until the whole buffer is written.
With these changes, here's an example of what reading from buffered stdin looks like: const std = @import("std");
pub fn main() anyerror!void {
- var stdin_unbuf = std.io.getStdIn().inStream();
- // damn that is pretty painful, isn't it?
- const in = &std.io.BufferedInStream(@typeOf(stdin_unbuf).Error).init(&stdin_unbuf.stream).stream;
+ const in = std.io.bufferedInStream(std.io.getStdIn().inStream()).inStream();
var sum: u64 = 0;
var line_buf: [50]u8 = undefined; |
@mlarouche - in ed13cff I attempted to fix the ELF emit raw code, but I didn't test it yet. Want to give it a lookover (and possibly submit a fix against this branch?) otherwise, I'll try to run |
I fixed those compile errors when trying to branch (see attached patch) but emit_raw is still completly broken, I don't have time until tonight to fix it properly so feel free to fix it during the day |
There are a few compilation errors, a few typos ( |
Notable in this branch is the new |
Confirmed that latests changes work with ZigGBA |
Also isn't #130 to make those interface generics instead ? |
nah, the whole point of a vtable language feature is to provide an interface type which is not generic, but can be used in different contexts with different implementations |
The main goal here is to make the function pointers comptime, so that we
don't have to do the crazy stuff with async function frames.
Since InStream, OutStream, and SeekableStream are already generic
across error sets, it's not really worse to make them generic across the
vtable as well.
See #764 for the open issue acknowledging that using generics for these
abstractions is a design flaw.
See #130 for the efforts to make these abstractions non-generic.
This commit also changes the OutStream API so that
write
returnsnumber of bytes written, and
writeAll
is the one that loops until thewhole buffer is written.