From bec4818943c8d5cbf8e7db9dfd8db037c8645d80 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 1 Jan 2019 22:20:31 -0500 Subject: [PATCH] WIN32: hint noreturn functions apply __declspec(noreturn) compiler hints to functions that do not return. Change-Id: I3c6c4703c7235d1df3e21dccad5272ea4cddfd36 --- cf/make-proto.pl | 79 +++++++++++++++++++++++++++++++------------- include/config.h.w32 | 6 ++++ lib/krb5/warn.c | 16 ++++----- lib/roken/err.hin | 29 ++++++++++------ lib/roken/errx.c | 2 +- lib/roken/roken.h.in | 53 +++++++++++++++++++++-------- lib/roken/verrx.c | 2 +- 7 files changed, 131 insertions(+), 56 deletions(-) diff --git a/cf/make-proto.pl b/cf/make-proto.pl index 577876c2d..72b3993b8 100644 --- a/cf/make-proto.pl +++ b/cf/make-proto.pl @@ -415,34 +415,67 @@ extern \"C\" { } if ($opt_E) { $public_h_header .= "#ifndef $opt_E -#ifndef ${opt_E}_FUNCTION -#if defined(_WIN32) -#define ${opt_E}_FUNCTION __declspec(dllimport) -#define ${opt_E}_CALL __stdcall -#define ${opt_E}_VARIABLE __declspec(dllimport) -#else -#define ${opt_E}_FUNCTION -#define ${opt_E}_CALL -#define ${opt_E}_VARIABLE -#endif -#endif + #ifndef ${opt_E}_FUNCTION + #if defined(_WIN32) + #define ${opt_E}_FUNCTION __declspec(dllimport) + #else + #define ${opt_E}_FUNCTION + #endif + #endif + #ifndef ${opt_E}_NORETURN_FUNCTION + #if defined(_WIN32) + #define ${opt_E}_NORETURN_FUNCTION __declspec(dllimport noreturn) + #else + #define ${opt_E}_NORETURN_FUNCTION + #endif + #endif + #ifndef ${opt_E}_CALL + #if defined(_WIN32) + #define ${opt_E}_CALL __stdcall + #else + #define ${opt_E}_CALL + #endif + #endif + #ifndef ${opt_E}_VARIABLE + #if defined(_WIN32) + #define ${opt_E}_VARIABLE __declspec(dllimport) + #else + #define ${opt_E}_VARIABLE + #endif + #endif #endif "; $private_h_header .= "#ifndef $opt_E -#ifndef ${opt_E}_FUNCTION -#if defined(_WIN32) -#define ${opt_E}_FUNCTION __declspec(dllimport) -#define ${opt_E}_CALL __stdcall -#define ${opt_E}_VARIABLE __declspec(dllimport) -#else -#define ${opt_E}_FUNCTION -#define ${opt_E}_CALL -#define ${opt_E}_VARIABLE + #ifndef ${opt_E}_FUNCTION + #if defined(_WIN32) + #define ${opt_E}_FUNCTION __declspec(dllimport) + #else + #define ${opt_E}_FUNCTION + #endif + #endif + #ifndef ${opt_E}_NORETURN_FUNCTION + #if defined(_WIN32) + #define ${opt_E}_NORETURN_FUNCTION __declspec(dllimport noreturn) + #else + #define ${opt_E}_NORETURN_FUNCTION + #endif + #endif + #ifndef ${opt_E}_CALL + #if defined(_WIN32) + #define ${opt_E}_CALL __stdcall + #else + #define ${opt_E}_CALL + #endif + #endif + #ifndef ${opt_E}_VARIABLE + #if defined(_WIN32) + #define ${opt_E}_VARIABLE __declspec(dllimport) + #else + #define ${opt_E}_VARIABLE + #endif + #endif #endif -#endif -#endif - "; } diff --git a/include/config.h.w32 b/include/config.h.w32 index b3330f58f..b56b1b4e0 100644 --- a/include/config.h.w32 +++ b/include/config.h.w32 @@ -55,10 +55,12 @@ static const char *const rcsid[] = { (const char *)rcsid, "@(#)" msg } #ifndef KRB5_LIB #ifdef _WIN32 #define KRB5_LIB_FUNCTION +#define KRB5_LIB_NORETURN_FUNCTION __declspec(noreturn) #define KRB5_LIB_CALL __stdcall #define KRB5_LIB_VARIABLE #else #define KRB5_LIB_FUNCTION +#define KRB5_LIB_NORETURN_FUNCTION #define KRB5_LIB_CALL #define KRB5_LIB_VARIABLE #endif @@ -70,10 +72,12 @@ static const char *const rcsid[] = { (const char *)rcsid, "@(#)" msg } #ifndef ROKEN_LIB #ifdef _WIN32 #define ROKEN_LIB_FUNCTION +#define ROKEN_LIB_NORETURN_FUNCTION __declspec(noreturn) #define ROKEN_LIB_CALL __cdecl #define ROKEN_LIB_VARIABLE #else #define ROKEN_LIB_FUNCTION +#define ROKEN_LIB_NORETURN_FUNCTION #define ROKEN_LIB_CALL #define ROKEN_LIB_VARIABLE #endif @@ -85,10 +89,12 @@ static const char *const rcsid[] = { (const char *)rcsid, "@(#)" msg } #ifndef GSSAPI_LIB #ifdef _WIN32 #define GSSAPI_LIB_FUNCTION +#define GSSAPI_LIB_NORETURN_FUNCTION __declspec(noreturn) #define GSSAPI_LIB_CALL __stdcall #define GSSAPI_LIB_VARIABLE #else #define GSSAPI_LIB_FUNCTION +#define GSSAPI_LIB_NORETURN_FUNCTION #define GSSAPI_LIB_CALL #define GSSAPI_LIB_VARIABLE #endif diff --git a/lib/krb5/warn.c b/lib/krb5/warn.c index 8269aff74..9a0d00461 100644 --- a/lib/krb5/warn.c +++ b/lib/krb5/warn.c @@ -181,7 +181,7 @@ krb5_warnx(krb5_context context, const char *fmt, ...) * @ingroup krb5_error */ -KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL krb5_verr(krb5_context context, int eval, krb5_error_code code, const char *fmt, va_list ap) __attribute__ ((__noreturn__, __format__ (__printf__, 4, 0))) @@ -203,7 +203,7 @@ krb5_verr(krb5_context context, int eval, krb5_error_code code, * @ingroup krb5_error */ -KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL krb5_err(krb5_context context, int eval, krb5_error_code code, const char *fmt, ...) __attribute__ ((__noreturn__, __format__ (__printf__, 4, 5))) @@ -224,7 +224,7 @@ krb5_err(krb5_context context, int eval, krb5_error_code code, * @ingroup krb5_error */ -KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL krb5_verrx(krb5_context context, int eval, const char *fmt, va_list ap) __attribute__ ((__noreturn__, __format__ (__printf__, 3, 0))) { @@ -243,7 +243,7 @@ krb5_verrx(krb5_context context, int eval, const char *fmt, va_list ap) * @ingroup krb5_error */ -KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL krb5_errx(krb5_context context, int eval, const char *fmt, ...) __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4))) { @@ -264,7 +264,7 @@ krb5_errx(krb5_context context, int eval, const char *fmt, ...) * @ingroup krb5_error */ -KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL krb5_vabort(krb5_context context, krb5_error_code code, const char *fmt, va_list ap) __attribute__ ((__noreturn__, __format__ (__printf__, 3, 0))) @@ -286,7 +286,7 @@ krb5_vabort(krb5_context context, krb5_error_code code, * @ingroup krb5_error */ -KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL krb5_abort(krb5_context context, krb5_error_code code, const char *fmt, ...) __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4))) { @@ -295,7 +295,7 @@ krb5_abort(krb5_context context, krb5_error_code code, const char *fmt, ...) UNREACHABLE(return 0); } -KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL krb5_vabortx(krb5_context context, const char *fmt, va_list ap) __attribute__ ((__noreturn__, __format__ (__printf__, 2, 0))) { @@ -314,7 +314,7 @@ krb5_vabortx(krb5_context context, const char *fmt, va_list ap) * @ingroup krb5_error */ -KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL krb5_abortx(krb5_context context, const char *fmt, ...) __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3))) { diff --git a/lib/roken/err.hin b/lib/roken/err.hin index c5343c49a..1cb0abe70 100644 --- a/lib/roken/err.hin +++ b/lib/roken/err.hin @@ -47,30 +47,39 @@ #endif #ifndef ROKEN_LIB_FUNCTION -#ifdef _WIN32 -#define ROKEN_LIB_FUNCTION -#define ROKEN_LIB_CALL __cdecl -#else -#define ROKEN_LIB_FUNCTION -#define ROKEN_LIB_CALL + #define ROKEN_LIB_FUNCTION #endif +#ifndef ROKEN_LIB_NORETURN_FUNCTION + #ifdef _WIN32 + #define ROKEN_LIB_NORETURN_FUNCTION _declspec(noreturn) + #else + #define ROKEN_LIB_NORETURN_FUNCTION + #endif +#endif +#ifndef ROKEN_LIB_CALL + #ifdef _WIN32 + #define ROKEN_LIB_CALL __cdecl + #else + #define ROKEN_LIB_CALL + #endif #endif -ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL +ROKEN_LIB_NORETURN_FUNCTION void ROKEN_LIB_CALL verr(int eval, const char *fmt, va_list ap) __attribute__ ((__noreturn__, __format__ (__printf__, 2, 0))); -ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL +ROKEN_LIB_NORETURN_FUNCTION void ROKEN_LIB_CALL err(int eval, const char *fmt, ...) __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3))); -ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL +ROKEN_LIB_NORETURN_FUNCTION void ROKEN_LIB_CALL verrx(int eval, const char *fmt, va_list ap) __attribute__ ((__noreturn__, __format__ (__printf__, 2, 0))); -ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL +ROKEN_LIB_NORETURN_FUNCTION void ROKEN_LIB_CALL errx(int eval, const char *fmt, ...) __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3))); + ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vwarn(const char *fmt, va_list ap) __attribute__ ((__format__ (__printf__, 1, 0))); diff --git a/lib/roken/errx.c b/lib/roken/errx.c index f75ad0179..121c7070d 100644 --- a/lib/roken/errx.c +++ b/lib/roken/errx.c @@ -35,7 +35,7 @@ #include "err.h" -ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL +ROKEN_LIB_NORETURN_FUNCTION void ROKEN_LIB_CALL errx(int eval, const char *fmt, ...) { va_list ap; diff --git a/lib/roken/roken.h.in b/lib/roken/roken.h.in index c8538e389..d37c7a5b2 100644 --- a/lib/roken/roken.h.in +++ b/lib/roken/roken.h.in @@ -52,22 +52,49 @@ #include #endif -#ifndef ROKEN_LIB_FUNCTION -#ifdef _WIN32 -# define ROKEN_LIB_CALL __cdecl -# ifdef ROKEN_LIB_DYNAMIC +# ifndef ROKEN_LIB_FUNCTION +# ifdef _WIN32 +# ifdef ROKEN_LIB_DYNAMIC # define ROKEN_LIB_FUNCTION __declspec(dllimport) -# define ROKEN_LIB_VARIABLE __declspec(dllimport) -# else +# else # define ROKEN_LIB_FUNCTION -# define ROKEN_LIB_VARIABLE +# endif +# else +# define ROKEN_LIB_FUNCTION # endif -#else -#define ROKEN_LIB_FUNCTION -#define ROKEN_LIB_CALL -#define ROKEN_LIB_VARIABLE -#endif -#endif +# endif + +# ifndef ROKEN_LIB_NORETURN_FUNCTION +# ifdef _WIN32 +# ifdef ROKEN_LIB_DYNAMIC +# define ROKEN_LIB_NORETURN_FUNCTION __declspec(dllimport noreturn) +# else +# define ROKEN_LIB_NORETURN_FUNCTION _declspec(noreturn) +# endif +# else +# define ROKEN_LIB_NORETURN_FUNCTION +# endif +# endif + +# ifndef ROKEN_LIB_CALL +# ifdef _WIN32 +# define ROKEN_LIB_CALL __cdecl +# else +# define ROKEN_LIB_CALL +# endif +# endif + +# ifndef ROKEN_LIB_VARIABLE +# ifdef _WIN32 +# ifdef ROKEN_LIB_DYNAMIC +# define ROKEN_LIB_VARIABLE __declspec(dllimport) +# else +# define ROKEN_LIB_VARIABLE +# endif +# else +# define ROKEN_LIB_VARIABLE +# endif +# endif #ifdef HAVE_WINSOCK /* Declarations for Microsoft Windows */ diff --git a/lib/roken/verrx.c b/lib/roken/verrx.c index 84645181c..7b148a45f 100644 --- a/lib/roken/verrx.c +++ b/lib/roken/verrx.c @@ -36,7 +36,7 @@ #include "roken.h" #include -ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL +ROKEN_LIB_NORETURN_FUNCTION void ROKEN_LIB_CALL verrx(int eval, const char *fmt, va_list ap) { rk_warnerr(0, fmt, ap);