From ac2223a474e4f69cddbf6e524b200eaf422c75d1 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 1 Apr 2022 16:44:06 -0500 Subject: [PATCH] bugfixes --- core/runtime/onyx_run.onyx | 1 + core/stdio.onyx | 3 ++- include/bh.h | 7 +++++++ src/checker.c | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/runtime/onyx_run.onyx b/core/runtime/onyx_run.onyx index c61a5ca8..d5f49619 100644 --- a/core/runtime/onyx_run.onyx +++ b/core/runtime/onyx_run.onyx @@ -17,6 +17,7 @@ __output_string :: (s: str) -> u32 { __read_from_input :: (buffer: [] u8) -> i32 { err, read := io.stream_read(^__stdin, buffer); + if err == .ReadPending do return 0; if err != .None do return -1; return read; } diff --git a/core/stdio.onyx b/core/stdio.onyx index 6e7b19ff..e7af56a7 100644 --- a/core/stdio.onyx +++ b/core/stdio.onyx @@ -128,7 +128,8 @@ __flush_stdio :: () { #local stdin_vtable := io.Stream_Vtable.{ read = (_: ^io.Stream, buffer: [] u8) -> (io.Error, u32) { bytes_read := runtime.__read_from_input(buffer); - if bytes_read <= 0 do return .EOF, 0; + if bytes_read == 0 do return .ReadPending, 0; + if bytes_read < 0 do return .EOF, 0; return .None, bytes_read; }, diff --git a/include/bh.h b/include/bh.h index 65276923..b187b96d 100644 --- a/include/bh.h +++ b/include/bh.h @@ -1471,6 +1471,13 @@ b32 bh_file_read_at(bh_file* file, i64 offset, void* buffer, isize buff_size, is else return 0; #elif defined(_BH_LINUX) + if (file->fd == 0) { + isize res = read(file->fd, buffer, buff_size); + if (res < 0) return 0; + if (bytes_read) *bytes_read = res; + return 1; + } + isize res = pread(file->fd, buffer, buff_size, offset); if (res < 0) return 0; if (bytes_read) *bytes_read = res; diff --git a/src/checker.c b/src/checker.c index 7cc6f445..23e2389f 100644 --- a/src/checker.c +++ b/src/checker.c @@ -216,6 +216,7 @@ CheckStatus check_while(AstIfWhile* whilenode) { } CheckStatus check_for(AstFor* fornode) { + b32 old_inside_for_iterator; if (fornode->flags & Ast_Flag_Has_Been_Checked) goto fornode_expr_checked; CHECK(expression, &fornode->iter); -- 2.25.1