]> granicus.if.org Git - nethack/commitdiff
Tweaks to nhassert implementation. Change to warnings on MSC build.
authorBart House <bart@barthouse.com>
Sat, 13 Jul 2019 01:40:34 +0000 (18:40 -0700)
committerBart House <bart@barthouse.com>
Mon, 19 Oct 2020 22:55:32 +0000 (15:55 -0700)
include/extern.h
include/global.h
include/ntconf.h
src/pline.c
sys/winnt/winnt.c

index ca480cf0d51364035f052b311a29aecd1eda8b64..18f81ea4809b61b7a25c0b78ca42d0d4922d4997 100644 (file)
@@ -2020,7 +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));
+E void FDECL(nhassert_failed, (const char *, int));
 
 /* ### polyself.c ### */
 
index 23350a12c3d3c3fdf83586b96a899be9696fe24c..cfd81ddbf965878dd25a34cac66cc49bdd9bb925 100644 (file)
@@ -428,7 +428,7 @@ struct savefile_info {
 /* Supply nhassert macro if not supplied by port */
 #ifndef nhassert
 #define nhassert(expression) (void)((!!(expression)) || \
-        (nhassert_failed(#expression, __FILE__, __LINE__), 0))
+        (nhassert_failed(__FILE__, __LINE__), 0))
 #endif
 
 #endif /* GLOBAL_H */
index 45a8ce266d039fd8f2a32f51be5b60eedf65463b..711c839149ca7a00421141d69b08711a4af1c3db 100644 (file)
@@ -144,6 +144,8 @@ extern void FDECL(interject, (int));
 #ifndef HAS_STDINT_H
 #define HAS_STDINT_H    /* force include of stdint.h in integer.h */
 #endif
+/* Turn on some additional warnings */
+#pragma warning(3:4389)
 #endif /* _MSC_VER */
 
 /* The following is needed for prototypes of certain functions */
@@ -281,4 +283,13 @@ extern boolean FDECL(file_newer, (const char *, const char *));
 #include "system.h"
 #endif
 
+/* Override the default version of nhassert.  The default version is unable
+ * to generate a string form of the expression due to the need to be
+ * compatible with compilers which do not support macro stringization (i.e.
+ * #x to turn x into its string form).
+ */
+extern void FDECL(nt_assert_failed, (const char *, const char *, int));
+#define nhassert(expression) (void)((!!(expression)) || \
+        (nt_assert_failed(#expression, __FILE__, __LINE__), 0))
+
 #endif /* NTCONF_H */
index 03c041c0391129f9cd9c767ea5c9f1463d67a76f..0c69a13e4b1c8d3c593df048d238f67ffc057edf 100644 (file)
@@ -620,9 +620,20 @@ VA_DECL(const char *, str)
 }
 
 /* nhassert_failed is called when an nhassert's condition is false */
-void nhassert_failed(const char * exp, const char * file, int line)
+void
+nhassert_failed(filepath, line)
+    const char * filepath;
+    int line;
 {
-    impossible("NHASSERT(%s) in '%s' at line %d", exp, file, line);
+    const char * filename;
+
+    /* attempt to get filename from path.  TODO: we really need a port provided
+     * function to return a filename from a path */
+    filename = strrchr(filepath, '/');
+    filename = (filename == NULL ? strrchr(filepath, '\\') : filename);
+    filename = (filename == NULL ? filepath : filename + 1);
+
+    impossible("nhassert failed in file '%s' at line %d", filename, line);
 }
 
 /*pline.c*/
index 238b78549716c123c4f491d5aad3e96ef695837b..09ee0c9b48c7805a761e9e4389628b4d0625d1e2 100644 (file)
@@ -717,6 +717,22 @@ sys_random_seed(VOID_ARGS)
     return ourseed;
 }
 
+/* nt_assert_failed is called when an nhassert's condition is false */
+void
+nt_assert_failed(expression, filepath, line)
+    const char * expression;
+    const char * filepath;
+    int line;
+{
+    const char * filename;
+
+    /* get file name from path */
+    filename = strrchr(filepath, '\\');
+    filename = (filename == NULL ? filepath : filename + 1);
+    impossible("nhassert(%s) failed in file '%s' at line %d",
+                expression, filename, line);
+}
+
 #endif /* WIN32 */
 
 /*winnt.c*/