From: Brendan Hansen Date: Fri, 22 Sep 2023 01:36:03 +0000 (-0500) Subject: bugfixes: miscellaneous X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8c55c1c07a87f61a3af56a5648355e67a63b7a08;p=onyx.git bugfixes: miscellaneous --- diff --git a/core/alloc/alloc.onyx b/core/alloc/alloc.onyx index 6df2b6b4..de3eb988 100644 --- a/core/alloc/alloc.onyx +++ b/core/alloc/alloc.onyx @@ -1,6 +1,7 @@ package core.alloc #load "./arena" +#load "./atomic" #load "./fixed" #load "./heap" #load "./ring" diff --git a/core/alloc/atomic.onyx b/core/alloc/atomic.onyx index ce4bad90..ffa485c6 100644 --- a/core/alloc/atomic.onyx +++ b/core/alloc/atomic.onyx @@ -6,6 +6,7 @@ package core.alloc.atomic // is not needed for the general purpose heap allocator, // as that already has a thread-safe implementation. +use core.alloc use core.sync AtomicAllocator :: struct { @@ -25,7 +26,7 @@ make_allocator :: (atomic: &AtomicAllocator) => Allocator.{ atomic, atomic_alloc }; #overload -core.alloc.as_allocator :: make_allocator +alloc.as_allocator :: make_allocator #local diff --git a/core/io/reader.onyx b/core/io/reader.onyx index ffec5669..9e9a8fdf 100644 --- a/core/io/reader.onyx +++ b/core/io/reader.onyx @@ -170,17 +170,21 @@ read_bytes :: (use reader: &Reader, bytes: [] u8) -> (i32, Error) { write_index := 0; while n > 0 && !reader_empty(reader) { + if start != end { + to_write := math.min(n, end); + memory.copy(bytes.data + write_index, buffer.data + start, to_write); + n -= to_write; + write_index += to_write; + start += to_write; + } + + if n == 0 do break; + if err := reader_read_next_chunk(reader); err == .ReadPending || err == .ReadLater { return write_index, err; } - - to_write := math.min(n, end); - memory.copy(bytes.data + write_index, buffer.data, to_write); - n -= to_write; - write_index += to_write; - start += to_write; } last_byte = cast(i32) bytes[write_index - 1]; @@ -336,6 +340,10 @@ read_line :: (use reader: &Reader, consume_newline := true, allocator := context array.init(&out, allocator=allocator); while done := false; !done { + if start == end { + while reader_read_next_chunk(reader) == .ReadPending --- + } + count := start; while count < end && buffer[count] != #char "\n" { count += 1; diff --git a/core/net/net.onyx b/core/net/net.onyx index 0cc0f6e8..ae8238bd 100644 --- a/core/net/net.onyx +++ b/core/net/net.onyx @@ -272,6 +272,8 @@ network_to_host :: #match #local {} if would_block do return .ReadLater, bytes_read; + if bytes_read == 0 do return .EOF, bytes_read; + return .None, bytes_read; }, diff --git a/core/string/string.onyx b/core/string/string.onyx index 29a259a1..7e67e925 100644 --- a/core/string/string.onyx +++ b/core/string/string.onyx @@ -303,7 +303,7 @@ index_of :: (s: str, substr: str) -> i32 { } last_index_of :: (s: str, c: u8) -> i32 { - for range.{s.count, 0, -1} { + for range.{s.count-1, 0, -1} { if s[it] == c do return it; } return -1; diff --git a/runtime/src/ort_net.h b/runtime/src/ort_net.h index c021b1c4..3550862b 100644 --- a/runtime/src/ort_net.h +++ b/runtime/src/ort_net.h @@ -331,7 +331,7 @@ ONYX_DEF(__net_poll_recv, (WASM_I32, WASM_I32, WASM_I32, WASM_I32), ()) { fds = alloca(params->data[1].of.i32 * sizeof(struct pollfd)); - for (i=0; idata[1].of.i32; i++) { + for (i=0; i < params->data[1].of.i32; i++) { fds[i].fd = *(i32 *) ONYX_PTR(params->data[0].of.i32 + 4 * i); fds[i].events = POLLIN; fds[i].revents = 0;