aboutsummaryrefslogtreecommitdiff
path: root/core/runtime/default_allocators_nil.odin
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-11-04 11:03:21 +0000
committergingerBill <bill@gingerbill.org>2021-11-04 11:03:21 +0000
commit3fa7dabaa87e99386e469bd5e4badab23f89aaef (patch)
tree84933a742d8246b97ec862142ec9579319510bf7 /core/runtime/default_allocators_nil.odin
parent1980f32bd6636edf7f8a1ba0d0010f23b5292488 (diff)
Correctly support `-default-to-nil-allocator` for all platforms
Diffstat (limited to 'core/runtime/default_allocators_nil.odin')
-rw-r--r--core/runtime/default_allocators_nil.odin33
1 files changed, 27 insertions, 6 deletions
diff --git a/core/runtime/default_allocators_nil.odin b/core/runtime/default_allocators_nil.odin
index 5100bc517..ccb4a3381 100644
--- a/core/runtime/default_allocators_nil.odin
+++ b/core/runtime/default_allocators_nil.odin
@@ -1,17 +1,38 @@
-//+build freestanding
package runtime
-// mem.nil_allocator reimplementation
-
-default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
+nil_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
size, alignment: int,
old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
+ switch mode {
+ case .Alloc:
+ return nil, .Out_Of_Memory
+ case .Free:
+ return nil, .None
+ case .Free_All:
+ return nil, .Mode_Not_Implemented
+ case .Resize:
+ if size == 0 {
+ return nil, .None
+ }
+ return nil, .Out_Of_Memory
+ case .Query_Features:
+ return nil, .Mode_Not_Implemented
+ case .Query_Info:
+ return nil, .Mode_Not_Implemented
+ }
return nil, .None
}
-default_allocator :: proc() -> Allocator {
+nil_allocator :: proc() -> Allocator {
return Allocator{
- procedure = default_allocator_proc,
+ procedure = nil_allocator_proc,
data = nil,
}
}
+
+
+
+when ODIN_OS == "freestanding" {
+ default_allocator_proc :: nil_allocator_proc
+ default_allocator :: nil_allocator
+} \ No newline at end of file