From 730463dbbb510b66fdb086cd3433f12bba407a16 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Thu, 14 Jan 2016 20:18:55 +0000 Subject: [PATCH] remove rct2_malloc, rct2_realloc and rct2_free --- src/drawing/sprite.c | 2 +- src/rct2.c | 44 --------------------------- src/rct2.h | 3 -- src/windows/editor_object_selection.c | 11 +++---- src/world/map.c | 4 +-- 5 files changed, 7 insertions(+), 57 deletions(-) diff --git a/src/drawing/sprite.c b/src/drawing/sprite.c index 7fc3f5c585..b7d7a97699 100644 --- a/src/drawing/sprite.c +++ b/src/drawing/sprite.c @@ -54,7 +54,7 @@ int gfx_load_g1() SDL_RWread(file, g1Elements, header.num_entries * sizeof(rct_g1_element), 1); // Read element data - _g1Buffer = rct2_malloc(header.total_size); + _g1Buffer = malloc(header.total_size); SDL_RWread(file, _g1Buffer, header.total_size, 1); SDL_RWclose(file); diff --git a/src/rct2.c b/src/rct2.c index d7c016093c..4deeac2fa6 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -587,47 +587,3 @@ void get_local_time() RCT2_GLOBAL(RCT2_ADDRESS_OS_TIME_HOUR, sint16) = t.hour; RCT2_GLOBAL(RCT2_ADDRESS_OS_TIME_MINUTE, sint16) = t.minute; } - -/** - * RCT2 and this DLL can not free each other's allocated memory blocks. Use this to allocate memory if RCT2 is still able to - * free it. - * rct2: 0x004068B2 - */ -void *rct2_malloc(size_t numBytes) -{ - #ifdef __WINDOWS__ - return RCT2_CALLFUNC_1(0x004068B2, void*, size_t, numBytes); - #else - //log_warning("call rct's function"); - return malloc(numBytes); - #endif // __WINDOWS__ -} - -/** - * RCT2 and this DLL can not free each other's allocated memory blocks. Use this to reallocate memory if RCT2 is still able to - * free it. - * rct2: 0x004068BD - */ -void *rct2_realloc(void *block, size_t numBytes) -{ - #ifdef __WINDOWS__ - return RCT2_CALLFUNC_2(0x004068BD, void*, void*, size_t, block, numBytes); - #else - //log_warning("call rct's function"); - return realloc(block, numBytes); - #endif // __WINDOWS__ -} - -/** - * RCT2 and this DLL can not free each other's allocated memory blocks. Use this to free memory that was allocated by RCT2. - * rct2: 0x004068CD - */ -void rct2_free(void *block) -{ - #ifdef __WINDOWS__ - RCT2_CALLPROC_1(0x004068CD, void*, block); - #else - //log_warning("call rct's function"); - free(block); - #endif // __WINDOWS__ -} diff --git a/src/rct2.h b/src/rct2.h index bfa1702c1a..da4eff58ea 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -272,9 +272,6 @@ const char *get_file_path(int pathId); void get_system_info(); void get_system_time(); void get_local_time(); -void *rct2_malloc(size_t numBytes); -void *rct2_realloc(void *block, size_t numBytes); -void rct2_free(void *block); void rct2_quit(); int rct2_open_file(const char *path); diff --git a/src/windows/editor_object_selection.c b/src/windows/editor_object_selection.c index e5c531c35e..910867533c 100644 --- a/src/windows/editor_object_selection.c +++ b/src/windows/editor_object_selection.c @@ -667,7 +667,7 @@ static void setup_in_use_selection_flags(){ static int sub_6AB211(){ uint32 total_objects = gInstalledObjectsCount; - RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) = rct2_malloc(total_objects); + RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) = malloc(total_objects); if (RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) == NULL){ log_error("Failed to allocate memory for object flag list."); @@ -717,12 +717,9 @@ static int sub_6AB211(){ * * rct2: 0x006AB316 */ -static void editor_object_flags_free(){ - if (RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) == NULL){ - return; - } - rct2_free(RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*)); - RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) = NULL; +static void editor_object_flags_free() +{ + SafeFree(RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*)); } /** diff --git a/src/world/map.c b/src/world/map.c index 268b42ad0e..3bf67de3f0 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -3654,7 +3654,7 @@ void map_reorganise_elements() { platform_set_cursor(CURSOR_ZZZ); - rct_map_element* new_map_elements = rct2_malloc(0x30000 * sizeof(rct_map_element)); + rct_map_element* new_map_elements = malloc(0x30000 * sizeof(rct_map_element)); rct_map_element* new_elements_pointer = new_map_elements; if (new_map_elements == NULL || new_map_elements == (rct_map_element*)-1){ @@ -3680,7 +3680,7 @@ void map_reorganise_elements() memcpy(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element), new_map_elements, num_elements * sizeof(rct_map_element)); memset(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element) + num_elements, 0, (0x30000 - num_elements) * sizeof(rct_map_element)); - rct2_free(new_map_elements); + free(new_map_elements); map_update_tile_pointers(); }