From f1fe7559bc46a987f65aac108bc46f9110432d7a Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 21 Mar 2015 06:17:03 +0100 Subject: [PATCH] Put g_extern on heap --- retroarch.c | 34 +++++++++++++++++++++++++++++++++- runloop.c | 25 +++++++++++++------------ runloop.h | 3 --- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/retroarch.c b/retroarch.c index e2a0434fec..d42e7530ce 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1717,7 +1717,7 @@ void rarch_main_state_new(void) { global_t *global = global_get_ptr(); - main_clear_state(global->main_is_init); + main_clear_state(global ? global->main_is_init: false); rarch_main_command(RARCH_CMD_MSG_QUEUE_INIT); } @@ -2385,6 +2385,9 @@ bool rarch_main_command(unsigned cmd) #endif break; case RARCH_CMD_CHEATS_DEINIT: + if (!global) + break; + if (global->cheat) cheat_manager_free(global->cheat); global->cheat = NULL; @@ -2400,6 +2403,8 @@ bool rarch_main_command(unsigned cmd) init_remapping(); break; case RARCH_CMD_REWIND_DEINIT: + if (!global) + break; #ifdef HAVE_NETPLAY if (driver->netplay_data) return false; @@ -2501,6 +2506,9 @@ bool rarch_main_command(unsigned cmd) #endif break; case RARCH_CMD_DSP_FILTER_DEINIT: + if (!global) + break; + if (global->audio_data.dsp) rarch_dsp_filter_free(global->audio_data.dsp); global->audio_data.dsp = NULL; @@ -2517,6 +2525,9 @@ bool rarch_main_command(unsigned cmd) settings->audio.dsp_plugin); break; case RARCH_CMD_GPU_RECORD_DEINIT: + if (!global) + break; + if (global->record.gpu_buffer) free(global->record.gpu_buffer); global->record.gpu_buffer = NULL; @@ -2545,6 +2556,9 @@ bool rarch_main_command(unsigned cmd) settings->content_history_size); break; case RARCH_CMD_CORE_INFO_DEINIT: + if (!global) + break; + if (global->core_info) core_info_list_free(global->core_info); global->core_info = NULL; @@ -2677,6 +2691,9 @@ bool rarch_main_command(unsigned cmd) } break; case RARCH_CMD_SHADER_DIR_DEINIT: + if (!global) + break; + dir_list_free(global->shader_dir.list); global->shader_dir.list = NULL; global->shader_dir.ptr = 0; @@ -2707,6 +2724,9 @@ bool rarch_main_command(unsigned cmd) save_files(); break; case RARCH_CMD_SAVEFILES_DEINIT: + if (!global) + break; + if (global->savefiles) string_list_free(global->savefiles); global->savefiles = NULL; @@ -2733,6 +2753,9 @@ bool rarch_main_command(unsigned cmd) rarch_main_data_init_queues(); break; case RARCH_CMD_BSV_MOVIE_DEINIT: + if (!global) + break; + if (global->bsv.movie) bsv_movie_free(global->bsv.movie); global->bsv.movie = NULL; @@ -2806,16 +2829,25 @@ bool rarch_main_command(unsigned cmd) #endif break; case RARCH_CMD_TEMPORARY_CONTENT_DEINIT: + if (!global) + break; + if (global->temporary_content) free_temporary_content(); global->temporary_content = NULL; break; case RARCH_CMD_SUBSYSTEM_FULLPATHS_DEINIT: + if (!global) + break; + if (global->subsystem_fullpaths) string_list_free(global->subsystem_fullpaths); global->subsystem_fullpaths = NULL; break; case RARCH_CMD_LOG_FILE_DEINIT: + if (!global) + break; + if (global->log_file) fclose(global->log_file); global->log_file = NULL; diff --git a/runloop.c b/runloop.c index 8fd6cce1ed..f628cb19e5 100644 --- a/runloop.c +++ b/runloop.c @@ -35,7 +35,7 @@ static struct runloop *g_runloop; -struct global g_extern; +static struct global *g_extern; /* Convenience macros. */ #define check_oneshot_func(trigger_input) (check_is_oneshot(BIT64_GET(trigger_input, RARCH_FRAMEADVANCE), BIT64_GET(trigger_input, RARCH_REWIND))) @@ -992,7 +992,7 @@ void rarch_main_msg_queue_init(void) global_t *global_get_ptr(void) { - return &g_extern; + return g_extern; } runloop_t *rarch_main_get_ptr(void) @@ -1012,19 +1012,19 @@ static void rarch_main_state_deinit(void) static void rarch_main_global_deinit(void) { + global_t *global = NULL; + rarch_main_command(RARCH_CMD_TEMPORARY_CONTENT_DEINIT); rarch_main_command(RARCH_CMD_SUBSYSTEM_FULLPATHS_DEINIT); rarch_main_command(RARCH_CMD_RECORD_DEINIT); rarch_main_command(RARCH_CMD_LOG_FILE_DEINIT); -#if 0 - global_t *global = global_get_ptr(); + global = global_get_ptr(); if (!global) return; free(global); -#endif } bool rarch_main_verbosity(void) @@ -1043,13 +1043,14 @@ FILE *rarch_main_log_file(void) return global->log_file; } -static void rarch_main_global_init(void) +static global_t *rarch_main_global_init(void) { -#if 0 - g_extern = rarch_main_global_init(); -#else - memset(&g_extern, 0, sizeof(g_extern)); -#endif + global_t *global = (global_t*)calloc(1, sizeof(global_t)); + + if (!global) + return NULL; + + return global; } static runloop_t *rarch_main_state_init(void) @@ -1068,7 +1069,7 @@ void rarch_main_clear_state(void) g_runloop = rarch_main_state_init(); rarch_main_global_deinit(); - rarch_main_global_init(); + g_extern = rarch_main_global_init(); } bool rarch_main_is_idle(void) diff --git a/runloop.h b/runloop.h index 359a0613dd..4f62af96c8 100644 --- a/runloop.h +++ b/runloop.h @@ -490,9 +490,6 @@ void rarch_main_data_deinit(void); void rarch_main_data_init_queues(void); -/* Public data structures. */ -extern global_t g_extern; - #ifdef __cplusplus } #endif