From db6171676a59786acdf951e4751356aca4e6582d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 8 Sep 2016 11:59:44 +0200 Subject: [PATCH] Use retro_assert everywhere --- audio/drivers/jack.c | 11 ++++--- audio/librsound.c | 51 +++++++++++++++++---------------- audio/test/snr.c | 9 +++--- gfx/drivers/exynos_gfx.c | 5 ++-- gfx/drivers/omap_gfx.c | 19 ++++++------ libretro-db/c_converter.c | 39 ++++++++++++++----------- network/netplay/netplay.c | 10 +++---- record/drivers/record_ffmpeg.c | 31 ++++++++++---------- ui/drivers/cocoa/cocoa_common.m | 7 +++-- 9 files changed, 100 insertions(+), 82 deletions(-) diff --git a/audio/drivers/jack.c b/audio/drivers/jack.c index e36b3fb54b..ad1574b50e 100644 --- a/audio/drivers/jack.c +++ b/audio/drivers/jack.c @@ -24,6 +24,7 @@ #include #include +#include #include #include "../audio_driver.h" @@ -51,7 +52,7 @@ typedef struct jack static int process_cb(jack_nframes_t nframes, void *data) { int i; - jack_nframes_t f, avail[2], min_avail; + jack_nframes_t avail[2], min_avail; jack_t *jd = (jack_t*)data; if (nframes <= 0) @@ -62,8 +63,8 @@ static int process_cb(jack_nframes_t nframes, void *data) return 0; } - avail[0] = jack_ringbuffer_read_space(jd->buffer[0]); - avail[1] = jack_ringbuffer_read_space(jd->buffer[1]); + avail[0] = jack_ringbuffer_read_space(jd->buffer[0]); + avail[1] = jack_ringbuffer_read_space(jd->buffer[1]); min_avail = ((avail[0] < avail[1]) ? avail[0] : avail[1]) / sizeof(jack_default_audio_sample_t); if (min_avail > nframes) @@ -71,8 +72,10 @@ static int process_cb(jack_nframes_t nframes, void *data) for (i = 0; i < 2; i++) { + jack_nframes_t f; jack_default_audio_sample_t *out = (jack_default_audio_sample_t*)jack_port_get_buffer(jd->ports[i], nframes); - assert(out); + + retro_assert(out); jack_ringbuffer_read(jd->buffer[i], (char*)out, min_avail * sizeof(jack_default_audio_sample_t)); for (f = min_avail; f < nframes; f++) diff --git a/audio/librsound.c b/audio/librsound.c index 9a12ee15a3..6934152413 100644 --- a/audio/librsound.c +++ b/audio/librsound.c @@ -65,13 +65,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include /* @@ -212,7 +212,7 @@ static INLINE int rsnd_format_to_samplesize ( uint16_t fmt ) int rsd_samplesize( rsound_t *rd ) { - assert(rd != NULL); + retro_assert(rd != NULL); return rd->samplesize; } @@ -1298,7 +1298,7 @@ static int rsnd_reset(rsound_t *rd) int rsd_stop(rsound_t *rd) { - assert(rd != NULL); + retro_assert(rd != NULL); rsnd_stop_thread(rd); const char buf[] = "RSD 5 STOP"; @@ -1314,7 +1314,7 @@ int rsd_stop(rsound_t *rd) size_t rsd_write( rsound_t *rsound, const void* buf, size_t size) { size_t max_write, written = 0; - assert(rsound != NULL); + retro_assert(rsound != NULL); if ( !rsound->ready_for_data ) return 0; @@ -1339,11 +1339,11 @@ size_t rsd_write( rsound_t *rsound, const void* buf, size_t size) int rsd_start(rsound_t *rsound) { - assert(rsound != NULL); - assert(rsound->rate > 0); - assert(rsound->channels > 0); - assert(rsound->host != NULL); - assert(rsound->port != NULL); + retro_assert(rsound != NULL); + retro_assert(rsound->rate > 0); + retro_assert(rsound->channels > 0); + retro_assert(rsound->host != NULL); + retro_assert(rsound->port != NULL); if ( rsnd_create_connection(rsound) < 0 ) return -1; @@ -1353,7 +1353,7 @@ int rsd_start(rsound_t *rsound) int rsd_exec(rsound_t *rsound) { - assert(rsound != NULL); + retro_assert(rsound != NULL); RSD_DEBUG("[RSound] rsd_exec().\n"); // Makes sure we have a working connection @@ -1406,8 +1406,8 @@ int rsd_exec(rsound_t *rsound) /* ioctl()-ish param setting :D */ int rsd_set_param(rsound_t *rd, enum rsd_settings option, void* param) { - assert(rd != NULL); - assert(param != NULL); + retro_assert(rd != NULL); + retro_assert(param != NULL); int retval = 0; switch(option) @@ -1505,7 +1505,7 @@ void rsd_delay_wait(rsound_t *rd) size_t rsd_pointer(rsound_t *rsound) { - assert(rsound != NULL); + retro_assert(rsound != NULL); int ptr; ptr = rsnd_get_ptr(rsound); @@ -1515,7 +1515,7 @@ size_t rsd_pointer(rsound_t *rsound) size_t rsd_get_avail(rsound_t *rd) { - assert(rd != NULL); + retro_assert(rd != NULL); int ptr; ptr = rsnd_get_ptr(rd); return rd->buffer_size - ptr; @@ -1523,7 +1523,7 @@ size_t rsd_get_avail(rsound_t *rd) size_t rsd_delay(rsound_t *rd) { - assert(rd != NULL); + retro_assert(rd != NULL); int ptr = rsnd_get_delay(rd); if ( ptr < 0 ) ptr = 0; @@ -1533,28 +1533,29 @@ size_t rsd_delay(rsound_t *rd) size_t rsd_delay_ms(rsound_t* rd) { - assert(rd); - assert(rd->rate > 0 && rd->channels > 0); + retro_assert(rd); + retro_assert(rd->rate > 0 && rd->channels > 0); return (rsd_delay(rd) * 1000) / ( rd->rate * rd->channels * rd->samplesize ); } int rsd_pause(rsound_t* rsound, int enable) { - assert(rsound != NULL); + retro_assert(rsound != NULL); if ( enable ) return rsd_stop(rsound); - else - return rsd_start(rsound); + + return rsd_start(rsound); } int rsd_init(rsound_t** rsound) { - assert(rsound != NULL); *rsound = calloc(1, sizeof(rsound_t)); if ( *rsound == NULL ) return -1; + retro_assert(rsound != NULL); + (*rsound)->conn.socket = -1; (*rsound)->conn.ctl_socket = -1; @@ -1616,7 +1617,7 @@ int rsd_simple_start(rsound_t** rsound, const char* host, const char* port, cons void rsd_set_callback(rsound_t *rsound, rsd_audio_callback_t audio_cb, rsd_error_callback_t err_cb, size_t max_size, void *userdata) { - assert(rsound != NULL); + retro_assert(rsound != NULL); rsound->audio_callback = audio_cb; rsound->error_callback = err_cb; @@ -1624,7 +1625,9 @@ void rsd_set_callback(rsound_t *rsound, rsd_audio_callback_t audio_cb, rsd_error rsound->cb_data = userdata; if (rsound->audio_callback) - assert(rsound->error_callback); + { + retro_assert(rsound->error_callback); + } } void rsd_callback_lock(rsound_t *rsound) @@ -1639,7 +1642,7 @@ void rsd_callback_unlock(rsound_t *rsound) int rsd_free(rsound_t *rsound) { - assert(rsound != NULL); + retro_assert(rsound != NULL); if (rsound->fifo_buffer) fifo_free(rsound->fifo_buffer); if (rsound->host) diff --git a/audio/test/snr.c b/audio/test/snr.c index 7e76ad990d..91a462c70b 100644 --- a/audio/test/snr.c +++ b/audio/test/snr.c @@ -21,6 +21,7 @@ #include #include +#include #include @@ -122,7 +123,7 @@ static void calculate_fft(const float *data, complex double *butterfly_buf, size unsigned i; /* Enforce POT. */ - assert((samples & (samples - 1)) == 0); + retro_assert((samples & (samples - 1)) == 0); for (i = 0; i < samples; i++) butterfly_buf[i] = data[2 * i]; @@ -154,7 +155,7 @@ static void calculate_ifft(complex double *butterfly_buf, size_t samples, bool n unsigned step_size; /* Enforce POT. */ - assert((samples & (samples - 1)) == 0); + retro_assert((samples & (samples - 1)) == 0); interleave(butterfly_buf, samples); @@ -297,8 +298,8 @@ int main(int argc, char *argv[]) output = calloc(sizeof(float), (fft_samples + 16) * 2); butterfly_buf = calloc(sizeof(complex double), fft_samples / 2); - assert(input); - assert(output); + retro_assert(input); + retro_assert(output); if (!rarch_resampler_realloc(&re, &resampler, RESAMPLER_IDENT, ratio)) { diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index 3b86a97257..2bb4a68945 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -22,13 +22,13 @@ #include #include #include -#include #include #include #include #include +#include #include #include "../common/drm_common.h" @@ -265,7 +265,8 @@ static const char *exynos_buffer_name(enum exynos_buffer_type type) case EXYNOS_BUFFER_AUX: return "aux"; default: - assert(false); + retro_assert(false); + break; } return NULL; diff --git a/gfx/drivers/omap_gfx.c b/gfx/drivers/omap_gfx.c index b75f86d207..dfac30e872 100644 --- a/gfx/drivers/omap_gfx.c +++ b/gfx/drivers/omap_gfx.c @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -333,7 +334,7 @@ static int omapfb_setup_pages(omapfb_data_t *pdata) static int omapfb_mmap(omapfb_data_t *pdata) { - assert(pdata->fb_mem == NULL); + retro_assert(pdata->fb_mem == NULL); pdata->fb_mem = mmap(NULL, pdata->current_state->mi.size, PROT_WRITE, MAP_SHARED, pdata->fd, 0); @@ -351,9 +352,9 @@ static int omapfb_mmap(omapfb_data_t *pdata) static int omapfb_backup_state(omapfb_data_t *pdata) { - void* mem; + void* mem = NULL; - assert(pdata->saved_state == NULL); + retro_assert(pdata->saved_state == NULL); pdata->saved_state = calloc(1, sizeof(omapfb_state_t)); if (!pdata->saved_state) return -1; @@ -393,14 +394,14 @@ static int omapfb_backup_state(omapfb_data_t *pdata) static int omapfb_alloc_mem(omapfb_data_t *pdata) { + unsigned mem_size; struct omapfb_plane_info pi; struct omapfb_mem_info mi; - unsigned mem_size; - void* mem = NULL; + void *mem = NULL; const struct retro_game_geometry *geom = NULL; - struct retro_system_av_info *av_info = NULL; + struct retro_system_av_info *av_info = NULL; - assert(pdata->current_state == NULL); + retro_assert(pdata->current_state == NULL); pdata->current_state = (omapfb_state_t*)calloc(1, sizeof(omapfb_state_t)); @@ -678,14 +679,14 @@ static int omapfb_set_mode(omapfb_data_t *pdata, int width, int height) static void omapfb_prepare(omapfb_data_t *pdata) { - omapfb_page_t *page; + omapfb_page_t *page = NULL; /* issue flip before getting free page */ omapfb_page_flip(pdata); page = omapfb_get_page(pdata); - assert(page != NULL); + retro_assert(page != NULL); pdata->old_page = pdata->cur_page; pdata->cur_page = page; diff --git a/libretro-db/c_converter.c b/libretro-db/c_converter.c index ffa0a86549..7284ef4e2b 100644 --- a/libretro-db/c_converter.c +++ b/libretro-db/c_converter.c @@ -28,9 +28,10 @@ #include #include #include -#include #include +#include + #include "libretrodb.h" static void dat_converter_exit(int rc) @@ -163,8 +164,8 @@ static dat_converter_bt_node_t* dat_converter_bt_node_insert( dat_converter_bt_node_t** node, dat_converter_map_t* map) { - assert(map->key); - assert(list->type == DAT_CONVERTER_MAP_LIST); + retro_assert(map->key); + retro_assert(list->type == DAT_CONVERTER_MAP_LIST); if (!*node) { @@ -189,7 +190,8 @@ static dat_converter_bt_node_t* dat_converter_bt_node_insert( if (map->type == DAT_CONVERTER_LIST_MAP) { int i; - assert(list->values[(*node)->index].map.value.list->type + + retro_assert(list->values[(*node)->index].map.value.list->type == map->value.list->type); for (i = 0; i < map->value.list->count; i++) @@ -457,7 +459,7 @@ static const char* dat_converter_get_match( { int i; - assert(match_key); + retro_assert(match_key); if (list->type != DAT_CONVERTER_MAP_LIST) return NULL; @@ -466,15 +468,16 @@ static const char* dat_converter_get_match( { if (list->values[i].map.hash == match_key->hash) { - assert(!strcmp(list->values[i].map.key, match_key->value)); + retro_assert(!strcmp(list->values[i].map.key, match_key->value)); if (match_key->next) return dat_converter_get_match( list->values[i].map.value.list, match_key->next); - else if ((list->values[i].map.type == DAT_CONVERTER_STRING_MAP)) + + if ((list->values[i].map.type == DAT_CONVERTER_STRING_MAP)) return list->values[i].map.value.string; - else - return NULL; + + return NULL; } } @@ -486,12 +489,12 @@ static dat_converter_list_t* dat_converter_parser( dat_converter_list_t* lexer_list, dat_converter_match_key_t* match_key) { - bool skip = true; - dat_converter_list_item_t* current = lexer_list->values; dat_converter_map_t map; + dat_converter_list_item_t* current = lexer_list->values; + bool skip = true; - map.key = NULL; - map.type = DAT_CONVERTER_LIST_MAP; + map.key = NULL; + map.type = DAT_CONVERTER_LIST_MAP; if (!target) { @@ -637,6 +640,8 @@ static int dat_converter_value_provider( dat_converter_list_item_t** current_item, struct rmsgpack_dom_value* out) { int i; + struct rmsgpack_dom_pair* current = NULL; + out->type = RDT_MAP; out->val.map.len = 0; out->val.map.items = calloc((sizeof(rdb_mappings) / sizeof(*rdb_mappings)), @@ -644,16 +649,16 @@ static int dat_converter_value_provider( (*current_item)--; - assert((*current_item)->map.type == DAT_CONVERTER_LIST_MAP); + retro_assert((*current_item)->map.type == DAT_CONVERTER_LIST_MAP); dat_converter_list_t* list = (*current_item)->map.value.list; if (!list) return 1; - assert(list->type == DAT_CONVERTER_MAP_LIST); + retro_assert(list->type == DAT_CONVERTER_MAP_LIST); - struct rmsgpack_dom_pair* current = out->val.map.items; + current = out->val.map.items; for (i = 0; i < (sizeof(rdb_mappings) / sizeof(*rdb_mappings)); i++) { @@ -720,7 +725,7 @@ static int dat_converter_value_provider( } break; default: - assert(0); + retro_assert(0); break; } current++; diff --git a/network/netplay/netplay.c b/network/netplay/netplay.c index 2df2bf6a02..a2a574ac52 100644 --- a/network/netplay/netplay.c +++ b/network/netplay/netplay.c @@ -18,11 +18,11 @@ #pragma comment(lib, "ws2_32") #endif -#include #include #include #include +#include #include #include #include @@ -64,7 +64,7 @@ static void warn_hangup(void) */ bool check_netplay_synched(netplay_t* netplay) { - assert(netplay); + retro_assert(netplay); return netplay->frame_count < (netplay->flip_frame + 2 * UDP_FRAME_PACKETS); } @@ -907,7 +907,7 @@ bool netplay_command(netplay_t* netplay, enum netplay_cmd cmd, bool host_only = !!(flags & CMD_OPT_HOST_ONLY); bool require_sync = !!(flags & CMD_OPT_REQUIRE_SYNC); - assert(netplay); + retro_assert(netplay); if (netplay->spectate.enabled && !allowed_spectate) { @@ -1063,7 +1063,7 @@ int16_t input_state_spectate_client(unsigned port, unsigned device, **/ void netplay_pre_frame(netplay_t *netplay) { - assert(netplay && netplay->net_cbs->pre_frame); + retro_assert(netplay && netplay->net_cbs->pre_frame); netplay->net_cbs->pre_frame(netplay); } @@ -1077,7 +1077,7 @@ void netplay_pre_frame(netplay_t *netplay) **/ void netplay_post_frame(netplay_t *netplay) { - assert(netplay && netplay->net_cbs->post_frame); + retro_assert(netplay && netplay->net_cbs->post_frame); netplay->net_cbs->post_frame(netplay); } diff --git a/record/drivers/record_ffmpeg.c b/record/drivers/record_ffmpeg.c index b4b65d3136..71ba0550a3 100644 --- a/record/drivers/record_ffmpeg.c +++ b/record/drivers/record_ffmpeg.c @@ -20,7 +20,17 @@ #include #include -#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include #ifdef HAVE_CONFIG_H #include "../../config.h" @@ -53,15 +63,6 @@ extern "C" { } #endif -#include - -#include -#include -#include -#include -#include -#include -#include #include "../record_driver.h" @@ -675,7 +676,7 @@ static bool init_thread(ffmpeg_t *handle) handle->can_sleep = true; handle->thread = sthread_create(ffmpeg_thread, handle); - assert(handle->lock && handle->cond_lock && + retro_assert(handle->lock && handle->cond_lock && handle->cond && handle->audio_fifo && handle->attr_fifo && handle->video_fifo && handle->thread); @@ -1371,14 +1372,14 @@ static bool ffmpeg_finalize(void *data) static void ffmpeg_thread(void *data) { size_t audio_buf_size; - void *audio_buf; - ffmpeg_t *ff = (ffmpeg_t*)data; - + void *audio_buf = NULL; + ffmpeg_t *ff = (ffmpeg_t*)data; /* For some reason, FFmpeg has a tendency to crash * if we don't overallocate a bit. */ void *video_buf = av_malloc(2 * ff->params.fb_width * ff->params.fb_height * ff->video.pix_size); - assert(video_buf); + + retro_assert(video_buf); audio_buf_size = ff->config.audio_enable ? (ff->audio.codec->frame_size * ff->params.channels * sizeof(int16_t)) : 0; diff --git a/ui/drivers/cocoa/cocoa_common.m b/ui/drivers/cocoa/cocoa_common.m index 248aa170e2..4094da9cbe 100644 --- a/ui/drivers/cocoa/cocoa_common.m +++ b/ui/drivers/cocoa/cocoa_common.m @@ -20,6 +20,9 @@ #ifdef HAVE_COCOA #include "../ui_cocoa.h" #endif + +#include + #include "../../../verbosity.h" /* Define compatibility symbols and categories. */ @@ -343,7 +346,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer /* Creata a video device and input from that Device. Add the input to the capture session. */ videoDevice = (AVCaptureDevice*)[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if (videoDevice == nil) - assert(0); + retro_assert(0); /* Add the device to the session. */ input = (AVCaptureDeviceInput*)[AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error]; @@ -351,7 +354,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer if (error) { RARCH_ERR("video device input %s\n", error.localizedDescription.UTF8String); - assert(0); + retro_assert(0); } [_session addInput:input];