Skip to content

Commit

Permalink
WIN32: hint noreturn functions
Browse files Browse the repository at this point in the history
apply __declspec(noreturn) compiler hints to functions that
do not return.

Change-Id: I3c6c4703c7235d1df3e21dccad5272ea4cddfd36
  • Loading branch information
jaltman committed Jan 2, 2019
1 parent a010e65 commit 73915cc
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 55 deletions.
79 changes: 56 additions & 23 deletions cf/make-proto.pl
Expand Up @@ -415,34 +415,67 @@ sub foo {
}
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
";
}

Expand Down
6 changes: 6 additions & 0 deletions include/config.h.w32
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/krb5/warn.c
Expand Up @@ -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)))
Expand All @@ -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)))
Expand All @@ -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)))
{
Expand All @@ -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)))
{
Expand All @@ -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)))
Expand All @@ -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)))
{
Expand All @@ -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)))
{
Expand All @@ -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)))
{
Expand Down
29 changes: 19 additions & 10 deletions lib/roken/err.hin
Expand Up @@ -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)));
Expand Down
2 changes: 1 addition & 1 deletion lib/roken/errx.c
Expand Up @@ -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;
Expand Down
51 changes: 39 additions & 12 deletions lib/roken/roken.h.in
Expand Up @@ -52,22 +52,49 @@
#include <util.h>
#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
# endif
# else
# define ROKEN_LIB_FUNCTION
# 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
#else
#define ROKEN_LIB_FUNCTION
#define ROKEN_LIB_CALL
#define ROKEN_LIB_VARIABLE
#endif
#endif
# endif

#ifdef HAVE_WINSOCK
/* Declarations for Microsoft Windows */
Expand Down
2 changes: 1 addition & 1 deletion lib/roken/verrx.c
Expand Up @@ -36,7 +36,7 @@
#include "roken.h"
#include <err.h>

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);
Expand Down

0 comments on commit 73915cc

Please sign in to comment.