From 5cbcc10444c8ca4036c7cbb4ecafc926330914bd Mon Sep 17 00:00:00 2001 From: Judah Caruso Date: Wed, 23 Jul 2025 15:22:00 -0600 Subject: [PATCH] use jc types --- memory/allocators.jai | 14 ++++++++------ memory/buffer.jai | 14 ++++++++------ memory/module.jai | 12 +++++++----- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/memory/allocators.jai b/memory/allocators.jai index 6ce2dba..e25ba3d 100644 --- a/memory/allocators.jai +++ b/memory/allocators.jai @@ -4,7 +4,7 @@ make_crash_allocator :: () -> Allocator { return .{ proc = crash_allocator_proc }; } -crash_allocator_proc :: (mode: Allocator_Mode, size: s64, old_size: s64, old_memory: *void, allocator_data: *void) -> *void { +crash_allocator_proc :: (mode: Allocator_Mode, size: s64, old_size: s64, old_memory: rawptr, allocator_data: rawptr) -> rawptr { message: string; if mode == { @@ -24,12 +24,12 @@ crash_allocator_proc :: (mode: Allocator_Mode, size: s64, old_size: s64, old_mem Arena :: struct { - memory: *void; + memory: rawptr; memory_size: u64; offset: u64; } -init_arena :: (a: *Arena, memory: *void, size: u64) { +init_arena :: (a: *Arena, memory: rawptr, size: u64) { a.memory = memory; a.memory_size = size; a.offset = 0; @@ -56,7 +56,7 @@ Extended_Allocator_Mode :: enum { restore_save_point; // 'old_size' will be the dereferenced return value of 'save_point' } -arena_allocator_proc :: (mode: Extended_Allocator_Mode, size: s64, old_size: s64, old_memory: *void, allocator_data: *void) -> *void { +arena_allocator_proc :: (mode: Extended_Allocator_Mode, size: s64, old_size: s64, old_memory: rawptr, allocator_data: rawptr) -> rawptr { arena := allocator_data.(*Arena); if mode == { case .request_memory; @@ -89,7 +89,7 @@ arena_allocator_proc :: (mode: Extended_Allocator_Mode, size: s64, old_size: s64 return null; } -arena_alloc :: (a: *Arena, count: int, alignment := mem.Default_Align, loc := #caller_location) -> *void { +arena_alloc :: (a: *Arena, count: int, alignment := mem.Default_Align, loc := #caller_location) -> rawptr { basic.assert(a.memory != null, "arena: not initialized", loc = loc); basic.assert(mem.power_of_two(alignment)); @@ -100,12 +100,14 @@ arena_alloc :: (a: *Arena, count: int, alignment := mem.Default_Align, loc := #c basic.assert(a.offset + total_size <= a.memory_size, "arena: out of memory", loc = loc); a.offset += total_size; - return ptr.(*void); + return ptr.(rawptr); } #scope_file; +#import "jc"; + mem :: #import "jc/memory"; meta :: #import "jc/meta"; diff --git a/memory/buffer.jai b/memory/buffer.jai index 4ccd9ad..837f3f2 100644 --- a/memory/buffer.jai +++ b/memory/buffer.jai @@ -3,19 +3,19 @@ Buffer :: struct { allocator: Allocator; - data: [..]u8; + data: [..]byte; count: int; } -append :: inline (buf: *Buffer, ptr: *void, count: int) { +append :: inline (buf: *Buffer, ptr: rawptr, size: int) { inline mem.lazy_set_allocator(buf); - free_space := ensure_buffer_has_room(buf, count); - memcpy(free_space, ptr, count); - buf.count += count; + free_space := ensure_buffer_has_room(buf, size); + memcpy(free_space, ptr, size); + buf.size += size; } -append :: inline (buf: *Buffer, data: []u8) { +append :: inline (buf: *Buffer, data: []byte) { append(buf, data.data, data.count); } @@ -29,6 +29,8 @@ reset :: inline (buf: *Buffer) { #scope_file; +#import "jc"; + array :: #import "jc/array"; mem :: #import "jc/memory"; meta :: #import "jc/meta"; diff --git a/memory/module.jai b/memory/module.jai index dca2e40..41baffc 100644 --- a/memory/module.jai +++ b/memory/module.jai @@ -93,7 +93,7 @@ allocator_restore :: (save_point: int) { allocator.proc(xx Extended_Allocator_Mode.restore_save_point, 0, save_point, null, allocator.data); } -request_memory :: (size: int, align := Default_Align) -> *void { +request_memory :: (size: int, align := Default_Align) -> rawptr { allocator := context.allocator; aligned_size := align_to(size, align); return allocator.proc(xx Extended_Allocator_Mode.request_memory, aligned_size.(int), 0, null, allocator.data); @@ -132,21 +132,21 @@ request_memory :: ($T: Type, $init := true) -> *T return ptr; } -release_memory :: inline (ptr: *void) { +release_memory :: inline (ptr: rawptr) { allocator := context.allocator; allocator.proc(xx Extended_Allocator_Mode.release_memory, 0, 0, ptr, allocator.data); } release_memory :: inline (arr: []$T) { - release_memory(arr.data.(*void)); + release_memory(arr.data.(*rawptr)); } release_memory :: inline (arr: [..]$T) { - release_memory(arr.data.(*void),, allocator = arr.allocator); + release_memory(arr.data.(*rawptr),, allocator = arr.allocator); } release_memory :: inline (str: string) { - release_memory(str.data.(*void)); + release_memory(str.data.(*rawptr)); } // @todo(judah): why can't we use $T/struct{ allocator: Allocator }? @@ -181,6 +181,8 @@ lazy_set_allocator :: (array: *[..]$T, allocator := context.allocator) #expand { #scope_file; +#import "jc"; + meta :: #import "jc/meta"; basic :: #import "Basic"; // @future