From 64c515bac403c769085d903590995a611c483f4d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 1 Feb 2020 04:15:22 +0100 Subject: [PATCH] Turn while (true) into for (;;) for easier MSVC backwards compatibility --- gfx/common/d3d12_common.c | 2 +- gfx/drivers/d3d10.c | 2 +- gfx/drivers/d3d11.c | 2 +- libretro-common/rthreads/ctr_pthread.h | 2 +- libretro-common/rthreads/tpool.c | 6 +- .../example_default/libretro_core_options.h | 29 ++++--- .../libretro_core_options.h | 29 ++++--- .../libretro_core_options.h | 29 ++++--- menu/drivers/xmb.c | 2 +- menu/menu_animation.c | 3 +- network/netplay/netplay_io.c | 3 +- retroarch.c | 77 +++++++++---------- tasks/task_patch.c | 6 +- uwp/uwp_main.cpp | 8 +- 14 files changed, 96 insertions(+), 104 deletions(-) diff --git a/gfx/common/d3d12_common.c b/gfx/common/d3d12_common.c index 9aea022009..7e0acf77e7 100644 --- a/gfx/common/d3d12_common.c +++ b/gfx/common/d3d12_common.c @@ -182,7 +182,7 @@ bool d3d12_init_base(d3d12_video_t* d3d12) d3d12->gpu_list = string_list_new(); - while (true) + for (;;) { char str[128]; union string_list_elem_attr attr = {0}; diff --git a/gfx/drivers/d3d10.c b/gfx/drivers/d3d10.c index d8769dcd9b..3b9d074f75 100644 --- a/gfx/drivers/d3d10.c +++ b/gfx/drivers/d3d10.c @@ -1008,7 +1008,7 @@ static void *d3d10_gfx_init(const video_info_t* video, d3d10_gpu_list = string_list_new(); - while (true) + for (;;) { DXGI_ADAPTER_DESC desc = {0}; union string_list_elem_attr attr = {0}; diff --git a/gfx/drivers/d3d11.c b/gfx/drivers/d3d11.c index af2255f715..8f9e29da3c 100644 --- a/gfx/drivers/d3d11.c +++ b/gfx/drivers/d3d11.c @@ -1079,7 +1079,7 @@ static void *d3d11_gfx_init(const video_info_t* video, d3d11_gpu_list = string_list_new(); - while (true) + for (;;) { DXGI_ADAPTER_DESC desc = {0}; char str[128]; diff --git a/libretro-common/rthreads/ctr_pthread.h b/libretro-common/rthreads/ctr_pthread.h index 9470d280f7..41e0fc2513 100644 --- a/libretro-common/rthreads/ctr_pthread.h +++ b/libretro-common/rthreads/ctr_pthread.h @@ -145,7 +145,7 @@ static INLINE int pthread_cond_wait(pthread_cond_t *cond, static INLINE int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) { - while (true) + for (;;) { struct timespec now = {0}; /* Missing clock_gettime*/ diff --git a/libretro-common/rthreads/tpool.c b/libretro-common/rthreads/tpool.c index 3c6b7b30b9..1e091a970b 100644 --- a/libretro-common/rthreads/tpool.c +++ b/libretro-common/rthreads/tpool.c @@ -104,7 +104,7 @@ static void tpool_worker(void *arg) tpool_work_t *work = NULL; tpool_t *tp = (tpool_t*)arg; - while (true) + for (;;) { slock_lock(tp->work_mutex); /* Keep running until told to stop. */ @@ -252,7 +252,8 @@ void tpool_wait(tpool_t *tp) return; slock_lock(tp->work_mutex); - while (true) + + for (;;) { /* working_cond is dual use. It signals when we're not stopping but the * working_cnt is 0 indicating there isn't any work processing. If we @@ -262,5 +263,6 @@ void tpool_wait(tpool_t *tp) else break; } + slock_unlock(tp->work_mutex); } diff --git a/libretro-common/samples/core_options/example_default/libretro_core_options.h b/libretro-common/samples/core_options/example_default/libretro_core_options.h index 04f9cb9aba..099ff633d4 100644 --- a/libretro-common/samples/core_options/example_default/libretro_core_options.h +++ b/libretro-common/samples/core_options/example_default/libretro_core_options.h @@ -166,12 +166,11 @@ static INLINE void libretro_set_core_options(retro_environment_t environ_cb) char **values_buf = NULL; /* Determine number of options */ - while (true) + for (;;) { - if (option_defs_us[num_options].key) - num_options++; - else + if (!option_defs_us[num_options].key) break; + num_options++; } /* Allocate arrays */ @@ -198,20 +197,18 @@ static INLINE void libretro_set_core_options(retro_environment_t environ_cb) size_t num_values = 0; /* Determine number of values */ - while (true) + for (;;) { - if (values[num_values].value) - { - /* Check if this is the default value */ - if (default_value) - if (strcmp(values[num_values].value, default_value) == 0) - default_index = num_values; - - buf_len += strlen(values[num_values].value); - num_values++; - } - else + if (!values[num_values].value) break; + + /* Check if this is the default value */ + if (default_value) + if (strcmp(values[num_values].value, default_value) == 0) + default_index = num_values; + + buf_len += strlen(values[num_values].value); + num_values++; } /* Build values string */ diff --git a/libretro-common/samples/core_options/example_hide_option/libretro_core_options.h b/libretro-common/samples/core_options/example_hide_option/libretro_core_options.h index f75a7ec12b..907f4b1aed 100644 --- a/libretro-common/samples/core_options/example_hide_option/libretro_core_options.h +++ b/libretro-common/samples/core_options/example_hide_option/libretro_core_options.h @@ -187,12 +187,11 @@ static INLINE void libretro_set_core_options(retro_environment_t environ_cb) * but we'll allocate space for all of them. The difference * in resource usage is negligible, and this allows us to * keep the code 'cleaner' */ - while (true) + for (;;) { - if (option_defs_us[num_options].key) - num_options++; - else + if (!option_defs_us[num_options].key) break; + num_options++; } /* Allocate arrays */ @@ -224,20 +223,18 @@ static INLINE void libretro_set_core_options(retro_environment_t environ_cb) size_t num_values = 0; /* Determine number of values */ - while (true) + for (;;) { - if (values[num_values].value) - { - /* Check if this is the default value */ - if (default_value) - if (strcmp(values[num_values].value, default_value) == 0) - default_index = num_values; - - buf_len += strlen(values[num_values].value); - num_values++; - } - else + if (!values[num_values].value) break; + + /* Check if this is the default value */ + if (default_value) + if (strcmp(values[num_values].value, default_value) == 0) + default_index = num_values; + + buf_len += strlen(values[num_values].value); + num_values++; } /* Build values string */ diff --git a/libretro-common/samples/core_options/example_translation/libretro_core_options.h b/libretro-common/samples/core_options/example_translation/libretro_core_options.h index d5cd4aa614..51c3d063b7 100644 --- a/libretro-common/samples/core_options/example_translation/libretro_core_options.h +++ b/libretro-common/samples/core_options/example_translation/libretro_core_options.h @@ -166,12 +166,11 @@ static INLINE void libretro_set_core_options(retro_environment_t environ_cb) char **values_buf = NULL; /* Determine number of options */ - while (true) + for (;;) { - if (option_defs_us[num_options].key) - num_options++; - else + if (!option_defs_us[num_options].key) break; + num_options++; } /* Allocate arrays */ @@ -198,20 +197,18 @@ static INLINE void libretro_set_core_options(retro_environment_t environ_cb) size_t num_values = 0; /* Determine number of values */ - while (true) + for (;;) { - if (values[num_values].value) - { - /* Check if this is the default value */ - if (default_value) - if (strcmp(values[num_values].value, default_value) == 0) - default_index = num_values; - - buf_len += strlen(values[num_values].value); - num_values++; - } - else + if (!values[num_values].value) break; + + /* Check if this is the default value */ + if (default_value) + if (strcmp(values[num_values].value, default_value) == 0) + default_index = num_values; + + buf_len += strlen(values[num_values].value); + num_values++; } /* Build values string */ diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 15da4b7e7e..5da6c74881 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -6476,7 +6476,7 @@ static int xmb_pointer_up(void *userdata, * to reach the bottom of the screen - i.e. we just * want an index offset to subtract from the current * selection... */ - while (true) + for (;;) { float top = xmb_item_y(xmb, bottom_idx, selection) + xmb->margins_screen_top; diff --git a/menu/menu_animation.c b/menu/menu_animation.c index 6ec45c6acf..1c7834a01d 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -1704,7 +1704,8 @@ bool menu_animation_ticker_smooth(menu_animation_ctx_ticker_smooth_t *ticker) /* Determine number of characters to copy */ text_width = ticker->field_width - (3 * period_width); - while (true) + + for (;;) { current_width += src_char_widths[num_chars]; diff --git a/network/netplay/netplay_io.c b/network/netplay/netplay_io.c index a1b63577b1..526d5cd4e6 100644 --- a/network/netplay/netplay_io.c +++ b/network/netplay/netplay_io.c @@ -1328,7 +1328,8 @@ static bool netplay_get_cmd(netplay_t *netplay, /* It wants future frames, make sure we don't capture or send intermediate ones */ START(netplay->self_ptr); frame_count = netplay->self_frame_count; - while (true) + + for (;;) { if (!dframe->used) { diff --git a/retroarch.c b/retroarch.c index f544e33409..c652c36f4a 100644 --- a/retroarch.c +++ b/retroarch.c @@ -4415,7 +4415,8 @@ static void handle_translation_cb( /* Parse JSON body for the image and sound data */ body_copy = strdup(data->data); - while (true) + + for (;;) { curr = (char)*(body_copy+i); if (curr == '\0') @@ -8191,12 +8192,11 @@ static bool core_option_manager_parse_option( option->info = strdup(option_def->info); /* Get number of values */ - while (true) + for (;;) { - if (!string_is_empty(values[num_vals].value)) - num_vals++; - else + if (string_is_empty(values[num_vals].value)) break; + num_vals++; } if (num_vals < 1) @@ -8605,12 +8605,11 @@ static struct retro_core_option_definition *core_option_manager_get_definitions( return NULL; /* Determine number of options */ - while (true) + for (;;) { - if (!string_is_empty(option_defs_us[num_options].key)) - num_options++; - else + if (string_is_empty(option_defs_us[num_options].key)) break; + num_options++; } if (num_options < 1) @@ -8647,24 +8646,22 @@ static struct retro_core_option_definition *core_option_manager_get_definitions( { size_t index = 0; - while (true) + for (;;) { const char *local_key = option_defs_local[index].key; - if (!string_is_empty(local_key)) - { - if (string_is_equal(key, local_key)) - { - local_desc = option_defs_local[index].desc; - local_info = option_defs_local[index].info; - local_values = option_defs_local[index].values; - break; - } - else - index++; - } - else + if (string_is_empty(local_key)) break; + + if (string_is_equal(key, local_key)) + { + local_desc = option_defs_local[index].desc; + local_info = option_defs_local[index].info; + local_values = option_defs_local[index].values; + break; + } + + index++; } } @@ -8674,12 +8671,11 @@ static struct retro_core_option_definition *core_option_manager_get_definitions( /* Determine number of values * (always taken from us english defs) */ - while (true) + for (;;) { - if (!string_is_empty(option_defs_us[i].values[num_values].value)) - num_values++; - else + if (string_is_empty(option_defs_us[i].values[num_values].value)) break; + num_values++; } /* Copy values */ @@ -8696,22 +8692,20 @@ static struct retro_core_option_definition *core_option_manager_get_definitions( { size_t value_index = 0; - while (true) + for (;;) { const char *local_value = local_values[value_index].value; - if (!string_is_empty(local_value)) - { - if (string_is_equal(value, local_value)) - { - local_label = local_values[value_index].label; - break; - } - else - value_index++; - } - else + if (string_is_empty(local_value)) break; + + if (string_is_equal(value, local_value)) + { + local_label = local_values[value_index].label; + break; + } + + value_index++; } } @@ -9098,9 +9092,7 @@ static bool dynamic_verify_hw_context(enum retro_hw_context_type type, case RETRO_HW_CONTEXT_OPENGL_CORE: if (!string_is_equal(video_ident, "gl") && !string_is_equal(video_ident, "glcore")) - { return false; - } break; case RETRO_HW_CONTEXT_DIRECT3D: if (!(string_is_equal(video_ident, "d3d11") && major == 11)) @@ -9175,7 +9167,8 @@ static size_t mmap_add_bits_down(size_t n) n |= n >> 8; n |= n >> 16; - /* double shift to avoid warnings on 32bit (it's dead code, but compilers suck) */ + /* double shift to avoid warnings on 32bit (it's dead code, + * but compilers suck) */ if (sizeof(size_t) > 4) n |= n >> 16 >> 16; diff --git a/tasks/task_patch.c b/tasks/task_patch.c index add06fbf88..b3837d5ed9 100644 --- a/tasks/task_patch.c +++ b/tasks/task_patch.c @@ -306,7 +306,8 @@ static void ups_target_write(struct ups_data *data, uint8_t n) static uint64_t ups_decode(struct ups_data *data) { uint64_t offset = 0, shift = 1; - while (true) + + for (;;) { uint8_t x = ups_patch_read(data); offset += (x & 0x7f) * shift; @@ -384,7 +385,8 @@ static enum patch_error ups_apply_patch( unsigned length = (unsigned)ups_decode(&data); while (length--) ups_target_write(&data, ups_source_read(&data)); - while (true) + + for (;;) { uint8_t patch_xor = ups_patch_read(&data); ups_target_write(&data, patch_xor ^ ups_source_read(&data)); diff --git a/uwp/uwp_main.cpp b/uwp/uwp_main.cpp index f46926b0c2..8ae6e68723 100644 --- a/uwp/uwp_main.cpp +++ b/uwp/uwp_main.cpp @@ -325,18 +325,20 @@ void App::Load(Platform::String^ entryPoint) // This method is called after the window becomes active. void App::Run() { + bool x = false; if (!m_initialized) { RARCH_WARN("Initialization failed, so not running\n"); return; } - bool x = false; - while (true) + + for (;;) { + int ret; CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); - int ret = runloop_iterate(); + ret = runloop_iterate(); task_queue_check();