From f0e5c5ccc8c56a2e35ad9736fe293b8c73f87015 Mon Sep 17 00:00:00 2001 From: stag019 Date: Wed, 31 Dec 2014 04:11:06 -0500 Subject: [PATCH] Cross-compiler noreturn support. --- Makefile | 2 +- include/extern/err.h | 9 +++++---- include/extern/stdnoreturn.h | 16 ++++++++++++++++ src/extern/err.c | 8 ++++---- 4 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 include/extern/stdnoreturn.h diff --git a/Makefile b/Makefile index ed45f81c..dec00ce9 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,7 @@ mingw: $Qenv PATH=/usr/local/mingw32/bin:/bin:/usr/bin:/usr/local/bin \ make CC=gcc CFLAGS="-I/usr/local/mingw32/include \ -D__progname=\\\"\\\" \ - -D_Noreturn='__attribute__((noreturn))' ${CFLAGS}" + ${CFLAGS}" $Qmv rgbasm rgbasm.exe $Qmv rgblink rgblink.exe $Qmv rgbfix rgbfix.exe diff --git a/include/extern/err.h b/include/extern/err.h index f68fa29f..3a4b721c 100644 --- a/include/extern/err.h +++ b/include/extern/err.h @@ -29,6 +29,7 @@ #else #include +#include "extern/stdnoreturn.h" #define warn rgbds_warn #define vwarn rgbds_vwarn @@ -49,10 +50,10 @@ void vwarn(const char *, va_list); void warnx(const char *, ...); void vwarnx(const char *, va_list); -_Noreturn void err(int, const char *, ...); -_Noreturn void verr(int, const char *, va_list); -_Noreturn void errx(int, const char *, ...); -_Noreturn void verrx(int, const char *, va_list); +noreturn void err(int, const char *, ...); +noreturn void verr(int, const char *, va_list); +noreturn void errx(int, const char *, ...); +noreturn void verrx(int, const char *, va_list); #ifdef __cplusplus } diff --git a/include/extern/stdnoreturn.h b/include/extern/stdnoreturn.h new file mode 100644 index 00000000..250c7a8b --- /dev/null +++ b/include/extern/stdnoreturn.h @@ -0,0 +1,16 @@ +#if _MSC_VER >= 1310 + // MS Visual Studio 2003/.NET Framework 1.1 or newer + #define noreturn _declspec( noreturn) +#elif __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ >= 5)) + // GCC 2.5 or newer + #define noreturn __attribute__ ((noreturn)) +#elif __cplusplus >= 201103L + // C++11 or newer + #define noreturn [[noreturn]] +#elif __STDC_VERSION__ >= 201112L + // C11 or newer + #define noreturn _Noreturn +#else + // unsupported, but no need to throw a fit + #define noreturn +#endif diff --git a/src/extern/err.c b/src/extern/err.c index 1b272849..2328c7ba 100644 --- a/src/extern/err.c +++ b/src/extern/err.c @@ -47,13 +47,13 @@ void rgbds_vwarnx(const char *fmt, va_list ap) putc('\n', stderr); } -_Noreturn void rgbds_verr(int status, const char *fmt, va_list ap) +noreturn void rgbds_verr(int status, const char *fmt, va_list ap) { vwarn(fmt, ap); exit(status); } -_Noreturn void rgbds_verrx(int status, const char *fmt, va_list ap) +noreturn void rgbds_verrx(int status, const char *fmt, va_list ap) { vwarnx(fmt, ap); exit(status); @@ -75,7 +75,7 @@ void rgbds_warnx(const char *fmt, ...) va_end(ap); } -_Noreturn void rgbds_err(int status, const char *fmt, ...) +noreturn void rgbds_err(int status, const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -83,7 +83,7 @@ _Noreturn void rgbds_err(int status, const char *fmt, ...) va_end(ap); } -_Noreturn void rgbds_errx(int status, const char *fmt, ...) +noreturn void rgbds_errx(int status, const char *fmt, ...) { va_list ap; va_start(ap, fmt);