Commits

Shlomi Fish  committed d65fc2e

Various compilation and run-time fixes.

valgrind complained and the program crashed in release mode.

  • Participants
  • Parent commits f7ada59
  • Branches make-code-suitable-for-fc-solve

Comments (0)

Files changed (5)

File patsolve/config.h

 #define NTPILES 4       /* number of T cells */
 #endif
 
+#ifndef DEBUG
 #define DEBUG 0
+#endif
 
 #ifdef WIN32
 typedef unsigned char u_char;

File patsolve/pat.c

 #if DEBUG
 		printf("%d positions generated.\n", soft_thread->Total_generated);
 		printf("%d unique positions.\n", soft_thread->Total_positions);
-		printf("Mem_remain = %ld\n", Mem_remain);
+		printf("Mem_remain = %ld\n", soft_thread->Mem_remain);
 #endif
 	}
 }

File patsolve/pat.h

 extern void free_buckets(fc_solve_soft_thread_t * soft_thread);
 extern void free_clusters(fc_solve_soft_thread_t * soft_thread);
 extern void free_blocks(fc_solve_soft_thread_t * soft_thread);
+extern void hash_layout(fc_solve_soft_thread_t * soft_thread);
 
 #endif /* #ifndef FC_SOLVE_PATSOLVE_PAT_H */

File patsolve/patmain.c

 #if DEBUG
 extern int Clusternum[];
 
-void quit(int sig)
+void quit(fc_solve_soft_thread_t * soft_thread, int sig)
 {
 	int i, c;
-	extern void print_queue(void);
-	extern int Clusternum[];
+	extern void print_queue(fc_solve_soft_thread_t * soft_thread);
 
-	print_queue();
+	print_queue(soft_thread);
 	c = 0;
 	for (i = 0; i <= 0xFFFF; i++) {
-		if (Clusternum[i]) {
-			fc_solve_msg("%04X: %6d", i, Clusternum[i]);
+		if (soft_thread->Clusternum[i]) {
+			fc_solve_msg("%04X: %6d", i, soft_thread->Clusternum[i]);
 			c++;
 			if (c % 5 == 0) {
 				c = 0;
 	}
 	print_layout(soft_thread);
 
+#if 0
 	signal(SIGQUIT, quit);
+#endif
 }
 #endif
 
 
 	Progname = *argv;
 #if DEBUG
+#if 0
 	signal(SIGQUIT, quit);
+#endif
     fc_solve_msg("sizeof(POSITION) = %d\n", sizeof(POSITION));
 #endif
 
 	}
 
 #if DEBUG
-Init_mem_remain = Mem_remain;
+Init_mem_remain = soft_thread->Mem_remain;
 #endif
 	if (Sgame < 0) {
 
 #if DEBUG
 		printf("%d positions generated.\n", soft_thread->Total_generated);
 		printf("%d unique positions.\n", soft_thread->Total_positions);
-		printf("Mem_remain = %ld\n", Mem_remain);
+		printf("Mem_remain = %ld\n", soft_thread->Mem_remain);
 #endif
 	}
 	if (!soft_thread->Interactive) {
 		soft_thread->Freepos = NULL;
 	}
 #if DEBUG
-if (Mem_remain != Init_mem_remain) {
- fc_solve_msg("Mem_remain = %ld\n", Mem_remain);
+if (soft_thread->Mem_remain != Init_mem_remain) {
+ fc_solve_msg("Mem_remain = %ld\n", soft_thread->Mem_remain);
 }
 #endif
 }

File patsolve/patsolve.c

 #include <math.h>
 #include "pat.h"
 #include "fnv.h"
+#include "util.h"
 
 static int solve(fc_solve_soft_thread_t *, POSITION *);
 static void free_position(fc_solve_soft_thread_t * soft_thread, POSITION *pos, int);
 
 #if DEBUG
 
-void print_queue(void)
+void print_queue(fc_solve_soft_thread_t * soft_thread)
 {
 	int i, n;
 
-	msg("Maxq %d\n", soft_thread->Maxq);
+	fc_solve_msg("Maxq %d\n", soft_thread->Maxq);
 	n = 0;
 	for (i = 0; i <= soft_thread->Maxq; i++) {
-		if (Inq[i]) {
-			msg("Inq %2d %5d", i, Inq[i]);
+		if (soft_thread->Inq[i]) {
+			fc_solve_msg("Inq %2d %5d", i, soft_thread->Inq[i]);
 			if (n & 1) {
-				msg("\n");
+				fc_solve_msg("\n");
 			} else {
-				msg("\t\t");
+				fc_solve_msg("\t\t");
 			}
 			n++;
 		}
 	}
-	msg("\n");
+	fc_solve_msg("\n");
 }
 #endif
 
 	int i, q;
 	POSITION *pos;
 	MOVE m;
-	extern void hash_layout(void);
 
 	/* Init the queues. */
 
 	}
 	soft_thread->Maxq = 0;
 #if DEBUG
-memset(Clusternum, 0, sizeof(Clusternum));
-memset(Inq, 0, sizeof(Inq));
+memset(soft_thread->Clusternum, 0, sizeof(soft_thread->Clusternum));
+memset(soft_thread->Inq, 0, sizeof(soft_thread->Inq));
 #endif
 
 	/* Queue the initial position to get started. */
 
-	hash_layout();
+	hash_layout(soft_thread);
 	pilesort(soft_thread);
 	m.card = NONE;
 	pos = new_position(soft_thread, NULL, &m);
 		}
 	}
 #if DEBUG
-Inq[pri]++;
-Clusternum[pos->cluster]++;
+soft_thread->Inq[pri]++;
+soft_thread->Clusternum[pos->cluster]++;
 #endif
 }
 
 	pos = soft_thread->Qhead[qpos];
 	soft_thread->Qhead[qpos] = pos->queue;
 #if DEBUG
-	Inq[qpos]--;
+	soft_thread->Inq[qpos]--;
 #endif
 
 	/* Decrease soft_thread->Maxq if that queue emptied. */
 	unpack_position(soft_thread, pos);
 
 #if DEBUG
-Clusternum[pos->cluster]--;
+soft_thread->Clusternum[pos->cluster]--;
 #endif
 	return pos;
 }