Improve the Allocator interface to support returning Allocator_Error to allow for safer calls

Virtually all code (except for user-written custom allocators) should work as normal. Extra features will need to be added to make the current procedures support the `Allocator_Error` return value (akin to #optional_ok)
This commit is contained in:
gingerBill
2021-04-19 12:31:31 +01:00
parent a4d0092b16
commit f98c4d6837
13 changed files with 386 additions and 276 deletions
+8 -2
View File
@@ -252,7 +252,6 @@ Source_Code_Location :: struct {
Assertion_Failure_Proc :: #type proc(prefix, message: string, loc: Source_Code_Location);
// Allocation Stuff
Allocator_Mode :: enum byte {
Alloc,
@@ -271,9 +270,16 @@ Allocator_Query_Info :: struct {
alignment: Maybe(int),
}
Allocator_Error :: enum byte {
None = 0,
Out_Of_Memory = 1,
Invalid_Pointer = 2,
}
Allocator_Proc :: #type proc(allocator_data: rawptr, mode: Allocator_Mode,
size, alignment: int,
old_memory: rawptr, old_size: int, flags: u64 = 0, location: Source_Code_Location = #caller_location) -> rawptr;
old_memory: rawptr, old_size: int,
location: Source_Code_Location = #caller_location) -> ([]byte, Allocator_Error);
Allocator :: struct {
procedure: Allocator_Proc,
data: rawptr,