shithub: puzzles

Download patch

ref: bb561ee3b18be69e52b17cedde50eac96ea409da
parent: 16f997d34c7b435d3fcf5774c700579e188b017f
author: Simon Tatham <anakin@pobox.com>
date: Thu Apr 20 09:35:58 EDT 2023

Use a dedicated free function to free dsfs.

No functional change: currently, this just wraps the previous sfree
call.

--- a/auxiliary/divvy-test.c
+++ b/auxiliary/divvy-test.c
@@ -94,7 +94,7 @@
 	    printf("\n");
 	}
 	printf("\n");
-	sfree(dsf);
+	dsf_free(dsf);
     }
 
     printf("%d retries needed for %d successes\n", fail_counter, tries);
--- a/bridges.c
+++ b/bridges.c
@@ -1820,8 +1820,8 @@
 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);
     }
 
--- a/divvy.c
+++ b/divvy.c
@@ -641,7 +641,7 @@
      */
     sfree(order);
     sfree(tmp);
-    sfree(tmpdsf);
+    dsf_free(tmpdsf);
     sfree(own);
     sfree(sizes);
     sfree(queue);
--- a/dominosa.c
+++ b/dominosa.c
@@ -510,7 +510,7 @@
     sfree(sc->pc_scratch);
     sfree(sc->pc_scratch2);
     sfree(sc->dc_scratch);
-    sfree(sc->dsf_scratch);
+    dsf_free(sc->dsf_scratch);
     sfree(sc);
 }
 
--- a/dsf.c
+++ b/dsf.c
@@ -86,6 +86,11 @@
     return ret;
 }
 
+void dsf_free(int *dsf)
+{
+    sfree(dsf);
+}
+
 int dsf_canonify(int *dsf, int index)
 {
     return edsf_canonify(dsf, index, NULL);
--- a/filling.c
+++ b/filling.c
@@ -464,7 +464,7 @@
     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 @@
         (*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 @@
 	}
     }
     sfree(next);
-    sfree(dsf);
+    dsf_free(dsf);
 
     /*
      * Now go through individual cells, in the same shuffled order,
@@ -1617,7 +1617,7 @@
         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 @@
     sfree(ds->v);
     sfree(ds->flags);
     sfree(ds->border_scratch);
-    sfree(ds->dsf_scratch);
+    dsf_free(ds->dsf_scratch);
     sfree(ds);
 }
 
--- a/galaxies.c
+++ b/galaxies.c
@@ -1817,7 +1817,7 @@
 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 @@
 
     sfree(sqdata);
     if (free_dsf)
-	sfree(dsf);
+	dsf_free(dsf);
 
     return ret;
 }
@@ -4095,7 +4095,7 @@
 			     black : white), black);
 	    }
 
-    sfree(dsf);
+    dsf_free(dsf);
     sfree(colours);
     sfree(coords);
 }
--- a/grid.c
+++ b/grid.c
@@ -493,7 +493,7 @@
     g->num_dots = newdots;
 
     sfree(dotpairs);
-    sfree(dsf);
+    dsf_free(dsf);
     sfree(dots);
     sfree(faces);
 }
--- a/keen.c
+++ b/keen.c
@@ -1284,7 +1284,7 @@
     sfree(order);
     sfree(revorder);
     sfree(singletons);
-    sfree(dsf);
+    dsf_free(dsf);
     sfree(clues);
     sfree(cluevals);
     sfree(soln);
@@ -1310,12 +1310,12 @@
     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,14 +1330,14 @@
 		/* 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++;
@@ -1344,7 +1344,7 @@
 	    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 @@
     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);
     }
--- a/loopy.c
+++ b/loopy.c
@@ -426,7 +426,7 @@
 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 @@
 
         /* OK, because sfree(NULL) is a no-op */
         sfree(sstate->dlines);
-        sfree(sstate->linedsf);
+        dsf_free(sstate->linedsf);
 
         sfree(sstate);
     }
@@ -1769,7 +1769,7 @@
     }
 
     sfree(component_state);
-    sfree(dsf);
+    dsf_free(dsf);
 
     return ret;
 }
--- a/map.c
+++ b/map.c
@@ -1802,7 +1802,7 @@
     err = NULL; /* no error */
 
   out:
-    sfree(dsf);
+    dsf_free(dsf);
     return err;
 }
 
--- a/net.c
+++ b/net.c
@@ -832,7 +832,7 @@
     sfree(tilestate);
     sfree(edgestate);
     sfree(deadends);
-    sfree(equivalence);
+    dsf_free(equivalence);
 
     return j;
 }
--- a/palisade.c
+++ b/palisade.c
@@ -565,11 +565,11 @@
         }
     }
 
-    sfree(dsf);
+    dsf_free(dsf);
     return true;
 
 error:
-    sfree(dsf);
+    dsf_free(dsf);
     return false;
 }
 
