diff --git a/README.md b/README.md index e5255b2a0..3d644ef8a 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,17 @@ There were additions made for quality of life reasons: * I added support for 'monlithic packages' or 'uniform-across-subdirectories packages'. It allows me to organize the main package with sub-directories. (Could be flag instead but making it a file flag works well) * Added the ability to debug using statements on structs (fields get dumped to the stack as ptr refs) * They show up as `struct_name::field_name` +* Remove implicit assignments for container allocators in the Base and Core packages + * I did not enjoy bug hunting a memory corruption because I mistakenly didn't properly initialize a core container with their designated initiatizer: new, make, or init. + * Affects the following: + * base:runtime/core_builtin.doin:`_reserve_dynamic_array`, `_resize_dynamic_array`, `_shrink_dynamic_array` + * base:runtime/core_builtin_soa.odin:`make_soa_aligned`, `_reserve_soa` + * base:runtime/default_temp_allocator_arena.odin:`arena_alloc` + * base:runtime/dynamic_array_internal.odin:`__dynamic_array_reserve`, `__dynamic_array_shrink` + * base:runtime/dynamic_map_internal.odin:`map_shrink_dynamic` + * core:flags/internal_assignment.doin:`set_key_value` + * core:mem/tracking_allocator.odin:`tracking_allocator_proc` + * core:strings/intern.odin:`_intern_get_entry` --- diff --git a/base/runtime/core_builtin.odin b/base/runtime/core_builtin.odin index cf379aacb..aed3444d8 100644 --- a/base/runtime/core_builtin.odin +++ b/base/runtime/core_builtin.odin @@ -786,9 +786,10 @@ _reserve_dynamic_array :: #force_inline proc(a: ^Raw_Dynamic_Array, size_of_elem return nil } - if a.allocator.procedure == nil { - a.allocator = context.allocator - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if a.allocator.procedure == nil { + // a.allocator = context.allocator + // } assert(a.allocator.procedure != nil) old_size := a.cap * size_of_elem @@ -836,9 +837,10 @@ _resize_dynamic_array :: #force_inline proc(a: ^Raw_Dynamic_Array, size_of_elem, return nil } - if a.allocator.procedure == nil { - a.allocator = context.allocator - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if a.allocator.procedure == nil { + // a.allocator = context.allocator + // } assert(a.allocator.procedure != nil) old_size := a.cap * size_of_elem @@ -900,9 +902,10 @@ _shrink_dynamic_array :: proc(a: ^Raw_Dynamic_Array, size_of_elem, align_of_elem return } - if a.allocator.procedure == nil { - a.allocator = context.allocator - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if a.allocator.procedure == nil { + // a.allocator = context.allocator + // } assert(a.allocator.procedure != nil) old_size := a.cap * size_of_elem diff --git a/base/runtime/core_builtin_soa.odin b/base/runtime/core_builtin_soa.odin index ff27a4559..ef8603ba4 100644 --- a/base/runtime/core_builtin_soa.odin +++ b/base/runtime/core_builtin_soa.odin @@ -102,10 +102,11 @@ make_soa_aligned :: proc($T: typeid/#soa[]$E, #any_int length, alignment: int, a total_size = align_forward_int(total_size, max_align) } - allocator := allocator - if allocator.procedure == nil { - allocator = context.allocator - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // allocator := allocator + // if allocator.procedure == nil { + // allocator = context.allocator + // } assert(allocator.procedure != nil) new_bytes: []byte @@ -215,9 +216,10 @@ _reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: boo return nil } - if array.allocator.procedure == nil { - array.allocator = context.allocator - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if array.allocator.procedure == nil { + // array.allocator = context.allocator + // } assert(array.allocator.procedure != nil) footer := raw_soa_footer(array) diff --git a/base/runtime/default_temp_allocator_arena.odin b/base/runtime/default_temp_allocator_arena.odin index db157b267..b84316634 100644 --- a/base/runtime/default_temp_allocator_arena.odin +++ b/base/runtime/default_temp_allocator_arena.odin @@ -113,9 +113,10 @@ arena_alloc :: proc(arena: ^Arena, size, alignment: uint, loc := #caller_locatio block_size := max(needed, arena.minimum_block_size) - if arena.backing_allocator.procedure == nil { - arena.backing_allocator = default_allocator() - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if arena.backing_allocator.procedure == nil { + // arena.backing_allocator = default_allocator() + // } new_block := memory_block_alloc(arena.backing_allocator, block_size, alignment, loc) or_return new_block.prev = arena.curr_block diff --git a/base/runtime/dynamic_array_internal.odin b/base/runtime/dynamic_array_internal.odin index 267ee0785..d047d38de 100644 --- a/base/runtime/dynamic_array_internal.odin +++ b/base/runtime/dynamic_array_internal.odin @@ -16,9 +16,11 @@ __dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap: // NOTE(tetra, 2020-01-26): We set the allocator before earlying-out below, because user code is usually written // assuming that appending/reserving will set the allocator, if it is not already set. - if array.allocator.procedure == nil { - array.allocator = context.allocator - } + + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if array.allocator.procedure == nil { + // array.allocator = context.allocator + // } assert(array.allocator.procedure != nil) if cap <= array.cap { @@ -50,9 +52,11 @@ __dynamic_array_shrink :: proc(array_: rawptr, elem_size, elem_align: int, new_c // NOTE(tetra, 2020-01-26): We set the allocator before earlying-out below, because user code is usually written // assuming that appending/reserving will set the allocator, if it is not already set. - if array.allocator.procedure == nil { - array.allocator = context.allocator - } + + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if array.allocator.procedure == nil { + // array.allocator = context.allocator + // } assert(array.allocator.procedure != nil) if new_cap > array.cap { diff --git a/base/runtime/dynamic_map_internal.odin b/base/runtime/dynamic_map_internal.odin index b95e3cd14..8b7c8a02a 100644 --- a/base/runtime/dynamic_map_internal.odin +++ b/base/runtime/dynamic_map_internal.odin @@ -587,9 +587,11 @@ map_reserve_dynamic :: #force_no_inline proc "odin" (#no_alias m: ^Raw_Map, #no_ return size_of(uintptr)*8 - 1 - z } - if m.allocator.procedure == nil { - m.allocator = context.allocator - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if m.allocator.procedure == nil { + // m.allocator = context.allocator + // } + assert( m.allocator.procedure != nil) new_capacity := new_capacity old_capacity := uintptr(map_cap(m^)) @@ -642,9 +644,11 @@ map_reserve_dynamic :: #force_no_inline proc "odin" (#no_alias m: ^Raw_Map, #no_ @(require_results) map_shrink_dynamic :: #force_no_inline proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Info, loc := #caller_location) -> (did_shrink: bool, err: Allocator_Error) { - if m.allocator.procedure == nil { - m.allocator = context.allocator - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if m.allocator.procedure == nil { + // m.allocator = context.allocator + // } + assert( m.allocator.procedure != nil) // Cannot shrink the capacity if the number of items in the map would exceed // one minus the current log2 capacity's resize threshold. That is the shrunk diff --git a/core/encoding/cbor/unmarshal.odin b/core/encoding/cbor/unmarshal.odin index c39255d9d..4ea5c610e 100644 --- a/core/encoding/cbor/unmarshal.odin +++ b/core/encoding/cbor/unmarshal.odin @@ -692,6 +692,8 @@ _unmarshal_map :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header, case reflect.Type_Info_Map: raw_map := (^mem.Raw_Map)(v.data) if raw_map.allocator.procedure == nil { + // Note(Ed) - Sectr Fork: I'm premmtively leaving this here incase it happens... + runtime.debug_trap() raw_map.allocator = context.allocator } diff --git a/core/encoding/json/unmarshal.odin b/core/encoding/json/unmarshal.odin index 57371e360..8ec956793 100644 --- a/core/encoding/json/unmarshal.odin +++ b/core/encoding/json/unmarshal.odin @@ -526,6 +526,8 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm } raw_map := (^mem.Raw_Map)(v.data) if raw_map.allocator.procedure == nil { + // Note(Ed) - Sectr Fork: I'm premmtively leaving this here incase it happens... + runtime.debug_trap() raw_map.allocator = p.allocator } diff --git a/core/flags/internal_assignment.odin b/core/flags/internal_assignment.odin index 12ddb876f..a3bfce567 100644 --- a/core/flags/internal_assignment.odin +++ b/core/flags/internal_assignment.odin @@ -203,9 +203,14 @@ set_key_value :: proc(model: ^$T, parser: ^Parser, name, key, value: string) -> elem_backing: []byte value_ptr: rawptr - if raw_map.allocator.procedure == nil { - raw_map.allocator = context.allocator - } else { + + assert(raw_map.allocator.procedure != nil) + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if raw_map.allocator.procedure == nil { + // raw_map.allocator = context.allocator + // } + // else + { value_ptr = runtime.__dynamic_map_get(raw_map, specific_type_info.map_info, hash, diff --git a/core/mem/tracking_allocator.odin b/core/mem/tracking_allocator.odin index 25c547471..263a1ca63 100644 --- a/core/mem/tracking_allocator.odin +++ b/core/mem/tracking_allocator.odin @@ -232,9 +232,11 @@ tracking_allocator_proc :: proc( } result_ptr := raw_data(result) - if data.allocation_map.allocator.procedure == nil { - data.allocation_map.allocator = context.allocator - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if data.allocation_map.allocator.procedure == nil { + // data.allocation_map.allocator = context.allocator + // } + assert(data.allocation_map.allocator.procedure != nil) switch mode { case .Alloc, .Alloc_Non_Zeroed: diff --git a/core/strings/intern.odin b/core/strings/intern.odin index 0b8ed173e..c0c3058a6 100644 --- a/core/strings/intern.odin +++ b/core/strings/intern.odin @@ -105,9 +105,10 @@ Returns: - err: An allocator error if one occured, `nil` otherwise */ _intern_get_entry :: proc(m: ^Intern, text: string) -> (new_entry: ^Intern_Entry, err: runtime.Allocator_Error) #no_bounds_check { - if m.allocator.procedure == nil { - m.allocator = context.allocator - } + // Note(Ed) - Sectr Fork: Not a fan. (I want it to assert) + // if m.allocator.procedure == nil { + // m.allocator = context.allocator + // } key_ptr, val_ptr, inserted := map_entry(&m.entries, text) or_return if !inserted {