From 7f24b27652ee6fa84e38f181cea57f319af0c204 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 28 Jul 2025 13:52:00 +0200 Subject: Make failed assert exit immediately --- src/arch/coordinates_unoptimized.h | 2 -- src/core/cube.h | 11 +++++------ src/core/oriented_cube.h | 3 +-- src/core/transform.h | 2 +- src/solvers/coord/common.h | 2 +- src/solvers/h48/coordinate.h | 5 ++--- src/solvers/h48/gendata_cocsep.h | 5 ++--- src/utils/dbg_log.h | 6 +++--- 8 files changed, 15 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/arch/coordinates_unoptimized.h b/src/arch/coordinates_unoptimized.h index c553b2b..de76018 100644 --- a/src/arch/coordinates_unoptimized.h +++ b/src/arch/coordinates_unoptimized.h @@ -34,8 +34,6 @@ coord_epud(cube_t cube) uint8_t c[8], e[12]; pieces(&cube, c, e); - DBG_ASSERT(isperm(8, e), -1, - "Cannot compute epud coordinate: edges not separated"); for (i = 0; i < 8; i++) e[i] &= PBITS; diff --git a/src/core/cube.h b/src/core/cube.h index 842ec59..cdd3946 100644 --- a/src/core/cube.h +++ b/src/core/cube.h @@ -87,8 +87,7 @@ issolvable(oriented_cube_t cube) { uint8_t i, eo, co, piece, edge[12], corner[8], ep[12], cp[8]; - DBG_ASSERT(isconsistent(cube), false, - "issolvable: cube is inconsistent\n"); + DBG_ASSERT(isconsistent(cube), "issolvable: cube is inconsistent\n"); pieces(&cube.cube, corner, edge); for (i = 0; i < 12; i++) @@ -175,16 +174,16 @@ getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co) uint8_t i, earr[12], carr[8], eoarr[12], coarr[8]; sumzerotodigits(eo, 12, 2, eoarr); - DBG_ASSERT(eoarr[0] != UINT8_ERROR, ZERO_CUBE, "Error making EO"); + DBG_ASSERT(eoarr[0] != UINT8_ERROR, "Error making EO"); indextoperm(ep, 12, earr); - DBG_ASSERT(earr[0] != UINT8_ERROR, ZERO_CUBE, "Error making EP"); + DBG_ASSERT(earr[0] != UINT8_ERROR, "Error making EP"); for (i = 0; i < 12; i++) earr[i] |= eoarr[i] << EOSHIFT; sumzerotodigits(co, 8, 3, coarr); - DBG_ASSERT(coarr[0] != UINT8_ERROR, ZERO_CUBE, "Error making CO"); + DBG_ASSERT(coarr[0] != UINT8_ERROR, "Error making CO"); indextoperm(cp, 8, carr); - DBG_ASSERT(carr[0] != UINT8_ERROR, ZERO_CUBE, "Error making CP"); + DBG_ASSERT(carr[0] != UINT8_ERROR, "Error making CP"); for (i = 0; i < 8; i++) carr[i] |= coarr[i] << COSHIFT; diff --git a/src/core/oriented_cube.h b/src/core/oriented_cube.h index 2c86af0..5449204 100644 --- a/src/core/oriented_cube.h +++ b/src/core/oriented_cube.h @@ -56,8 +56,7 @@ applymoves(oriented_cube_t cube, const char *buf) uint8_t m; oriented_cube_t c, cinv; - DBG_ASSERT(isconsistent(cube), ZERO_ORIENTED_CUBE, - "move error: inconsistent cube\n"); + DBG_ASSERT(isconsistent(cube), "move error: inconsistent cube\n"); c = cube; cinv = SOLVED_ORIENTED_CUBE; diff --git a/src/core/transform.h b/src/core/transform.h index d1d2931..91d4893 100644 --- a/src/core/transform.h +++ b/src/core/transform.h @@ -371,7 +371,7 @@ applytrans(oriented_cube_t cube, const char *buf) { uint8_t t; - DBG_ASSERT(isconsistent(cube), ZERO_ORIENTED_CUBE, + DBG_ASSERT(isconsistent(cube), "transformation error: inconsistent cube\n"); t = readtrans(buf); diff --git a/src/solvers/coord/common.h b/src/solvers/coord/common.h index d000ce9..d38b7d3 100644 --- a/src/solvers/coord/common.h +++ b/src/solvers/coord/common.h @@ -133,7 +133,7 @@ coord_gendata_generic( writetableinfo(&info, coord_datasize, data); - DBG_ASSERT(n == coord->sym.classes, SIZE_MAX, + DBG_ASSERT(n == coord->sym.classes, "%s coordinate data: computed %" PRIu64 " classes, " "expected %" PRIu64 "\n", coord->name, n, coord->sym.classes); diff --git a/src/solvers/h48/coordinate.h b/src/solvers/h48/coordinate.h index eb08fd8..9437fa7 100644 --- a/src/solvers/h48/coordinate.h +++ b/src/solvers/h48/coordinate.h @@ -15,7 +15,7 @@ coord_h48( uint32_t data; uint8_t ttrep; - DBG_ASSERT(h <= 11, -1, "coord_h48: h must be between 0 and 11\n"); + DBG_ASSERT(h <= 11, "coord_h48: h must be between 0 and 11\n"); cocsep = coord_cocsep(c); data = cocsepdata[cocsep]; @@ -54,8 +54,7 @@ invcoord_h48( cube_t ret; int64_t hh, coclass, ee, esep, eo; - DBG_ASSERT(h <= 11, ZERO_CUBE, - "invcoord_h48: h must be between 0 and 11\n"); + DBG_ASSERT(h <= 11, "invcoord_h48: h must be between 0 and 11\n"); hh = (int64_t)h; coclass = i / H48_ESIZE(h); diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h index 3117a8e..7a589b5 100644 --- a/src/solvers/h48/gendata_cocsep.h +++ b/src/solvers/h48/gendata_cocsep.h @@ -61,9 +61,8 @@ gendata_cocsep( writetableinfo(&info, COCSEP_FULLSIZE, buf); - DBG_ASSERT(n == COCSEP_CLASSES, 0, - "cocsep: computed %" PRIu16 " symmetry classes, " - "expected %zu\n", n, COCSEP_CLASSES); + DBG_ASSERT(n == COCSEP_CLASSES, "cocsep: computed %" PRIu16 + " symmetry classes, expected %zu\n", n, COCSEP_CLASSES); LOG("[H48 gendata] cocsep data computed\n"); diff --git a/src/utils/dbg_log.h b/src/utils/dbg_log.h index e5b3e24..d737ff2 100644 --- a/src/utils/dbg_log.h +++ b/src/utils/dbg_log.h @@ -24,11 +24,11 @@ write_wrapper(void (*write)(const char *, void *), const char *str, ...) #define STATIC #define STATIC_INLINE #define DBG_WARN(condition, ...) if (!(condition)) LOG(__VA_ARGS__); -#define DBG_ASSERT(condition, retval, ...) \ - if (!(condition)) { LOG(__VA_ARGS__); return retval; } +#define DBG_ASSERT(condition, ...) \ + if (!(condition)) { LOG(__VA_ARGS__); exit(1); } #else #define STATIC static #define STATIC_INLINE static inline #define DBG_WARN(condition, ...) -#define DBG_ASSERT(condition, retval, ...) +#define DBG_ASSERT(condition, ...) #endif -- cgit v1.3