From debe0b5737118f7f1806cc133e81549d88340bfd Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 2 Nov 2007 01:00:42 +0100 Subject: [PATCH] score.c: Use the new OSL_DONT_FREE flag for the aft column. The score tables stores in one of its columns a pointer to a row in the audio file table. This means for each admissible file we're allocating space for a void* pointer to store the aft pointer. It's simpler and probably faster to store the afs pointer directly, but of course that pointer must not be freed by the osl. --- score.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/score.c b/score.c index 2707e6a7..58d219ab 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 = 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,7 @@ 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 = aft_row, .size = sizeof(aft_row)}; int ret = osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, &row); if (ret < 0) @@ -221,14 +219,14 @@ 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 = aft_row, .size = sizeof(aft_row)}; return osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, score_row); } @@ -286,7 +284,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); } -- 2.39.2