Cross-compiler noreturn support.

This commit is contained in:
stag019
2014-12-31 04:11:06 -05:00
parent 9b4959cb75
commit f0e5c5ccc8
4 changed files with 26 additions and 9 deletions

View File

@@ -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

View File

@@ -29,6 +29,7 @@
#else
#include <stdarg.h>
#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
}

16
include/extern/stdnoreturn.h vendored Normal file
View File

@@ -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

8
src/extern/err.c vendored
View File

@@ -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);