aboutsummaryrefslogtreecommitdiff
path: root/core/runtime/default_allocators_windows.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_windows.odin
parent1980f32bd6636edf7f8a1ba0d0010f23b5292488 (diff)
Correctly support `-default-to-nil-allocator` for all platforms
Diffstat (limited to 'core/runtime/default_allocators_windows.odin')
-rw-r--r--core/runtime/default_allocators_windows.odin66
1 files changed, 36 insertions, 30 deletions
diff --git a/core/runtime/default_allocators_windows.odin b/core/runtime/default_allocators_windows.odin
index f57f4c86c..9cabbcce8 100644
--- a/core/runtime/default_allocators_windows.odin
+++ b/core/runtime/default_allocators_windows.odin
@@ -1,38 +1,44 @@
//+build windows
package runtime
-default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
- size, alignment: int,
- old_memory: rawptr, old_size: int, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
- switch mode {
- case .Alloc:
- data, err = _windows_default_alloc(size, alignment)
-
- case .Free:
- _windows_default_free(old_memory)
-
- case .Free_All:
- // NOTE(tetra): Do nothing.
-
- case .Resize:
- data, err = _windows_default_resize(old_memory, old_size, size, alignment)
-
- case .Query_Features:
- set := (^Allocator_Mode_Set)(old_memory)
- if set != nil {
- set^ = {.Alloc, .Free, .Resize, .Query_Features}
+when ODIN_DEFAULT_TO_NIL_ALLOCATOR {
+ // mem.nil_allocator reimplementation
+ default_allocator_proc :: nil_allocator_proc
+ default_allocator :: nil_allocator
+} else {
+ default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
+ size, alignment: int,
+ old_memory: rawptr, old_size: int, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
+ switch mode {
+ case .Alloc:
+ data, err = _windows_default_alloc(size, alignment)
+
+ case .Free:
+ _windows_default_free(old_memory)
+
+ case .Free_All:
+ // NOTE(tetra): Do nothing.
+
+ case .Resize:
+ data, err = _windows_default_resize(old_memory, old_size, size, alignment)
+
+ case .Query_Features:
+ set := (^Allocator_Mode_Set)(old_memory)
+ if set != nil {
+ set^ = {.Alloc, .Free, .Resize, .Query_Features}
+ }
+
+ case .Query_Info:
+ // Do nothing
}
- case .Query_Info:
- // Do nothing
+ return
}
- return
-}
-
-default_allocator :: proc() -> Allocator {
- return Allocator{
- procedure = default_allocator_proc,
- data = nil,
+ default_allocator :: proc() -> Allocator {
+ return Allocator{
+ procedure = default_allocator_proc,
+ data = nil,
+ }
}
-}
+} \ No newline at end of file