X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=score.c;h=7d3b024690d432ee9d4fb9b77a0388fabee90e6b;hp=abccb28fe5082df36e88a5e3ba6a01888c808cb8;hb=73f02f72cb49baebff3e0f6946750a5bc0693321;hpb=c2ac39f76d245816a919d94790672fb66e9a7253 diff --git a/score.c b/score.c index abccb28f..7d3b0246 100644 --- a/score.c +++ b/score.c @@ -61,7 +61,7 @@ enum score_table_columns { static struct osl_column_description score_cols[] = { [SCORECOL_AFT_ROW] = { .storage_type = OSL_NO_STORAGE, - .storage_flags = OSL_RBTREE | OSL_FIXED_SIZE | OSL_UNIQUE, + .storage_flags = OSL_RBTREE | OSL_FIXED_SIZE | OSL_UNIQUE | OSL_DONT_FREE, .name = "aft_row", .compare_function = ptr_compare, .data_size = sizeof(void *) @@ -132,9 +132,8 @@ int score_add(const struct osl_row *aft_row, long score) assert(aft_row); size = score_table_desc.column_descriptions[SCORECOL_AFT_ROW].data_size; - score_objs[SCORECOL_AFT_ROW].data = para_malloc(size); + score_objs[SCORECOL_AFT_ROW].data = (struct osl_row *)aft_row; score_objs[SCORECOL_AFT_ROW].size = size; - *(const void **)(score_objs[SCORECOL_AFT_ROW].data) = aft_row; size = score_table_desc.column_descriptions[SCORECOL_SCORE].data_size; score_objs[SCORECOL_SCORE].data = para_malloc(size); @@ -145,7 +144,6 @@ int score_add(const struct osl_row *aft_row, long score) ret = osl_add_row(score_table, score_objs); if (ret < 0) { PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); - free(score_objs[SCORECOL_AFT_ROW].data); free(score_objs[SCORECOL_SCORE].data); } return ret; @@ -180,7 +178,8 @@ int score_update(const struct osl_row *aft_row, long percent) struct osl_row *row; long new_score; unsigned n, new_pos; - struct osl_object obj = {.data = &aft_row, .size = sizeof(void **)}; + struct osl_object obj = {.data = (struct osl_row *)aft_row, + .size = sizeof(aft_row)}; int ret = osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, &row); if (ret < 0) @@ -221,14 +220,15 @@ int get_score_and_aft_row(struct osl_row *score_row, long *score, ret = osl_get_object(score_table, score_row, SCORECOL_AFT_ROW, &obj); if (ret < 0) return ret; - *aft_row = *(void **)obj.data; + *aft_row = obj.data; return 1; } static int get_score_row_from_aft_row(const struct osl_row *aft_row, struct osl_row **score_row) { - struct osl_object obj = {.data = &aft_row, .size = sizeof(void **)}; + struct osl_object obj = {.data = (struct osl_row *)aft_row, + .size = sizeof(aft_row)}; return osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, score_row); } @@ -286,7 +286,7 @@ int score_get_best(struct osl_row **aft_row, long *score) ret = osl_get_object(score_table, row, SCORECOL_AFT_ROW, &obj); if (ret < 0) return ret; - *aft_row = *(void **)obj.data; + *aft_row = obj.data; return get_score_of_row(row, score); } @@ -357,26 +357,27 @@ static int score_open(__a_unused const char *dir) return osl_open_table(&score_table_desc, &score_table); } -static int score_event_handler(enum afs_events event, struct para_buffer *pb, - void *data) +/** + * Remove all entries from the score table, but keep the table open. + * + * \return Standard. + */ +int clear_score_table(void) { - int ret; + score_close(); + return score_open(NULL); +} - switch(event) { - case ATTRIBUTE_ADD: - case ATTRIBUTE_REMOVE: - case ATTRIBUTE_RENAME: { - score_close(); - return score_open(NULL); - } - default: return 1; - } +static int score_event_handler(__a_unused enum afs_events event, + __a_unused struct para_buffer *pb, __a_unused void *data) +{ + return 1; } /** * Initialize the scoring subsystem. * - * \param t The members of \t are filled in by the function. + * \param t The members of \a t are filled in by the function. */ void score_init(struct afs_table *t) {