Renamed str_fmt_alloc to str_fmt, str_fmt to str_fmt_out, allocator convention enforcement in context
I'm enforcing aprintf it as the default formatter. I changed up the context allocator assignment to reflect how I've been intending to allocation in startup & platform events vs tick. Tick uses the frame slab's by default with transient on temp. Startup & platform events use the transient by default & for temp, with any use of the persistent allocator being explicit.
This commit is contained in:
@ -27,9 +27,9 @@ import "core:hash"
|
||||
import "core:hash/xxhash"
|
||||
xxh32 :: xxhash.XXH32
|
||||
import fmt_io "core:fmt"
|
||||
str_fmt :: fmt_io.printf
|
||||
str_fmt_out :: fmt_io.printf
|
||||
str_fmt_tmp :: fmt_io.tprintf
|
||||
str_fmt_alloc :: fmt_io.aprintf
|
||||
str_fmt :: fmt_io.aprintf // Decided to make aprintf the default. (It will always be the default allocator)
|
||||
str_fmt_builder :: fmt_io.sbprintf
|
||||
str_fmt_buffer :: fmt_io.bprintf
|
||||
str_to_file_ln :: fmt_io.fprintln
|
||||
|
@ -73,7 +73,7 @@ hmap_chained_init :: proc( $Type : typeid, lookup_capacity : uint, allocator : A
|
||||
bucket_reserve_num = pool_bucket_reserve_num,
|
||||
alignment = pool_alignment,
|
||||
allocator = allocator,
|
||||
dbg_name = str_intern(str_fmt_tmp("%v: pool", dbg_name)).str
|
||||
dbg_name = str_intern(str_fmt("%v: pool", dbg_name)).str
|
||||
)
|
||||
data := transmute([^] ^HMapChainedSlot(Type)) (transmute( [^]HMapChained(Type)) table.header)[1:]
|
||||
table.lookup = slice_ptr( data, int(lookup_capacity) )
|
||||
|
@ -51,7 +51,7 @@ zpl_hmap_init :: proc( $ Type : typeid, allocator : Allocator ) -> ( HMapZPL( Ty
|
||||
zpl_hmap_init_reserve :: proc
|
||||
( $ Type : typeid, allocator : Allocator, num : u64, dbg_name : string = "" ) -> ( HMapZPL( Type), AllocatorError )
|
||||
{
|
||||
result : HMapZPL(Type)
|
||||
result : HMapZPL(Type)
|
||||
table_result, entries_result : AllocatorError
|
||||
|
||||
result.table, table_result = array_init_reserve( i64, allocator, num, dbg_name = dbg_name )
|
||||
|
@ -73,17 +73,17 @@ memtracker_register :: proc( tracker : ^MemoryTracker, new_entry : MemoryTracker
|
||||
|
||||
if (entry.end < new_entry.start)
|
||||
{
|
||||
msg := str_fmt_tmp("Memory tracker(%v) detected a collision:\nold_entry: %v\nnew_entry: %v", tracker.name, entry, new_entry)
|
||||
msg := str_fmt("Memory tracker(%v) detected a collision:\nold_entry: %v\nnew_entry: %v", tracker.name, entry, new_entry)
|
||||
ensure( false, msg )
|
||||
memtracker_dump_entries(tracker ^)
|
||||
}
|
||||
array_append_at( & tracker.entries, new_entry, idx )
|
||||
log(str_fmt_tmp("%v : Registered: %v", tracker.name, new_entry) )
|
||||
log(str_fmt("%v : Registered: %v", tracker.name, new_entry) )
|
||||
return
|
||||
}
|
||||
|
||||
array_append( & tracker.entries, new_entry )
|
||||
log(str_fmt_tmp("%v : Registered: %v", tracker.name, new_entry) )
|
||||
log(str_fmt("%v : Registered: %v", tracker.name, new_entry) )
|
||||
}
|
||||
|
||||
memtracker_register_auto_name :: proc( tracker : ^MemoryTracker, start, end : rawptr )
|
||||
@ -119,17 +119,17 @@ memtracker_unregister :: proc( tracker : MemoryTracker, to_remove : MemoryTracke
|
||||
entry := & entries[idx]
|
||||
if entry.start == to_remove.start {
|
||||
if (entry.end == to_remove.end || to_remove.end == nil) {
|
||||
log(str_fmt_tmp("%v: Unregistered: %v", tracker.name, to_remove));
|
||||
log(str_fmt("%v: Unregistered: %v", tracker.name, to_remove));
|
||||
array_remove_at(tracker.entries, idx)
|
||||
return
|
||||
}
|
||||
|
||||
ensure(false, str_fmt_tmp("%v: Found an entry with the same start address but end address was different:\nentry : %v\nto_remove: %v", tracker.name, entry, to_remove))
|
||||
ensure(false, str_fmt("%v: Found an entry with the same start address but end address was different:\nentry : %v\nto_remove: %v", tracker.name, entry, to_remove))
|
||||
memtracker_dump_entries(tracker)
|
||||
}
|
||||
}
|
||||
|
||||
ensure(false, str_fmt_tmp("%v: Attempted to unregister an entry that was not tracked: %v", tracker.name, to_remove))
|
||||
ensure(false, str_fmt("%v: Attempted to unregister an entry that was not tracked: %v", tracker.name, to_remove))
|
||||
memtracker_dump_entries(tracker)
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ memtracker_check_for_collisions :: proc ( tracker : MemoryTracker )
|
||||
|
||||
collided := left.start > right.start || left.end > right.end
|
||||
if collided {
|
||||
msg := str_fmt_tmp("%v: Memory tracker detected a collision:\nleft: %v\nright: %v", tracker.name, left, right)
|
||||
msg := str_fmt("%v: Memory tracker detected a collision:\nleft: %v\nright: %v", tracker.name, left, right)
|
||||
memtracker_dump_entries(tracker)
|
||||
}
|
||||
}
|
||||
@ -167,6 +167,6 @@ memtracker_dump_entries :: proc( tracker : MemoryTracker )
|
||||
log( "Dumping Memory Tracker:")
|
||||
for idx in 0 ..< tracker.entries.num {
|
||||
entry := & tracker.entries.data[idx]
|
||||
log( str_fmt_tmp("%v", entry) )
|
||||
log( str_fmt("%v", entry) )
|
||||
}
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ pool_grab :: proc( pool : Pool, zero_memory := false ) -> ( block : []byte, allo
|
||||
pool := pool
|
||||
if pool.current_bucket != nil {
|
||||
if ( pool.current_bucket.blocks == nil ) {
|
||||
ensure( false, str_fmt_tmp("(corruption) current_bucket was wiped %p", pool.current_bucket) )
|
||||
ensure( false, str_fmt("(corruption) current_bucket was wiped %p", pool.current_bucket) )
|
||||
}
|
||||
// verify( pool.current_bucket.blocks != nil, str_fmt_tmp("(corruption) current_bucket was wiped %p", pool.current_bucket) )
|
||||
}
|
||||
@ -313,17 +313,17 @@ pool_validate :: proc( pool : Pool )
|
||||
bucket : ^PoolBucket = pool.bucket_list.first
|
||||
|
||||
if bucket != nil && uintptr(bucket) < 0x10000000000 {
|
||||
ensure(false, str_fmt_tmp("Found a corrupted bucket %p", bucket ))
|
||||
ensure(false, str_fmt("Found a corrupted bucket %p", bucket ))
|
||||
}
|
||||
// Compiler bug ^^ same as pool_reset
|
||||
for ; bucket != nil; bucket = bucket.next
|
||||
{
|
||||
if bucket != nil && uintptr(bucket) < 0x10000000000 {
|
||||
ensure(false, str_fmt_tmp("Found a corrupted bucket %p", bucket ))
|
||||
ensure(false, str_fmt("Found a corrupted bucket %p", bucket ))
|
||||
}
|
||||
|
||||
if ( bucket.blocks == nil ) {
|
||||
ensure(false, str_fmt_tmp("Found a corrupted bucket %p", bucket ))
|
||||
ensure(false, str_fmt("Found a corrupted bucket %p", bucket ))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -346,7 +346,7 @@ pool_validate_ownership :: proc( using self : Pool, block : [] byte ) -> b32
|
||||
misalignment := (block_address - start) % uintptr(block_size)
|
||||
if misalignment != 0 {
|
||||
ensure(false, "pool_validate_ownership: This data is within this pool's buckets, however its not aligned to the start of a block")
|
||||
log(str_fmt_tmp("Block address: %p Misalignment: %p closest: %p",
|
||||
log(str_fmt("Block address: %p Misalignment: %p closest: %p",
|
||||
transmute(rawptr)block_address,
|
||||
transmute(rawptr)misalignment,
|
||||
rawptr(block_address - misalignment)))
|
||||
|
@ -84,7 +84,7 @@ slab_init_pools :: proc ( using self : Slab, policy : ^SlabPolicy, bucket_reserv
|
||||
for id in 0 ..< policy.idx {
|
||||
using size_class := policy.items[id]
|
||||
|
||||
pool_dbg_name := str_fmt_alloc("%v pool[%v]", dbg_name, block_size, allocator = backing)
|
||||
pool_dbg_name := str_fmt("%v pool[%v]", dbg_name, block_size, allocator = backing)
|
||||
pool, alloc_error := pool_init( should_zero_buckets, block_size, bucket_capacity, bucket_reserve_num, block_alignment, backing, pool_dbg_name )
|
||||
if alloc_error != .None do return alloc_error
|
||||
|
||||
|
@ -113,7 +113,7 @@ str_intern :: proc( content : string ) -> StrRunesPair
|
||||
}
|
||||
|
||||
str_intern_fmt :: #force_inline proc( format : string, args : ..any, allocator := context.allocator ) -> StrRunesPair {
|
||||
return str_intern(str_fmt_alloc(format, args, allocator = allocator))
|
||||
return str_intern(str_fmt(format, args, allocator = allocator))
|
||||
}
|
||||
|
||||
// runes_intern :: proc( content : []rune ) -> StrRunesPair
|
||||
|
@ -20,7 +20,7 @@ thread__highres_wait :: proc( desired_ms : f64, loc := #caller_location ) -> b32
|
||||
|
||||
timer := win32.CreateWaitableTimerExW( nil, nil, win32.CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, win32.TIMER_ALL_ACCESS )
|
||||
if timer == nil {
|
||||
msg := str_fmt_tmp("Failed to create win32 timer - ErrorCode: %v", win32.GetLastError() )
|
||||
msg := str_fmt("Failed to create win32 timer - ErrorCode: %v", win32.GetLastError() )
|
||||
log( msg, LogLevel.Warning, loc)
|
||||
return false
|
||||
}
|
||||
@ -28,7 +28,7 @@ thread__highres_wait :: proc( desired_ms : f64, loc := #caller_location ) -> b32
|
||||
due_time := win32.LARGE_INTEGER(desired_ms * MS_To_NS)
|
||||
result := win32.SetWaitableTimerEx( timer, & due_time, 0, nil, nil, nil, 0 )
|
||||
if ! result {
|
||||
msg := str_fmt_tmp("Failed to set win32 timer - ErrorCode: %v", win32.GetLastError() )
|
||||
msg := str_fmt("Failed to set win32 timer - ErrorCode: %v", win32.GetLastError() )
|
||||
log( msg, LogLevel.Warning, loc)
|
||||
return false
|
||||
}
|
||||
@ -43,22 +43,22 @@ thread__highres_wait :: proc( desired_ms : f64, loc := #caller_location ) -> b32
|
||||
switch wait_result
|
||||
{
|
||||
case WAIT_ABANDONED:
|
||||
msg := str_fmt_tmp("Failed to wait for win32 timer - Error: WAIT_ABANDONED" )
|
||||
msg := str_fmt("Failed to wait for win32 timer - Error: WAIT_ABANDONED" )
|
||||
log( msg, LogLevel.Error, loc)
|
||||
return false
|
||||
|
||||
case WAIT_IO_COMPLETION:
|
||||
msg := str_fmt_tmp("Waited for win32 timer: Ended by APC queued to the thread" )
|
||||
msg := str_fmt("Waited for win32 timer: Ended by APC queued to the thread" )
|
||||
log( msg, LogLevel.Error, loc)
|
||||
return false
|
||||
|
||||
case WAIT_OBJECT_0:
|
||||
msg := str_fmt_tmp("Waited for win32 timer- Reason : WAIT_OBJECT_0" )
|
||||
msg := str_fmt("Waited for win32 timer- Reason : WAIT_OBJECT_0" )
|
||||
log( msg, loc = loc)
|
||||
return false
|
||||
|
||||
case WAIT_FAILED:
|
||||
msg := str_fmt_tmp("Waited for win32 timer failed - ErrorCode: $v", win32.GetLastError() )
|
||||
msg := str_fmt("Waited for win32 timer failed - ErrorCode: $v", win32.GetLastError() )
|
||||
log( msg, LogLevel.Error, loc)
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user