Skip to content

Commit

Permalink
Fixed a Windows issue with struct initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
tanis2000 committed Apr 8, 2024
1 parent 3daf061 commit 0b6ada7
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/binocle/core/binocle_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include "binocle_memory.h"
#include "binocle_math.h"
#include <assert.h>
#include "binocle_sdl.h"
//#include <sys/mman.h>
#include <assert.h>
// #include <sys/mman.h>

static binocle_memory_state g_memory_state;

Expand All @@ -26,13 +26,14 @@ binocle_memory_arena_push_params binocle_memory_default_arena_params(void) {

binocle_memory_arena_bootstrap_params
binocle_memory_default_bootstrap_params(void) {
binocle_memory_arena_bootstrap_params params = {};
binocle_memory_arena_bootstrap_params params = {0};
return params;
}

binocle_memory_arena_bootstrap_params
binocle_memory_non_restored_arena_bootstrap_params(void) {
binocle_memory_arena_bootstrap_params params = binocle_memory_default_bootstrap_params();
binocle_memory_arena_bootstrap_params params =
binocle_memory_default_bootstrap_params();
params.allocation_flags = BINOCLE_MEMORY_FLAG_NOT_RESTORED;
return params;
}
Expand Down Expand Up @@ -94,18 +95,19 @@ binocle_memory_block *binocle_memory_allocate(binocle_memory_index size,
protect_offset = page_size + size_rounded_up;
}

binocle_memory_platform_block *block = (binocle_memory_platform_block *)SDL_malloc(total_size);
binocle_memory_platform_block *block =
(binocle_memory_platform_block *)SDL_malloc(total_size);
assert(block != 0);
block->block.base = (uint8_t *)block + base_offset;
assert(block->block.used == 0);
assert(block->block.prev_arena == 0);

// if (flags & (BINOCLE_MEMORY_FLAG_CHECK_UNDERFLOW |
// BINOCLE_MEMORY_FLAG_CHECK_OVERFLOW)) {
// int Protected =
// mprotect((uint8_t *)block + protect_offset, page_size, PROT_NONE);
// assert(Protected != -1);
// }
// if (flags & (BINOCLE_MEMORY_FLAG_CHECK_UNDERFLOW |
// BINOCLE_MEMORY_FLAG_CHECK_OVERFLOW)) {
// int Protected =
// mprotect((uint8_t *)block + protect_offset, page_size, PROT_NONE);
// assert(Protected != -1);
// }

binocle_memory_platform_block *Sentinel = &g_memory_state.memory_sentinel;
block->next = Sentinel;
Expand Down Expand Up @@ -174,7 +176,7 @@ void *binocle_memory_bootstrap_push_size(
BINOCLE_MEMORY_PARAM uintptr_t struct_size, uintptr_t offset_to_arena,
binocle_memory_arena_bootstrap_params bootstrap_params,
binocle_memory_arena_push_params push_params) {
binocle_memory_arena bootstrap = {};
binocle_memory_arena bootstrap = {0};
bootstrap.allocation_flags = bootstrap_params.allocation_flags;
bootstrap.minimum_block_size = bootstrap_params.minimum_block_size;
void *res_struct = binocle_memory_push_size_(BINOCLE_MEMORY_PASS & bootstrap,
Expand Down

0 comments on commit 0b6ada7

Please sign in to comment.