From bf978e2b6b9f32672c8b6b46ba6a917745279e74 Mon Sep 17 00:00:00 2001 From: derselbst Date: Mon, 30 Oct 2017 11:28:08 +0100 Subject: [PATCH] even more destructor refactor --- src/bindings/fluid_cmd.c | 39 ++++++++++--------------------- src/bindings/fluid_filerenderer.c | 4 +--- src/drivers/fluid_adriver.c | 1 + src/drivers/fluid_alsa.c | 3 --- src/drivers/fluid_aufile.c | 8 +------ src/drivers/fluid_coreaudio.c | 5 +--- src/drivers/fluid_coremidi.c | 4 +--- src/drivers/fluid_dart.c | 5 +--- src/drivers/fluid_dsound.c | 5 +--- src/drivers/fluid_mdriver.c | 1 + src/drivers/fluid_winmidi.c | 4 +--- src/sfloader/fluid_ramsfont.c | 22 +++++++---------- src/synth/fluid_event.c | 4 +--- src/synth/fluid_tuning.c | 9 ++++--- src/synth/fluid_voice.c | 5 ++-- src/utils/fluid_sys.c | 10 +++----- src/utils/fluid_sys.h | 2 ++ 17 files changed, 41 insertions(+), 90 deletions(-) diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index 79867540..9e85a976 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -303,6 +303,8 @@ fluid_shell_init(fluid_shell_t* shell, void delete_fluid_shell(fluid_shell_t* shell) { + fluid_return_if_fail(shell != NULL); + if (shell->thread != NULL) { delete_fluid_thread(shell->thread); } @@ -2240,16 +2242,11 @@ fluid_cmd_t* fluid_cmd_copy(fluid_cmd_t* cmd) void delete_fluid_cmd(fluid_cmd_t* cmd) { - if (cmd->name) { + fluid_return_if_fail(cmd != NULL); FLUID_FREE(cmd->name); - } - if (cmd->topic) { FLUID_FREE(cmd->topic); - } - if (cmd->help) { FLUID_FREE(cmd->help); - } - FLUID_FREE(cmd); + FLUID_FREE(cmd); } /* @@ -2316,6 +2313,8 @@ fluid_cmd_handler_t* new_fluid_cmd_handler(fluid_synth_t* synth, fluid_midi_rout void delete_fluid_cmd_handler(fluid_cmd_handler_t* handler) { + fluid_return_if_fail(handler != NULL); + delete_fluid_hashtable(handler->commands); FLUID_FREE(handler); } @@ -2426,9 +2425,7 @@ new_fluid_server(fluid_settings_t* settings, void delete_fluid_server(fluid_server_t* server) { - if (server == NULL) { - return; - } + fluid_return_if_fail(server != NULL); fluid_server_close(server); @@ -2441,9 +2438,7 @@ static void fluid_server_close(fluid_server_t* server) fluid_list_t* clients; fluid_client_t* client; - if (server == NULL) { - return; - } + fluid_return_if_fail(server != NULL); fluid_mutex_lock(server->mutex); clients = server->clients; @@ -2565,10 +2560,8 @@ error_recovery: void fluid_client_quit(fluid_client_t* client) { - if (client->socket != INVALID_SOCKET) { fluid_socket_close(client->socket); - client->socket = INVALID_SOCKET; - } + FLUID_LOG(FLUID_DBG, "fluid_client_quit: joining"); fluid_thread_join(client->thread); FLUID_LOG(FLUID_DBG, "fluid_client_quit: done"); @@ -2576,20 +2569,12 @@ void fluid_client_quit(fluid_client_t* client) void delete_fluid_client(fluid_client_t* client) { - if(client->handler != NULL) - { + fluid_return_if_fail(client != NULL); + delete_fluid_cmd_handler(client->handler); - client->handler = NULL; - } - - if (client->socket != INVALID_SOCKET) { fluid_socket_close(client->socket); - client->socket = INVALID_SOCKET; - } - if (client->thread != NULL) { delete_fluid_thread(client->thread); - client->thread = NULL; - } + FLUID_FREE(client); } diff --git a/src/bindings/fluid_filerenderer.c b/src/bindings/fluid_filerenderer.c index 417b34d2..486dd0d2 100644 --- a/src/bindings/fluid_filerenderer.c +++ b/src/bindings/fluid_filerenderer.c @@ -326,9 +326,7 @@ fluid_file_set_encoding_quality(fluid_file_renderer_t* r, double q) */ void delete_fluid_file_renderer(fluid_file_renderer_t* dev) { - if (dev == NULL) { - return; - } + fluid_return_if_fail(dev != NULL); #if LIBSNDFILE_SUPPORT if (dev->sndfile != NULL) { diff --git a/src/drivers/fluid_adriver.c b/src/drivers/fluid_adriver.c index d4b50df2..db6a6c6b 100644 --- a/src/drivers/fluid_adriver.c +++ b/src/drivers/fluid_adriver.c @@ -369,6 +369,7 @@ void delete_fluid_audio_driver(fluid_audio_driver_t* driver) { unsigned int i; + fluid_return_if_fail(driver != NULL); for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers); i++) { if (fluid_audio_drivers[i].name == driver->name) { diff --git a/src/drivers/fluid_alsa.c b/src/drivers/fluid_alsa.c index c8a2093d..d655b990 100644 --- a/src/drivers/fluid_alsa.c +++ b/src/drivers/fluid_alsa.c @@ -321,7 +321,6 @@ new_fluid_alsa_audio_driver2(fluid_settings_t* settings, void delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p) { fluid_alsa_audio_driver_t* dev = (fluid_alsa_audio_driver_t*) p; - fluid_return_if_fail(dev != NULL); dev->cont = 0; @@ -649,7 +648,6 @@ void delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p) { fluid_alsa_rawmidi_driver_t* dev = (fluid_alsa_rawmidi_driver_t*) p; - fluid_return_if_fail(dev != NULL); /* cancel the thread and wait for it before cleaning up */ @@ -975,7 +973,6 @@ void delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p) { fluid_alsa_seq_driver_t* dev = (fluid_alsa_seq_driver_t*) p; - fluid_return_if_fail(dev != NULL); /* cancel the thread and wait for it before cleaning up */ diff --git a/src/drivers/fluid_aufile.c b/src/drivers/fluid_aufile.c index f7344cad..7d5865dd 100644 --- a/src/drivers/fluid_aufile.c +++ b/src/drivers/fluid_aufile.c @@ -103,17 +103,11 @@ new_fluid_file_audio_driver(fluid_settings_t* settings, void delete_fluid_file_audio_driver(fluid_audio_driver_t* p) { fluid_file_audio_driver_t* dev = (fluid_file_audio_driver_t*) p; - fluid_return_if_fail(dev != NULL); - if (dev->timer != NULL) { delete_fluid_timer(dev->timer); - } - - if (dev->renderer != NULL) { delete_fluid_file_renderer(dev->renderer); - } - + FLUID_FREE(dev); } diff --git a/src/drivers/fluid_coreaudio.c b/src/drivers/fluid_coreaudio.c index cad98658..8c4b7fae 100644 --- a/src/drivers/fluid_coreaudio.c +++ b/src/drivers/fluid_coreaudio.c @@ -319,10 +319,7 @@ void delete_fluid_core_audio_driver(fluid_audio_driver_t* p) { fluid_core_audio_driver_t* dev = (fluid_core_audio_driver_t*) p; - - if (dev == NULL) { - return; - } + fluid_return_if_fail(dev != NULL); CloseComponent (dev->outputUnit); diff --git a/src/drivers/fluid_coremidi.c b/src/drivers/fluid_coremidi.c index 125a7e61..1bbe6c1e 100644 --- a/src/drivers/fluid_coremidi.c +++ b/src/drivers/fluid_coremidi.c @@ -162,9 +162,7 @@ void delete_fluid_coremidi_driver(fluid_midi_driver_t* p) { fluid_coremidi_driver_t* dev = (fluid_coremidi_driver_t*) p; - - if(dev == NULL) - return; + fluid_return_if_fail(dev != NULL); if (dev->client != NULL) { MIDIClientDispose(dev->client); diff --git a/src/drivers/fluid_dart.c b/src/drivers/fluid_dart.c index 5f440851..0bd4f11a 100644 --- a/src/drivers/fluid_dart.c +++ b/src/drivers/fluid_dart.c @@ -215,10 +215,7 @@ error_recovery: void delete_fluid_dart_audio_driver(fluid_audio_driver_t* p) { fluid_dart_audio_driver_t* dev = (fluid_dart_audio_driver_t*) p; - - if (dev == NULL) { - return; - } + fluid_return_if_fail(dev != NULL); if (dev->usDeviceID != 0) { MCI_GENERIC_PARMS GenericParms; diff --git a/src/drivers/fluid_dsound.c b/src/drivers/fluid_dsound.c index e9ff3aeb..bdb6fab5 100644 --- a/src/drivers/fluid_dsound.c +++ b/src/drivers/fluid_dsound.c @@ -273,10 +273,7 @@ new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth) void delete_fluid_dsound_audio_driver(fluid_audio_driver_t* d) { fluid_dsound_audio_driver_t* dev = (fluid_dsound_audio_driver_t*) d; - - if (dev == NULL) { - return; - } + fluid_return_if_fail(dev != NULL); /* tell the audio thread to stop its loop */ dev->cont = 0; diff --git a/src/drivers/fluid_mdriver.c b/src/drivers/fluid_mdriver.c index 16001af9..53b76346 100644 --- a/src/drivers/fluid_mdriver.c +++ b/src/drivers/fluid_mdriver.c @@ -234,6 +234,7 @@ fluid_midi_driver_t* new_fluid_midi_driver(fluid_settings_t* settings, handle_mi void delete_fluid_midi_driver(fluid_midi_driver_t* driver) { unsigned int i; + fluid_return_if_fail(driver != NULL); for (i = 0; i < FLUID_N_ELEMENTS(fluid_midi_drivers); i++) { if (fluid_midi_drivers[i].name == driver->name) { diff --git a/src/drivers/fluid_winmidi.c b/src/drivers/fluid_winmidi.c index 1242225d..b6503eaf 100644 --- a/src/drivers/fluid_winmidi.c +++ b/src/drivers/fluid_winmidi.c @@ -247,9 +247,7 @@ void delete_fluid_winmidi_driver(fluid_midi_driver_t* p) { fluid_winmidi_driver_t* dev = (fluid_winmidi_driver_t*) p; - - if(dev == NULL) - return; + fluid_return_if_fail (dev != NULL); if (dev->hmidiin != NULL) { fluid_atomic_int_set (&dev->closing, TRUE); diff --git a/src/sfloader/fluid_ramsfont.c b/src/sfloader/fluid_ramsfont.c index d6039caf..43d27eb7 100644 --- a/src/sfloader/fluid_ramsfont.c +++ b/src/sfloader/fluid_ramsfont.c @@ -251,6 +251,7 @@ delete_fluid_ramsfont (fluid_ramsfont_t* sfont) { fluid_list_t *list; fluid_rampreset_t* preset; + fluid_return_if_fail(sfont != NULL); /* Check that no samples are currently used */ for (list = sfont->sample; list; list = fluid_list_next(list)) { @@ -534,25 +535,21 @@ new_fluid_rampreset(fluid_ramsfont_t* sfont) } /* Delete a RAM SoundFont preset */ -static int +static void delete_fluid_rampreset (fluid_rampreset_t* preset) { - int err = FLUID_OK; fluid_preset_zone_t* zone; fluid_rampreset_voice_t *data; + fluid_return_if_fail(preset != NULL); if (preset->global_zone != NULL) { - if (delete_fluid_preset_zone(preset->global_zone) != FLUID_OK) { - err = FLUID_FAILED; - } + delete_fluid_preset_zone(preset->global_zone); preset->global_zone = NULL; } zone = preset->zone; while (zone != NULL) { preset->zone = zone->next; - if (delete_fluid_preset_zone(zone) != FLUID_OK) { - err = FLUID_FAILED; - } + delete_fluid_preset_zone(zone) != FLUID_OK); zone = preset->zone; } @@ -570,7 +567,6 @@ delete_fluid_rampreset (fluid_rampreset_t* preset) preset->presetvoices = NULL; FLUID_FREE(preset); - return err; } /* Get a RAM SoundFont preset bank */ @@ -1217,14 +1213,12 @@ new_fluid_ramsample (void) * @param sample Sample to delete * @return #FLUID_OK */ -int +void delete_fluid_ramsample (fluid_sample_t* sample) { + fluid_return_if_fail(sample != NULL); + /* same as delete_fluid_sample, plus frees the data */ - if (sample->data != NULL) { FLUID_FREE(sample->data); - } - sample->data = NULL; FLUID_FREE(sample); - return FLUID_OK; } diff --git a/src/synth/fluid_event.c b/src/synth/fluid_event.c index 83438bc3..d654710b 100644 --- a/src/synth/fluid_event.c +++ b/src/synth/fluid_event.c @@ -75,9 +75,7 @@ new_fluid_event() void delete_fluid_event(fluid_event_t* evt) { - if (evt == NULL) { - return; - } + fluid_return_if_fail(evt != NULL); FLUID_FREE(evt); } diff --git a/src/synth/fluid_tuning.c b/src/synth/fluid_tuning.c index d0188a35..81424f74 100644 --- a/src/synth/fluid_tuning.c +++ b/src/synth/fluid_tuning.c @@ -94,11 +94,10 @@ fluid_tuning_duplicate (fluid_tuning_t *tuning) void delete_fluid_tuning (fluid_tuning_t *tuning) { - if(tuning != NULL) - { - if (tuning->name) FLUID_FREE (tuning->name); - FLUID_FREE (tuning); - } + fluid_return_if_fail(tuning != NULL); + + FLUID_FREE (tuning->name); + FLUID_FREE (tuning); } /* Add a reference to a tuning object */ diff --git a/src/synth/fluid_voice.c b/src/synth/fluid_voice.c index 08c48355..5029b5af 100644 --- a/src/synth/fluid_voice.c +++ b/src/synth/fluid_voice.c @@ -220,9 +220,8 @@ new_fluid_voice(fluid_real_t output_rate) int delete_fluid_voice(fluid_voice_t* voice) { - if (voice == NULL) { - return FLUID_OK; - } + fluid_return_val_if_fail(voice != NULL, FLUID_OK); + if (!voice->can_access_rvoice || !voice->can_access_overflow_rvoice) { /* stop rvoice before deleting voice! */ return FLUID_FAILED; diff --git a/src/utils/fluid_sys.c b/src/utils/fluid_sys.c index f25870a0..d2f4a665 100644 --- a/src/utils/fluid_sys.c +++ b/src/utils/fluid_sys.c @@ -745,9 +745,7 @@ void delete_fluid_timer (fluid_timer_t *timer) { int auto_destroy; - - if(timer == NULL) - return; + fluid_return_if_fail(timer != NULL); auto_destroy = timer->auto_destroy; @@ -1092,8 +1090,7 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void* data) void delete_fluid_server_socket(fluid_server_socket_t* server_socket) { - if(server_socket == NULL) - return; + fluid_return_if_fail(server_socket != NULL); server_socket->cont = 0; if (server_socket->socket != INVALID_SOCKET) { @@ -1286,8 +1283,7 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void* data) void delete_fluid_server_socket(fluid_server_socket_t *server_socket) { - if(server_socket == NULL) - return; + fluid_return_if_fail(server_socket != NULL); server_socket->cont = 0; diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 908c28ad..7ba6bb92 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -148,6 +148,7 @@ new_fluid_cond_mutex (void) static FLUID_INLINE void delete_fluid_cond_mutex (fluid_cond_mutex_t *m) { + fluid_return_if_fail(m != NULL); g_mutex_clear (m); g_free (m); } @@ -170,6 +171,7 @@ new_fluid_cond (void) static FLUID_INLINE void delete_fluid_cond (fluid_cond_t *cond) { + fluid_return_if_fail(cond != NULL); g_cond_clear (cond); g_free (cond); }