From: Andre Noll Date: Tue, 22 Mar 2022 18:33:52 +0000 (+0100) Subject: Assume that score_open() and score_clear() always succeed. X-Git-Tag: v0.7.2~14^2~3 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=d5cf034cce34635e065d91350475199adec80232;p=paraslash.git Assume that score_open() and score_clear() always succeed. Since the score table has only volatile columns, the only possible error is memory exhaustion, in which case we can only abort anyway. This patch changes score_open() to abort if osl_open() fails. This allows us to let score_clear() return void. We can't get rid of the return value of score_open(), however, since a pointer to this function is stored the afs table operations structure. --- diff --git a/afs.c b/afs.c index c162cef4..b2cdb6c4 100644 --- a/afs.c +++ b/afs.c @@ -534,11 +534,7 @@ static int com_select_callback(struct afs_callback_arg *aca) ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr); assert(ret >= 0); arg = lls_input(0, aca->lpr); - ret = clear_score_table(); - if (ret < 0) { - para_printf(&aca->pbout, "could not clear score table\n"); - goto free_lpr; - } + score_clear(); if (current_play_mode == PLAY_MODE_MOOD) close_current_mood(); else diff --git a/afs.h b/afs.h index f12bf369..760ed756 100644 --- a/afs.h +++ b/afs.h @@ -236,7 +236,7 @@ int get_score_and_aft_row(struct osl_row *score_row, long *score, struct osl_row int score_add(const struct osl_row *row, long score); int score_update(const struct osl_row *aft_row, long new_score); int score_delete(const struct osl_row *aft_row); -int clear_score_table(void); +void score_clear(void); bool row_belongs_to_score_table(const struct osl_row *aft_row); /* attribute */ diff --git a/mood.c b/mood.c index 9c2571aa..3df8c1db 100644 --- a/mood.c +++ b/mood.c @@ -655,9 +655,7 @@ static int reload_current_mood(void) char *mood_name = NULL; assert(current_mood); - ret = clear_score_table(); - if (ret < 0) - return ret; + score_clear(); PARA_NOTICE_LOG("reloading %s\n", current_mood->name? current_mood->name : "(dummy)"); if (current_mood->name) diff --git a/score.c b/score.c index fa12663c..10cd254a 100644 --- a/score.c +++ b/score.c @@ -279,18 +279,17 @@ static void score_close(void) static int score_open(__a_unused const char *dir) { - return osl(osl_open_table(&score_table_desc, &score_table)); + assert(osl_open_table(&score_table_desc, &score_table) >= 0); + return 1; } /** * Remove all entries from the score table, but keep the table open. - * - * \return Standard. */ -int clear_score_table(void) +void score_clear(void) { score_close(); - return score_open(NULL); + score_open(NULL); } /** The score table stores (aft row, score) pairs in memory. */