From 0aa8ace26652712e3c274cf5e7aeb8d2b7392ea7 Mon Sep 17 00:00:00 2001 From: Justin Hiemstra Date: Thu, 18 May 2023 15:34:33 +0000 Subject: [PATCH 1/2] Add wrapper to throw compiler warning for deprecated funcs In order to keep the `scitokens.h` header backwards compatible with older versions of C/C++ while still providing support for compiler warnings when a deprecated function is used, I set up a macro wrapper that checks for compiler support of the attribute and throws a warning when a deprecated function is used. --- src/scitokens.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/scitokens.h b/src/scitokens.h index b87003a..b04bec3 100644 --- a/src/scitokens.h +++ b/src/scitokens.h @@ -14,6 +14,21 @@ extern "C" { #include #endif +// Set up a wrapper macro to warn compiler of soon-to-be-deprecated functions +#if __cplusplus >= 201402L + #if defined(__has_cpp_attribute) + #if __has_cpp_attribute(deprecated) + #define DEPRECATION_WARNING(msg, func) [[deprecated(msg)]] func + #endif + #endif +#else + #ifdef __GNUC__ + #define DEPRECATION_WARNING(msg, func) func __attribute__ ((deprecated(msg))) + #elif defined(_MSC_VER) + #define DEPRECATION_WARNING(msg, func) __declspec(deprecated(msg)) func + #endif +#endif + typedef void *SciTokenKey; typedef void *SciToken; typedef void *Validator; @@ -294,8 +309,9 @@ int keycache_set_jwks(const char *issuer, const char *jwks, char **err_msg); * APIs for managing scitokens configuration parameters. */ -// On its way to deprecation -int config_set_int(const char *key, int value, char **err_msg); + +// On its way to deprecation. API wrapped in deprecation warning +DEPRECATION_WARNING("Use scitoken_ prefixed version instead", int config_set_int(const char *key, int value, char **err_msg)); /** * Update scitokens int parameters. @@ -305,8 +321,8 @@ int config_set_int(const char *key, int value, char **err_msg); */ int scitoken_config_set_int(const char *key, int value, char **err_msg); -// on its way to deprecation -int config_get_int(const char *key, char **err_msg); +// On its way to deprecation. API wrapped in deprecation warning +DEPRECATION_WARNING("Use scitoken_ prefixed version instead", int config_get_int(const char *key, char **err_msg)); /** * Get current scitokens int parameters. From f9b7677620e38e9c3b0615e3969ddb964bfb8d09 Mon Sep 17 00:00:00 2001 From: jhiemstrawisc <75916364+jhiemstrawisc@users.noreply.github.com> Date: Thu, 18 May 2023 10:47:33 -0500 Subject: [PATCH 2/2] Apply suggestions from linter review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/scitokens.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/scitokens.h b/src/scitokens.h index b04bec3..d88ff5b 100644 --- a/src/scitokens.h +++ b/src/scitokens.h @@ -16,17 +16,17 @@ extern "C" { // Set up a wrapper macro to warn compiler of soon-to-be-deprecated functions #if __cplusplus >= 201402L - #if defined(__has_cpp_attribute) - #if __has_cpp_attribute(deprecated) - #define DEPRECATION_WARNING(msg, func) [[deprecated(msg)]] func - #endif - #endif +#if defined(__has_cpp_attribute) +#if __has_cpp_attribute(deprecated) +#define DEPRECATION_WARNING(msg, func) [[deprecated(msg)]] func +#endif +#endif #else - #ifdef __GNUC__ - #define DEPRECATION_WARNING(msg, func) func __attribute__ ((deprecated(msg))) - #elif defined(_MSC_VER) - #define DEPRECATION_WARNING(msg, func) __declspec(deprecated(msg)) func - #endif +#ifdef __GNUC__ +#define DEPRECATION_WARNING(msg, func) func __attribute__((deprecated(msg))) +#elif defined(_MSC_VER) +#define DEPRECATION_WARNING(msg, func) __declspec(deprecated(msg)) func +#endif #endif typedef void *SciTokenKey; @@ -309,9 +309,10 @@ int keycache_set_jwks(const char *issuer, const char *jwks, char **err_msg); * APIs for managing scitokens configuration parameters. */ - // On its way to deprecation. API wrapped in deprecation warning -DEPRECATION_WARNING("Use scitoken_ prefixed version instead", int config_set_int(const char *key, int value, char **err_msg)); +DEPRECATION_WARNING("Use scitoken_ prefixed version instead", + int config_set_int(const char *key, int value, + char **err_msg)); /** * Update scitokens int parameters. @@ -322,7 +323,8 @@ DEPRECATION_WARNING("Use scitoken_ prefixed version instead", int config_set_int int scitoken_config_set_int(const char *key, int value, char **err_msg); // On its way to deprecation. API wrapped in deprecation warning -DEPRECATION_WARNING("Use scitoken_ prefixed version instead", int config_get_int(const char *key, char **err_msg)); +DEPRECATION_WARNING("Use scitoken_ prefixed version instead", + int config_get_int(const char *key, char **err_msg)); /** * Get current scitokens int parameters.