From: Bart House Date: Fri, 12 Jul 2019 05:01:39 +0000 (-0700) Subject: Added nhassert to core. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3842da9dbde163b6fa66e4bf8b8afe2d52e7c46c;p=nethack Added nhassert to core. --- diff --git a/include/extern.h b/include/extern.h index 83a1cd30f..ca480cf0d 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2020,6 +2020,7 @@ E void VDECL(verbalize, (const char *, ...)) PRINTF_F(1, 2); E void VDECL(raw_printf, (const char *, ...)) PRINTF_F(1, 2); E void VDECL(impossible, (const char *, ...)) PRINTF_F(1, 2); E void VDECL(config_error_add, (const char *, ...)) PRINTF_F(1, 2); +E void FDECL(nhassert_failed, (const char *, const char *, int)); /* ### polyself.c ### */ diff --git a/include/global.h b/include/global.h index caa32847b..23350a12c 100644 --- a/include/global.h +++ b/include/global.h @@ -427,8 +427,8 @@ struct savefile_info { /* Supply nhassert macro if not supplied by port */ #ifndef nhassert -#define nhassert(e) ((void)0) +#define nhassert(expression) (void)((!!(expression)) || \ + (nhassert_failed(#expression, __FILE__, __LINE__), 0)) #endif - #endif /* GLOBAL_H */ diff --git a/include/ntconf.h b/include/ntconf.h index 5a7d0ed78..45a8ce266 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -273,16 +273,6 @@ extern int FDECL(set_win32_option, (const char *, const char *)); extern int FDECL(alternative_palette, (char *)); #endif -#ifdef NDEBUG -#define nhassert(expression) ((void)0) -#else -extern void FDECL(nhassert_failed, (const char * exp, const char * file, - int line)); - -#define nhassert(expression) (void)((!!(expression)) || \ - (nhassert_failed(#expression, __FILE__, __LINE__), 0)) -#endif - #define nethack_enter(argc, argv) nethack_enter_winnt() extern void FDECL(nethack_exit, (int)) NORETURN; extern boolean FDECL(file_exists, (const char *)); diff --git a/src/pline.c b/src/pline.c index cc03ebd44..03c041c03 100644 --- a/src/pline.c +++ b/src/pline.c @@ -619,4 +619,10 @@ VA_DECL(const char *, str) #endif } +/* nhassert_failed is called when an nhassert's condition is false */ +void nhassert_failed(const char * exp, const char * file, int line) +{ + impossible("NHASSERT(%s) in '%s' at line %d", exp, file, line); +} + /*pline.c*/ diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index 8f44163dd..238b78549 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -483,16 +483,6 @@ char *buf; } #endif /* RUNTIME_PORT_ID */ -/* nhassert_failed is called when an nhassert's condition is false */ -void nhassert_failed(const char * exp, const char * file, int line) -{ - char message[BUFSZ]; - snprintf(message, sizeof(message), - "NHASSERT(%s) in '%s' at line %d", exp, file, line); - - impossible(message); -} - void nethack_exit(code) int code;