bugfixes: miscellaneous
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 22 Sep 2023 01:36:03 +0000 (20:36 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 22 Sep 2023 01:36:03 +0000 (20:36 -0500)
core/alloc/alloc.onyx
core/alloc/atomic.onyx
core/io/reader.onyx
core/net/net.onyx
core/string/string.onyx
runtime/src/ort_net.h

index 6df2b6b4a913e66b8dcbbba40ab661508e996674..de3eb988f239548f48ad92eed05ec1a5e15c3bfd 100644 (file)
@@ -1,6 +1,7 @@
 package core.alloc
 
 #load "./arena"
+#load "./atomic"
 #load "./fixed"
 #load "./heap"
 #load "./ring"
index ce4bad90548477abaf353618aac553e8c09c8b64..ffa485c64440690b6edfd603f0bc76c9ebb426de 100644 (file)
@@ -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
index ffec5669ac7112c64960fd3bd1ddbd52b1966795..9e9a8fdf3ed1a7b4a0f174a8f80f7a390ef025b7 100644 (file)
@@ -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;
index 0cc0f6e8d0679c189e8f370341224c5949af2c0d..ae8238bd25154916220b04a5dc012632f45a55d6 100644 (file)
@@ -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;
     },
 
index 29a259a1185faaa1984c02ed223bc9ca641aab02..7e67e9253d826ae2c6d55f31f7db5ec97d8feae9 100644 (file)
@@ -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;
index c021b1c48fe53a0905f9b275c4042f83f0a333f9..3550862b9e6470f3e35fc06ed97629d775921ae0 100644 (file)
@@ -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; i<params->data[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;