Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROTON-2772: add compiler warning management macros #413

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions c/include/proton/annotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,36 @@
#define PN_FALLTHROUGH (void)0
#endif

// Generalize warning push/pop.
#if defined(__GNUC__) || defined(__clang__)
// Clang & GCC
#define PN_PUSH_WARNING _Pragma("GCC diagnostic push")
#define PN_POP_WARNING _Pragma("GCC diagnostic pop")
#define PN_GNU_DISABLE_WARNING_INTERNAL2(warningName) #warningName
#define PN_GNU_DISABLE_WARNING(warningName) _Pragma(PN_GNU_DISABLE_WARNING_INTERNAL2(GCC diagnostic ignored warningName))
#ifdef __clang__
#define PN_CLANG_DISABLE_WARNING(warningName) PN_GNU_DISABLE_WARNING(warningName)
#define PN_GCC_DISABLE_WARNING(warningName)
#else
#define PN_CLANG_DISABLE_WARNING(warningName)
#define PN_GCC_DISABLE_WARNING(warningName) PN_GNU_DISABLE_WARNING(warningName)
#endif
#define PN_MSVC_DISABLE_WARNING(warningNumber)
#elif defined(_MSC_VER)
#define PN_PUSH_WARNING __pragma(warning(push))
#define PN_POP_WARNING __pragma(warning(pop))
// Disable the GCC warnings.
#define PN_GNU_DISABLE_WARNING(warningName)
#define PN_GCC_DISABLE_WARNING(warningName)
#define PN_CLANG_DISABLE_WARNING(warningName)
#define PN_MSVC_DISABLE_WARNING(warningNumber) __pragma(warning(disable : warningNumber))
#else
#define PN_PUSH_WARNING
#define PN_POP_WARNING
#define PN_GNU_DISABLE_WARNING(warningName)
#define PN_GCC_DISABLE_WARNING(warningName)
#define PN_CLANG_DISABLE_WARNING(warningName)
#define PN_MSVC_DISABLE_WARNING(warningNumber)
#endif

#endif /* annotations.h */
4 changes: 4 additions & 0 deletions c/src/sasl/cyrus_sasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "core/logger_private.h"

#include "proton/annotations.h"
#include "proton/sasl.h"
#include "proton/sasl_plugin.h"
#include "proton/transport.h"
Expand Down Expand Up @@ -187,10 +188,13 @@ static int pni_authorize(sasl_conn_t *conn,
return SASL_OK;
}

PN_PUSH_WARNING
PN_GNU_DISABLE_WARNING("-Wcast-function-type")
static const sasl_callback_t pni_server_callbacks[] = {
{SASL_CB_PROXY_POLICY, (int(*)(void)) pni_authorize, NULL},
{SASL_CB_LIST_END, NULL, NULL},
};
PN_POP_WARNING

// Machinery to initialise the cyrus library only once even in a multithreaded environment
// Relies on pthreads.
Expand Down