@@ -594,7 +594,7 @@
         changed |= solver_equivalent_edges(&ctx);
     } while (changed);
 
-    sfree(ctx.dsf);
+    dsf_free(ctx.dsf);
 
     return is_solved(params, clues, borders);
 }
@@ -648,7 +648,7 @@
         ++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 @@
     sfree(scratch_borders);
     sfree(rim);
     sfree(shuf);
-    sfree(dsf);
+    dsf_free(dsf);
 
     char *output = snewn(wh + 1, char), *p = output;
 
@@ -1252,8 +1252,8 @@
             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,
--- a/pearl.c
+++ b/pearl.c
@@ -891,7 +891,7 @@
     }
 
     sfree(dsfsize);
-    sfree(dsf);
+    dsf_free(dsf);
     sfree(workspace);
     assert(ret >= 0);
     return ret;
@@ -1582,7 +1582,7 @@
         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 @@
      * 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
--- a/puzzles.h
+++ b/puzzles.h
@@ -427,6 +427,7 @@
  * dsf.c
  */
 int *snew_dsf(int size);
+void dsf_free(int *dsf);
 
 void print_dsf(int *dsf, int size);
 
--- a/range.c
+++ b/range.c
@@ -1492,7 +1492,7 @@
         int biggest, canonical;
 
         if (!report) {
-            sfree(dsf);
+            dsf_free(dsf);
             goto found_error;
         }
 
@@ -1517,7 +1517,7 @@
             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 */
--- a/signpost.c
+++ b/signpost.c
@@ -500,7 +500,7 @@
     sfree(state->flags);
     sfree(state->next);
     sfree(state->prev);
-    sfree(state->dsf);
+    dsf_free(state->dsf);
     sfree(state->numsi);
     sfree(state);
 }
--- a/singles.c
+++ b/singles.c
@@ -562,7 +562,7 @@
         }
     }
 
-    sfree(dsf);
+    dsf_free(dsf);
     return !(error > 0);
 }
 
--- a/slant.c
+++ b/slant.c
@@ -325,10 +325,10 @@
 {
     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 @@
     }
 
     sfree(indices);
-    sfree(connected);
+    dsf_free(connected);
 }
 
 static char *new_game_desc(const game_params *params, random_state *rs,
--- a/solo.c
+++ b/solo.c
@@ -3693,7 +3693,7 @@
 
 	    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 @@
 	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 @@
 	     * 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 @@
      * 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 @@
 		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 @@
 
 	    if (c == ncanons) {
 		if (ncanons >= max_nr_blocks) {
-		    sfree(dsf);
+		    dsf_free(dsf);
 		    sfree(canons);
 		    sfree(counts);
 		    return "Too many distinct jigsaw blocks";
@@ -4064,7 +4064,7 @@
 	}
 
 	if (ncanons < min_nr_blocks) {
-	    sfree(dsf);
+	    dsf_free(dsf);
 	    sfree(canons);
 	    sfree(counts);
 	    return "Not enough distinct jigsaw blocks";
@@ -4071,7 +4071,7 @@
 	}
 	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 @@
 	sfree(counts);
     }
 
-    sfree(dsf);
+    dsf_free(dsf);
     return NULL;
 }
 
@@ -4172,7 +4172,7 @@
 	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 @@
 	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 == ',');
--- a/tents.c
+++ b/tents.c
@@ -2302,7 +2302,7 @@
 #undef TENT
 
     sfree(tmp);
-    sfree(dsf);
+    dsf_free(dsf);
     return ret;
 }
 
--- a/tracks.c
+++ b/tracks.c
@@ -1412,7 +1412,7 @@
         }
     }
 
-    sfree(dsf);
+    dsf_free(dsf);
 
     return did;
 }
@@ -1605,7 +1605,7 @@
         break;
     }
 
-    sfree(sc->dsf);
+    dsf_free(sc->dsf);
 
     if (max_diff_out)
         *max_diff_out = max_diff;
@@ -1999,7 +1999,7 @@
         state->completed = ret;
         if (ret) set_flash_data(state);
     }
-    sfree(dsf);
+    dsf_free(dsf);
     return ret;
 }
 
--- a/unfinished/separate.c
+++ b/unfinished/separate.c
@@ -239,7 +239,7 @@
 
 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 @@
 		retries = k*k;	       /* reset this counter, and continue */
 	}
 
-	sfree(dsf);
+	dsf_free(dsf);
     } while (m == 0);
 
     sfree(gen_lock);
--- a/unfinished/slide.c
+++ b/unfinished/slide.c
@@ -824,7 +824,7 @@
 	}
     }
 
-    sfree(dsf);
+    dsf_free(dsf);
     sfree(list);
     sfree(tried_merge);
     sfree(board2);
@@ -2260,7 +2260,7 @@
 	status_bar(dr, statusbuf);
     }
 
-    sfree(dsf);
+    dsf_free(dsf);
     sfree(board);
 }