From a02ca6026649a51dda33cf81ef36f162853b38c9 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 11 Sep 2022 20:54:01 -0500 Subject: [PATCH] bugfixes in standard libraries --- core/alloc/auto_heap.onyx | 9 +++++++-- core/alloc/heap.onyx | 9 ++++++++- core/builtin.onyx | 4 +++- core/string.onyx | 4 ++-- misc/onyx.vim | 2 ++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/core/alloc/auto_heap.onyx b/core/alloc/auto_heap.onyx index 03334251..af634d7e 100644 --- a/core/alloc/auto_heap.onyx +++ b/core/alloc/auto_heap.onyx @@ -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 { diff --git a/core/alloc/heap.onyx b/core/alloc/heap.onyx index 0dfe3018..d01f38f2 100644 --- a/core/alloc/heap.onyx +++ b/core/alloc/heap.onyx @@ -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; diff --git a/core/builtin.onyx b/core/builtin.onyx index 04b9b0de..5d9a16bc 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -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); + } } diff --git a/core/string.onyx b/core/string.onyx index e77239de..268c6b74 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -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; diff --git a/misc/onyx.vim b/misc/onyx.vim index 631208ee..2ec599ca 100644 --- a/misc/onyx.vim +++ b/misc/onyx.vim @@ -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 -- 2.25.1