bugfixes in standard libraries
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 12 Sep 2022 01:54:01 +0000 (20:54 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 12 Sep 2022 01:54:01 +0000 (20:54 -0500)
core/alloc/auto_heap.onyx
core/alloc/heap.onyx
core/builtin.onyx
core/string.onyx
misc/onyx.vim

index 03334251f812cf51d7a8d095908884ab760a20ab..af634d7ebcf9766087f5068f67bd56f2e39e5b96 100644 (file)
@@ -10,12 +10,17 @@ AutoHeapState :: struct {
 
     switch aa {
         case .Alloc {
-            data.set->insert(newptr);
+            if newptr != null {
+                data.set->insert(newptr);
+            }
         }
 
         case .Resize {
             data.set->remove(oldptr);
-            data.set->insert(newptr);
+
+            if newptr != null {
+                data.set->insert(newptr);
+            }
         }
 
         case .Free {
index 0dfe30182e1555ee9177a1bc5c1cd67de1a54c55..d01f38f2b7bcaccd029778094babcbb811bb5d4e 100644 (file)
@@ -175,7 +175,14 @@ get_freed_size :: () => {
         #if runtime.Multi_Threading_Enabled do sync.scoped_mutex(^heap_mutex);
 
         hb_ptr := cast(^heap_freed_block) (cast(uintptr) ptr - sizeof heap_allocated_block);
-        #if Enable_Debug do assert(hb_ptr.size & Allocated_Flag == Allocated_Flag, "Corrupted heap on free. This could be due to a double free, or using memory past were you allocated it.");
+        #if Enable_Debug {
+            // assert(hb_ptr.size & Allocated_Flag == Allocated_Flag, "Corrupted heap on free. This could be due to a double free, or using memory past were you allocated it.");
+
+            if hb_ptr.size & Allocated_Flag != Allocated_Flag {
+                log("INVALID DOUBLE FREE");
+                return;
+            }
+        }
 
         hb_ptr.size &= ~Allocated_Flag;
         orig_size := hb_ptr.size - sizeof heap_allocated_block;
index 04b9b0dede26df3385db66396b24fe3f15bf1e1a..5d9a16bc662e3666bd3f08d8a52be1d23334cae1 100644 (file)
@@ -76,7 +76,9 @@ OnyxContext :: struct {
 #thread_local context : OnyxContext;
 
 assert :: (cond: bool, msg: str, site := #callsite) {
-    if !cond do context.assert_handler(msg, site);
+    if !cond {
+        context.assert_handler(msg, site);
+    }
 }
 
 
index e77239deb41c9b60c5b836d2f3415087fcc2535b..268c6b7467406ab72bccdb6dd2c496e62cec0dff 100644 (file)
@@ -399,8 +399,8 @@ read_until :: (s: ^str, upto: str, skip := 0) -> str {
 
     } else {
         out.count = i;
-        s.data  += out.count + (upto.count - 1);
-        s.count -= out.count + (upto.count - 1);
+        s.data  += out.count;
+        s.count -= out.count;
     }
 
     return out;
index 631208eed51526eedae8c735a335f572cdeb14d3..2ec599caebde62f294d6fd25aba345165d63b70e 100644 (file)
@@ -46,6 +46,7 @@ syn match onyxCallGroup         "\<[a-zA-Z_][a-zA-Z0-9_\.]*\> *(" contains=onyxC
 syn match onyxCall              "\<[a-zA-Z_][a-zA-Z0-9_\.]*\>" contained
 
 syn match onyxDirective         "\#[a-zA-Z_]\+"
+syn match onyxTag               "@.\+$"
 
 syn region onyxString              display start=+"+ skip=+\\\\\|\\"+ end=+"+ keepend
 
@@ -60,6 +61,7 @@ hi def link onyxNumber           Number
 hi def link onyxDefinition       Identifier
 hi def link onyxCall             Function
 hi def link onyxOperator         Operator
+hi def link onyxTag              Constant
 
 let b:current_syntax = "onyx"
 let &cpo = s:cpo_save