aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-01-18 13:11:51 +0000
committergingerBill <bill@gingerbill.org>2018-01-18 13:11:51 +0000
commit386f5f596da284e90565b02d7766ebf79fddb8f7 (patch)
tree96933323160f1afa272ff626caa07409d2425a12 /src
parentadd53228b2ee93f7374a815ce1c4e5a86b7b9d28 (diff)
Change to HeapAlloc et al on Windows
Diffstat (limited to 'src')
-rw-r--r--src/common.cpp35
-rw-r--r--src/ir.cpp3
-rw-r--r--src/types.cpp8
3 files changed, 36 insertions, 10 deletions
diff --git a/src/common.cpp b/src/common.cpp
index 915ad65cd..b922980db 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -12,6 +12,21 @@
#include <math.h>
+gb_inline i64 align_formula(i64 size, i64 align) {
+ if (align > 0) {
+ i64 result = size + align-1;
+ return result - result%align;
+ }
+ return size;
+}
+gb_inline isize align_formula_isize(isize size, isize align) {
+ if (align > 0) {
+ isize result = size + align-1;
+ return result - result%align;
+ }
+ return size;
+}
+
GB_ALLOCATOR_PROC(heap_allocator_proc);
gbAllocator heap_allocator(void) {
@@ -26,13 +41,18 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
void *ptr = NULL;
gb_unused(allocator_data);
gb_unused(old_size);
+
+
+
// TODO(bill): Throughly test!
switch (type) {
#if defined(GB_COMPILER_MSVC)
+ #if 0
case gbAllocation_Alloc:
ptr = _aligned_malloc(size, alignment);
- if (flags & gbAllocatorFlag_ClearToZero)
+ if (flags & gbAllocatorFlag_ClearToZero) {
gb_zero_size(ptr, size);
+ }
break;
case gbAllocation_Free:
_aligned_free(old_memory);
@@ -40,6 +60,19 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
case gbAllocation_Resize:
ptr = _aligned_realloc(old_memory, size, alignment);
break;
+ #else
+ case gbAllocation_Alloc:
+ // TODO(bill): Make sure this is aligned correctly
+ // ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, align_formula_isize(size, alignment));
+ ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, align_formula_isize(size, alignment));
+ break;
+ case gbAllocation_Free:
+ HeapFree(GetProcessHeap(), 0, old_memory);
+ break;
+ case gbAllocation_Resize:
+ ptr = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, old_memory, align_formula_isize(size, alignment));
+ break;
+ #endif
#elif defined(GB_SYSTEM_LINUX)
// TODO(bill): *nix version that's decent
diff --git a/src/ir.cpp b/src/ir.cpp
index dae3e94d6..39d7e3e84 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -1285,7 +1285,6 @@ irDefer ir_add_defer_instr(irProcedure *proc, isize scope_index, irValue *instr)
irValue *ir_add_module_constant(irModule *m, Type *type, ExactValue value) {
gbAllocator a = m->allocator;
- // gbAllocator a = gb_heap_allocator();
if (is_type_slice(type)) {
ast_node(cl, CompoundLit, value.value_compound);
@@ -1321,7 +1320,7 @@ irValue *ir_add_global_string_array(irModule *m, String string) {
// TODO(bill): Should this use the arena allocator or the heap allocator?
// Strings could be huge!
// gbAllocator a = m->allocator;
- gbAllocator a = gb_heap_allocator();
+ gbAllocator a = heap_allocator();
isize max_len = 6+8+1;
u8 *str = cast(u8 *)gb_alloc_array(a, u8, max_len);
diff --git a/src/types.cpp b/src/types.cpp
index d515d9390..34c4870ef 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -1782,13 +1782,7 @@ void type_path_pop(TypePath *tp) {
i64 type_size_of_internal (gbAllocator allocator, Type *t, TypePath *path);
i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path);
-i64 align_formula(i64 size, i64 align) {
- if (align > 0) {
- i64 result = size + align-1;
- return result - result%align;
- }
- return size;
-}
+
i64 type_size_of(gbAllocator allocator, Type *t) {
if (t == nullptr) {