Commit-ID: f0d92fd19ad01b99a93a766f482d2ecaa3ca91a8
Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=f0d92fd19ad01b99a93a766f482d2ecaa3ca91a8
Author: H. Peter Anvin <hp...@li...>
AuthorDate: Tue, 2 Feb 2016 16:01:43 -0800
Committer: H. Peter Anvin <hp...@li...>
CommitDate: Tue, 2 Feb 2016 16:01:43 -0800
nasmlib: Add generic panic() macro, and no-return nasm_panic()
Add a generic panic() macro which we can simply insert where an
internal error happens. Also, create a nasm_panic() function
the only purpose of which is to let the compiler know that we will
never return after a panic.
Signed-off-by: H. Peter Anvin <hp...@li...>
---
compiler.h | 9 +++++++++
nasmlib.c | 11 ++++++++++-
nasmlib.h | 10 ++++------
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/compiler.h b/compiler.h
index de7c0e4..e9022f8 100644
--- a/compiler.h
+++ b/compiler.h
@@ -188,4 +188,13 @@ char *strsep(char **, const char *);
# define no_return void
#endif
+/*
+ * How to tell the compiler that a function takes a printf-like string
+ */
+#ifdef __GNUC__
+# define printf_func(fmt, list) __attribute__((format(printf, fmt, list)))
+#else
+# define printf_func(fmt, list)
+#endif
+
#endif /* NASM_COMPILER_H */
diff --git a/nasmlib.c b/nasmlib.c
index ecd6d8d..3c26546 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 1996-2014 The NASM Authors - All Rights Reserved
+ * Copyright 1996-2016 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@@ -83,6 +83,15 @@ void nasm_error(int severity, const char *fmt, ...)
va_end(ap);
}
+no_return nasm_panic(int flags, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ nasm_verror(flags | ERR_PANIC, fmt, ap);
+ abort(); /* We should never get here */
+}
+
void *nasm_malloc(size_t size)
{
void *p = malloc(size);
diff --git a/nasmlib.h b/nasmlib.h
index 9cd417f..52eadd8 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ * Copyright 1996-2016 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@@ -75,12 +75,10 @@ extern unsigned char nasm_tolower_tab[256];
*/
typedef void (*efunc) (int severity, const char *fmt, ...);
typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
-#ifdef __GNUC__
-void nasm_error(int severity, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
-#else
-void nasm_error(int severity, const char *fmt, ...);
-#endif
+void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
void nasm_set_verror(vefunc);
+no_return printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...);
+#define panic() nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", __FILE__, __LINE__);
/*
* These are the error severity codes which get passed as the first
|