]> git.tue.mpg.de Git - paraslash.git/commitdiff
Assume that score_open() and score_clear() always succeed.
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 22 Mar 2022 18:33:52 +0000 (19:33 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 17 Oct 2022 18:36:21 +0000 (20:36 +0200)
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.

afs.c
afs.h
mood.c
score.c

diff --git a/afs.c b/afs.c
index c162cef44c65897335c8455e570fd92c1d11efc4..b2cdb6c46ef85a7526538342b27604456e7cf648 100644 (file)
--- 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 f12bf369cd430d1ec6c6be321bf7e5756daf1e1a..760ed7565ab1a26321ca4a819816e7cf34735987 100644 (file)
--- 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 9c2571aa054287859ca4f041f2384900999be33b..3df8c1dbe27d86085d7b397ab6210955904cef89 100644 (file)
--- 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 fa12663cb936535cd43d623c37b331a86896a1cb..10cd254a8dba2926614d0a76ffa29cad90e74792 100644 (file)
--- 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. */