aboutsummaryrefslogtreecommitdiff
path: root/base/runtime/default_allocators_nil.odin
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-01-28 21:05:53 +0000
committergingerBill <bill@gingerbill.org>2024-01-28 21:05:53 +0000
commit09fa1c29cd014b4560b3c79c72db68af20ef8187 (patch)
tree45095630fb03a50df20e0249f98879cf27d94397 /base/runtime/default_allocators_nil.odin
parentddcaa0de5395bfb1a2b004e6a6cb5e2ba1e2eed1 (diff)
Move `core:runtime` to `base:runtime`; keep alias around
Diffstat (limited to 'base/runtime/default_allocators_nil.odin')
-rw-r--r--base/runtime/default_allocators_nil.odin88
1 files changed, 88 insertions, 0 deletions
diff --git a/base/runtime/default_allocators_nil.odin b/base/runtime/default_allocators_nil.odin
new file mode 100644
index 000000000..c882f5196
--- /dev/null
+++ b/base/runtime/default_allocators_nil.odin
@@ -0,0 +1,88 @@
+package runtime
+
+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, .Alloc_Non_Zeroed:
+ return nil, .Out_Of_Memory
+ case .Free:
+ return nil, .None
+ case .Free_All:
+ return nil, .Mode_Not_Implemented
+ case .Resize, .Resize_Non_Zeroed:
+ 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
+}
+
+nil_allocator :: proc() -> Allocator {
+ return Allocator{
+ procedure = nil_allocator_proc,
+ data = nil,
+ }
+}
+
+
+
+when ODIN_OS == .Freestanding {
+ default_allocator_proc :: nil_allocator_proc
+ default_allocator :: nil_allocator
+}
+
+
+
+panic_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:
+ if size > 0 {
+ panic("panic allocator, .Alloc called", loc=loc)
+ }
+ case .Alloc_Non_Zeroed:
+ if size > 0 {
+ panic("panic allocator, .Alloc_Non_Zeroed called", loc=loc)
+ }
+ case .Resize:
+ if size > 0 {
+ panic("panic allocator, .Resize called", loc=loc)
+ }
+ case .Resize_Non_Zeroed:
+ if size > 0 {
+ panic("panic allocator, .Alloc_Non_Zeroed called", loc=loc)
+ }
+ case .Free:
+ if old_memory != nil {
+ panic("panic allocator, .Free called", loc=loc)
+ }
+ case .Free_All:
+ panic("panic allocator, .Free_All called", loc=loc)
+
+ case .Query_Features:
+ set := (^Allocator_Mode_Set)(old_memory)
+ if set != nil {
+ set^ = {.Query_Features}
+ }
+ return nil, nil
+
+ case .Query_Info:
+ panic("panic allocator, .Query_Info called", loc=loc)
+ }
+
+ return nil, nil
+}
+
+panic_allocator :: proc() -> Allocator {
+ return Allocator{
+ procedure = panic_allocator_proc,
+ data = nil,
+ }
+}