diff options
| author | Simon Tatham <anakin@pobox.com> | 2023-04-20 13:35:58 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2023-04-20 17:21:12 +0100 |
| commit | bb561ee3b18be69e52b17cedde50eac96ea409da (patch) | |
| tree | 43b58f8e05550dfad4936e63cccb7ebe9a7c7ed5 | |
| parent | 16f997d34c7b435d3fcf5774c700579e188b017f (diff) | |
| download | puzzles-bb561ee3b18be69e52b17cedde50eac96ea409da.zip puzzles-bb561ee3b18be69e52b17cedde50eac96ea409da.tar.gz puzzles-bb561ee3b18be69e52b17cedde50eac96ea409da.tar.bz2 puzzles-bb561ee3b18be69e52b17cedde50eac96ea409da.tar.xz | |
Use a dedicated free function to free dsfs.
No functional change: currently, this just wraps the previous sfree
call.
| -rw-r--r-- | auxiliary/divvy-test.c | 2 | ||||
| -rw-r--r-- | bridges.c | 4 | ||||
| -rw-r--r-- | divvy.c | 2 | ||||
| -rw-r--r-- | dominosa.c | 2 | ||||
| -rw-r--r-- | dsf.c | 5 | ||||
| -rw-r--r-- | filling.c | 12 | ||||
| -rw-r--r-- | galaxies.c | 6 | ||||
| -rw-r--r-- | grid.c | 2 | ||||
| -rw-r--r-- | keen.c | 16 | ||||
| -rw-r--r-- | loopy.c | 6 | ||||
| -rw-r--r-- | map.c | 2 | ||||
| -rw-r--r-- | net.c | 2 | ||||
| -rw-r--r-- | palisade.c | 14 | ||||
| -rw-r--r-- | pearl.c | 6 | ||||
| -rw-r--r-- | puzzles.h | 1 | ||||
| -rw-r--r-- | range.c | 4 | ||||
| -rw-r--r-- | signpost.c | 2 | ||||
| -rw-r--r-- | singles.c | 2 | ||||
| -rw-r--r-- | slant.c | 6 | ||||
| -rw-r--r-- | solo.c | 22 | ||||
| -rw-r--r-- | tents.c | 2 | ||||
| -rw-r--r-- | tracks.c | 6 | ||||
| -rw-r--r-- | unfinished/separate.c | 4 | ||||
| -rw-r--r-- | unfinished/slide.c | 4 |
24 files changed, 70 insertions, 64 deletions
diff --git a/auxiliary/divvy-test.c b/auxiliary/divvy-test.c index b6c9584..b7e3d6c 100644 --- a/auxiliary/divvy-test.c +++ b/auxiliary/divvy-test.c @@ -94,7 +94,7 @@ int main(int argc, char **argv) printf("\n"); } printf("\n"); - sfree(dsf); + dsf_free(dsf); } printf("%d retries needed for %d successes\n", fail_counter, tries); @@ -1820,8 +1820,8 @@ static game_state *dup_game(const game_state *state) static void free_game(game_state *state) { if (--state->solver->refcount <= 0) { - sfree(state->solver->dsf); - sfree(state->solver->tmpdsf); + dsf_free(state->solver->dsf); + dsf_free(state->solver->tmpdsf); sfree(state->solver); } @@ -641,7 +641,7 @@ int *divvy_rectangle_attempt(int w, int h, int k, random_state *rs) */ sfree(order); sfree(tmp); - sfree(tmpdsf); + dsf_free(tmpdsf); sfree(own); sfree(sizes); sfree(queue); @@ -510,7 +510,7 @@ static void solver_free_scratch(struct solver_scratch *sc) sfree(sc->pc_scratch); sfree(sc->pc_scratch2); sfree(sc->dc_scratch); - sfree(sc->dsf_scratch); + dsf_free(sc->dsf_scratch); sfree(sc); } @@ -86,6 +86,11 @@ int *snew_dsf(int size) return ret; } +void dsf_free(int *dsf) +{ + sfree(dsf); +} + int dsf_canonify(int *dsf, int index) { return edsf_canonify(dsf, index, NULL); @@ -464,7 +464,7 @@ retry: for (i = 0; i < sz; ++i) board[i] = dsf_size(dsf, i); merge_ones(board, w, h); - sfree(dsf); + dsf_free(dsf); } static void merge(int *dsf, int *connected, int a, int b) { @@ -1118,11 +1118,11 @@ static bool solver(const int *orig, int w, int h, char **solution) { (*solution)[sz + 1] = '\0'; } - sfree(ss.dsf); + dsf_free(ss.dsf); sfree(ss.board); sfree(ss.connected); sfree(ss.bm); - sfree(ss.bmdsf); + dsf_free(ss.bmdsf); sfree(ss.bmminsize); return !ss.nempty; @@ -1226,7 +1226,7 @@ static void minimize_clue_set(int *board, int w, int h, random_state *rs) } } sfree(next); - sfree(dsf); + dsf_free(dsf); /* * Now go through individual cells, in the same shuffled order, @@ -1617,7 +1617,7 @@ static game_state *execute_move(const game_state *state, const char *move) int *dsf = make_dsf(NULL, new_state->board, w, h); int i; for (i = 0; i < sz && new_state->board[i] == dsf_size(dsf, i); ++i); - sfree(dsf); + dsf_free(dsf); if (i == sz) new_state->completed = true; } @@ -1717,7 +1717,7 @@ static void game_free_drawstate(drawing *dr, game_drawstate *ds) sfree(ds->v); sfree(ds->flags); sfree(ds->border_scratch); - sfree(ds->dsf_scratch); + dsf_free(ds->dsf_scratch); sfree(ds); } @@ -1817,7 +1817,7 @@ static solver_ctx *new_solver(game_state *state) static void free_solver(solver_ctx *sctx) { sfree(sctx->scratch); - sfree(sctx->dsf); + dsf_free(sctx->dsf); sfree(sctx->iscratch); sfree(sctx); } @@ -3240,7 +3240,7 @@ static bool check_complete(const game_state *state, int *dsf, int *colours) sfree(sqdata); if (free_dsf) - sfree(dsf); + dsf_free(dsf); return ret; } @@ -4095,7 +4095,7 @@ static void game_print(drawing *dr, const game_state *state, int sz) black : white), black); } - sfree(dsf); + dsf_free(dsf); sfree(colours); sfree(coords); } @@ -493,7 +493,7 @@ static void grid_trim_vigorously(grid *g) g->num_dots = newdots; sfree(dotpairs); - sfree(dsf); + dsf_free(dsf); sfree(dots); sfree(faces); } @@ -1284,7 +1284,7 @@ done sfree(order); sfree(revorder); sfree(singletons); - sfree(dsf); + dsf_free(dsf); sfree(clues); sfree(cluevals); sfree(soln); @@ -1310,12 +1310,12 @@ static const char *validate_desc(const game_params *params, const char *desc) dsf = snew_dsf(a); ret = parse_block_structure(&p, w, dsf); if (ret) { - sfree(dsf); + dsf_free(dsf); return ret; } if (*p != ',') { - sfree(dsf); + dsf_free(dsf); return "Expected ',' after block structure description"; } p++; @@ -1330,21 +1330,21 @@ static const char *validate_desc(const game_params *params, const char *desc) /* these clues need no validation */ } else if (*p == 'd' || *p == 's') { if (dsf_size(dsf, i) != 2) { - sfree(dsf); + dsf_free(dsf); return "Subtraction and division blocks must have area 2"; } } else if (!*p) { - sfree(dsf); + dsf_free(dsf); return "Too few clues for block structure"; } else { - sfree(dsf); + dsf_free(dsf); return "Unrecognised clue type"; } p++; while (*p && isdigit((unsigned char)*p)) p++; } } - sfree(dsf); + dsf_free(dsf); if (*p) return "Too many clues for block structure"; @@ -1459,7 +1459,7 @@ static void free_game(game_state *state) sfree(state->grid); sfree(state->pencil); if (--state->clues->refcount <= 0) { - sfree(state->clues->dsf); + dsf_free(state->clues->dsf); sfree(state->clues->clues); sfree(state->clues); } @@ -426,7 +426,7 @@ static solver_state *new_solver_state(const game_state *state, int diff) { static void free_solver_state(solver_state *sstate) { if (sstate) { free_game(sstate->state); - sfree(sstate->dotdsf); + dsf_free(sstate->dotdsf); sfree(sstate->looplen); sfree(sstate->dot_solved); sfree(sstate->face_solved); @@ -437,7 +437,7 @@ static void free_solver_state(solver_state *sstate) { /* OK, because sfree(NULL) is a no-op */ sfree(sstate->dlines); - sfree(sstate->linedsf); + dsf_free(sstate->linedsf); sfree(sstate); } @@ -1769,7 +1769,7 @@ static bool check_completion(game_state *state) } sfree(component_state); - sfree(dsf); + dsf_free(dsf); return ret; } @@ -1802,7 +1802,7 @@ static const char *parse_edge_list(const game_params *params, err = NULL; /* no error */ out: - sfree(dsf); + dsf_free(dsf); return err; } @@ -832,7 +832,7 @@ static int net_solver(int w, int h, unsigned char *tiles, sfree(tilestate); sfree(edgestate); sfree(deadends); - sfree(equivalence); + dsf_free(equivalence); return j; } @@ -565,11 +565,11 @@ static bool is_solved(const game_params *params, clue *clues, } } - sfree(dsf); + dsf_free(dsf); return true; error: - sfree(dsf); + dsf_free(dsf); return false; } @@ -594,7 +594,7 @@ static bool solver(const game_params *params, clue *clues, borderflag *borders) changed |= solver_equivalent_edges(&ctx); } while (changed); - sfree(ctx.dsf); + dsf_free(ctx.dsf); return is_solved(params, clues, borders); } @@ -648,7 +648,7 @@ static char *new_game_desc(const game_params *params, random_state *rs, ++attempts; setmem(soln, '@', wh); - sfree(dsf); + dsf_free(dsf); dsf = divvy_rectangle(w, h, k, rs); for (r = 0; r < h; ++r) @@ -683,7 +683,7 @@ static char *new_game_desc(const game_params *params, random_state *rs, sfree(scratch_borders); sfree(rim); sfree(shuf); - sfree(dsf); + dsf_free(dsf); char *output = snewn(wh + 1, char), *p = output; @@ -1252,8 +1252,8 @@ static void game_redraw(drawing *dr, game_drawstate *ds, draw_tile(dr, ds, r, c, ds->grid[i], clue); } - sfree(black_border_dsf); - sfree(yellow_border_dsf); + dsf_free(black_border_dsf); + dsf_free(yellow_border_dsf); } static float game_anim_length(const game_state *oldstate, @@ -891,7 +891,7 @@ cleanup: } sfree(dsfsize); - sfree(dsf); + dsf_free(dsf); sfree(workspace); assert(ret >= 0); return ret; @@ -1582,7 +1582,7 @@ static bool check_completion(game_state *state, bool mark) for (y = 0; y < h; y++) { if (!dsf_update_completion(state, x, y, R, dsf) || !dsf_update_completion(state, x, y, D, dsf)) { - sfree(dsf); + dsf_free(dsf); return false; } } @@ -1665,7 +1665,7 @@ static bool check_completion(game_state *state, bool mark) * part of a single loop, for which our counter variables * nsilly,nloop,npath are enough. */ sfree(component_state); - sfree(dsf); + dsf_free(dsf); /* * Check that no clues are contradicted. This code is similar to @@ -427,6 +427,7 @@ char *button2label(int button); * dsf.c */ int *snew_dsf(int size); +void dsf_free(int *dsf); void print_dsf(int *dsf, int size); @@ -1492,7 +1492,7 @@ static bool find_errors(const game_state *state, bool *report) int biggest, canonical; if (!report) { - sfree(dsf); + dsf_free(dsf); goto found_error; } @@ -1517,7 +1517,7 @@ static bool find_errors(const game_state *state, bool *report) if (state->grid[i] != BLACK && dsf_canonify(dsf, i) != canonical) report[i] = true; } - sfree(dsf); + dsf_free(dsf); free_game(dup); return false; /* if report != NULL, this is ignored */ @@ -500,7 +500,7 @@ static void free_game(game_state *state) sfree(state->flags); sfree(state->next); sfree(state->prev); - sfree(state->dsf); + dsf_free(state->dsf); sfree(state->numsi); sfree(state); } @@ -562,7 +562,7 @@ static bool check_complete(game_state *state, unsigned flags) } } - sfree(dsf); + dsf_free(dsf); return !(error > 0); } @@ -325,10 +325,10 @@ static void free_scratch(struct solver_scratch *sc) { sfree(sc->vbitmap); sfree(sc->slashval); - sfree(sc->equiv); + dsf_free(sc->equiv); sfree(sc->border); sfree(sc->exits); - sfree(sc->connected); + dsf_free(sc->connected); sfree(sc); } @@ -1064,7 +1064,7 @@ static void slant_generate(int w, int h, signed char *soln, random_state *rs) } sfree(indices); - sfree(connected); + dsf_free(connected); } static char *new_game_desc(const game_params *params, random_state *rs, @@ -3693,7 +3693,7 @@ static char *new_game_desc(const game_params *params, random_state *rs, dsf_to_blocks (dsf, blocks, cr, cr); - sfree(dsf); + dsf_free(dsf); } else { /* basic Sudoku mode */ for (y = 0; y < cr; y++) for (x = 0; x < cr; x++) @@ -3926,7 +3926,7 @@ static const char *spec_to_dsf(const char **pdesc, int **pdsf, else if (*desc >= 'a' && *desc <= 'z') c = *desc - 'a' + 1; else { - sfree(dsf); + dsf_free(dsf); return "Invalid character in game description"; } desc++; @@ -3941,7 +3941,7 @@ static const char *spec_to_dsf(const char **pdesc, int **pdsf, * side of it. */ if (pos >= 2*cr*(cr-1)) { - sfree(dsf); + dsf_free(dsf); return "Too much data in block structure specification"; } @@ -3971,7 +3971,7 @@ static const char *spec_to_dsf(const char **pdesc, int **pdsf, * edge at the end. */ if (pos != 2*cr*(cr-1)+1) { - sfree(dsf); + dsf_free(dsf); return "Not enough data in block structure specification"; } @@ -4042,7 +4042,7 @@ static const char *validate_block_desc(const char **pdesc, int cr, int area, if (canons[c] == j) { counts[c]++; if (counts[c] > max_nr_squares) { - sfree(dsf); + dsf_free(dsf); sfree(canons); sfree(counts); return "A jigsaw block is too big"; @@ -4052,7 +4052,7 @@ static const char *validate_block_desc(const char **pdesc, int cr, int area, if (c == ncanons) { if (ncanons >= max_nr_blocks) { - sfree(dsf); + dsf_free(dsf); sfree(canons); sfree(counts); return "Too many distinct jigsaw blocks"; @@ -4064,14 +4064,14 @@ static const char *validate_block_desc(const char **pdesc, int cr, int area, } if (ncanons < min_nr_blocks) { - sfree(dsf); + dsf_free(dsf); sfree(canons); sfree(counts); return "Not enough distinct jigsaw blocks"; } for (c = 0; c < ncanons; c++) { if (counts[c] < min_nr_squares) { - sfree(dsf); + dsf_free(dsf); sfree(canons); sfree(counts); return "A jigsaw block is too small"; @@ -4081,7 +4081,7 @@ static const char *validate_block_desc(const char **pdesc, int cr, int area, sfree(counts); } - sfree(dsf); + dsf_free(dsf); return NULL; } @@ -4172,7 +4172,7 @@ static game_state *new_game(midend *me, const game_params *params, err = spec_to_dsf(&desc, &dsf, cr, area); assert(err == NULL); dsf_to_blocks(dsf, state->blocks, cr, cr); - sfree(dsf); + dsf_free(dsf); } else { int x, y; @@ -4190,7 +4190,7 @@ static game_state *new_game(midend *me, const game_params *params, err = spec_to_dsf(&desc, &dsf, cr, area); assert(err == NULL); dsf_to_blocks(dsf, state->kblocks, cr, area); - sfree(dsf); + dsf_free(dsf); make_blocks_from_whichblock(state->kblocks); assert(*desc == ','); @@ -2302,7 +2302,7 @@ static int *find_errors(const game_state *state, char *grid) #undef TENT sfree(tmp); - sfree(dsf); + dsf_free(dsf); return ret; } @@ -1412,7 +1412,7 @@ static int solve_check_loop(game_state *state) } } - sfree(dsf); + dsf_free(dsf); return did; } @@ -1605,7 +1605,7 @@ static int tracks_solve(game_state *state, int diff, int *max_diff_out) break; } - sfree(sc->dsf); + dsf_free(sc->dsf); if (max_diff_out) *max_diff_out = max_diff; @@ -1999,7 +1999,7 @@ static bool check_completion(game_state *state, bool mark) state->completed = ret; if (ret) set_flash_data(state); } - sfree(dsf); + dsf_free(dsf); return ret; } diff --git a/unfinished/separate.c b/unfinished/separate.c index 9ed1cac..b064f18 100644 --- a/unfinished/separate.c +++ b/unfinished/separate.c @@ -239,7 +239,7 @@ static struct solver_scratch *solver_scratch_new(int w, int h, int k) static void solver_scratch_free(struct solver_scratch *sc) { - sfree(sc->dsf); + dsf_free(sc->dsf); sfree(sc->size); sfree(sc->contents); sfree(sc->disconnect); @@ -615,7 +615,7 @@ static unsigned char *generate(int w, int h, int k, random_state *rs) retries = k*k; /* reset this counter, and continue */ } - sfree(dsf); + dsf_free(dsf); } while (m == 0); sfree(gen_lock); diff --git a/unfinished/slide.c b/unfinished/slide.c index fe573e8..d607b39 100644 --- a/unfinished/slide.c +++ b/unfinished/slide.c @@ -824,7 +824,7 @@ static void generate_board(int w, int h, int *rtx, int *rty, int *minmoves, } } - sfree(dsf); + dsf_free(dsf); sfree(list); sfree(tried_merge); sfree(board2); @@ -2260,7 +2260,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, status_bar(dr, statusbuf); } - sfree(dsf); + dsf_free(dsf); sfree(board); } |