fixed arena allocator; should have tested it
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 20 Dec 2020 00:32:58 +0000 (18:32 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 20 Dec 2020 00:32:58 +0000 (18:32 -0600)
core/alloc/arena.onyx
docs/bugs [new file with mode: 0644]

index fba72bea30a48c321681a93b19930179efb923f5..051e705ce0b475f7bd175e186e0a98081079f100 100644 (file)
@@ -25,8 +25,8 @@ arena_alloc_proc :: proc (data: rawptr, aa: AllocationAction, size: u32, align:
             retval = ss.curr_ptr;
             ss.curr_ptr = cast(rawptr) (cast(u32) ss.curr_ptr + size);
         } else {
-               // Not enough space for the allocation
-               retval = null;
+            // Not enough space for the allocation
+            retval = null;
         }
 
         return retval;
@@ -36,20 +36,20 @@ arena_alloc_proc :: proc (data: rawptr, aa: AllocationAction, size: u32, align:
 }
 
 make :: proc (buffer: rawptr, length: u32) -> ArenaState {
-       return ArenaState.{
-           base_ptr = buffer,
-           curr_ptr = buffer,
-           size     = length,
-       };
+    return ArenaState.{
+        base_ptr = buffer,
+        curr_ptr = buffer,
+        size     = length,
+    };
 }
 
 make_allocator :: proc (rs: ^ArenaState) -> Allocator {
-       return Allocator.{
-               func = ring_alloc_proc,
-               data = rs,
-       };
+    return Allocator.{
+        func = arena_alloc_proc,
+        data = rs,
+    };
 }
 
 reset :: proc (arena: ^ArenaState) {
-       arena.curr_ptr = arena.base_ptr;
+    arena.curr_ptr = arena.base_ptr;
 }
\ No newline at end of file
diff --git a/docs/bugs b/docs/bugs
new file mode 100644 (file)
index 0000000..23fd0eb
--- /dev/null
+++ b/docs/bugs
@@ -0,0 +1,26 @@
+List of known bugs:
+
+[ ] Using an auto-cast on an argument when calling an overloaded proc leads
+       to an unexpected error. Take the following example:
+       ```
+       overloaded :: proc {
+               proc (x: f32, y: str) ---,
+               proc (x: i32, y: i32) ---,
+       }
+
+       foo :: proc () {
+               x: i32 = 1234;
+               overloaded(~~x, 4);
+       }
+       ```
+       Compiles with the following error:
+       ```
+       (/home/brendan/dev/c/onyx/a.onyx:8,15) unable to match overloaded function with provided argument types: (f32, unsized int)
+       8 |     overloaded(~~x, 4);
+       ```
+
+       This is because in trying the first overload, the auto-cast is consumed
+       and converted to a cast(f32). Then, when it doesn't match the first one
+       and it tries the second, the parameter types are f32 and unsized int,
+       which is doesn't match the second one, when the original parameters would
+       have matched correctly.
\ No newline at end of file