From: Arran Cudbard-Bell Date: Mon, 25 Jan 2021 17:16:16 +0000 (+0000) Subject: Rework DIAG_ON and DIAG_OFF macros to behave consistently. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53fbd477c67eaa44835c9ce9343525efd1cee961;p=thirdparty%2Ffreeradius-server.git Rework DIAG_ON and DIAG_OFF macros to behave consistently. Add DIAG_OFF_OPTIONAL and DIAG_ON_OPTIONAL which ignore unknown pragmas --- diff --git a/src/include/build.h b/src/include/build.h index 291efe3b39..1f136d0788 100644 --- a/src/include/build.h +++ b/src/include/build.h @@ -168,31 +168,41 @@ extern "C" { /* * Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8 */ -#if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402 -# define DIAG_PRAGMA(_x) PRAGMA(GCC diagnostic _x) -# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406 -# define DIAG_OFF(_x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored JOINSTR(-W,_x)) -# define DIAG_ON(_x) DIAG_PRAGMA(pop) -# else -# define DIAG_OFF(_x) DIAG_PRAGMA(ignored JOINSTR(-W,_x)) -# define DIAG_ON(_x) DIAG_PRAGMA(warning JOINSTR(-W,_x)) -# endif -#elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__ >= 208) +#if defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__ >= 208) # define DIAG_PRAGMA(_x) PRAGMA(clang diagnostic _x) -# define DIAG_OFF(_x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored JOINSTR(-W,_x)) -# define DIAG_ON(_x) DIAG_PRAGMA(pop) +# define DIAG_OFF(_x) DIAG_PRAGMA(ignored JOINSTR(-W,_x)) +# define DIAG_ON(_x) DIAG_PRAGMA(warning JOINSTR(-W,_x)) +# define DIAG_OFF_OPTIONAL(_x) \ + DIAG_OFF(ignored unknown-pragmas) \ + DIAG_OFF(_x) \ + DIAG_ON(warning unknown-pragmas) +# define DIAG_ON_OPTIONAL(_x) \ + DIAG_OFF(unknown-pragmas) \ + DIAG_ON(_x) \ + DIAG_ON(unknown-pragmas) +# define DIAG_PUSH() DIAG_PRAGMA(push) +# define DIAG_POP() DIAG_PRAGMA(pop) +#elif !defined(__clang__) && defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402 +# define DIAG_PRAGMA(_x) PRAGMA(GCC diagnostic _x) +# define DIAG_OFF(_x) DIAG_PRAGMA(ignored JOINSTR(-W,_x)) +# define DIAG_ON(_x) DIAG_PRAGMA(warning JOINSTR(-W,_x)) +# define DIAG_OFF_OPTIONAL(_x) \ + DIAG_OFF(pragmas) \ + DIAG_OFF(_x) \ + DIAG_ON(pragmas) +# define DIAG_ON_OPTIONAL(_x) \ + DIAG_OFF(pragmas) + DIAG_ON(_x) \ + DIAG_ON(pragmas) +# define DIAG_PUSH() DIAG_PRAGMA(push) +# define DIAG_POP() DIAG_PRAGMA(pop) #else # define DIAG_OFF(_x) # define DIAG_ON(_x) -#endif - -/* - * GCC and clang use different macros - */ -#ifdef __clang__ -# define DIAG_OPTIONAL DIAG_OFF(unknown-pragmas) -#else -# define DIAG_OPTIONAL DIAG_OFF(pragmas) +# define DIAG_OFF_OPTIONAL(_x) +# define DIAG_ON_OPTIONAL(_x) +# define DIAG_PUSH() +# define DIAG_POP() #endif /* diff --git a/src/lib/curl/base.h b/src/lib/curl/base.h index b6be40b6c1..1b71c6fa8d 100644 --- a/src/lib/curl/base.h +++ b/src/lib/curl/base.h @@ -36,8 +36,7 @@ extern "C" { #include #include -DIAG_OPTIONAL -DIAG_OFF(disabled-macro-expansion) +DIAG_OFF_OPTIONAL(disabled-macro-expansion) #define FR_CURL_SET_OPTION(_x, _y)\ do {\ int _ret;\ @@ -72,7 +71,7 @@ do {\ } while (0) /* - *␉·····We have to use this as curl uses lots of enums + * We have to use this as curl uses lots of enums */ #ifndef CURL_AT_LEAST_VERSION # define CURL_VERSION_BITS(x, y, z) ((x) << 16 | (y) << 8 | (z)) diff --git a/src/lib/curl/io.c b/src/lib/curl/io.c index 17bad21711..14ab4da80f 100644 --- a/src/lib/curl/io.c +++ b/src/lib/curl/io.c @@ -32,8 +32,7 @@ * * #define curl_easy_setopt(handle,opt,param) curl_easy_setopt(handle,opt,param) */ -DIAG_OPTIONAL -DIAG_OFF(disabled-macro-expansion) +DIAG_OFF_OPTIONAL(disabled-macro-expansion) #define SET_MOPTION(_mandle, _opt, _val)\ do {\ if ((ret = curl_multi_setopt(mandle, _opt, _val)) != CURLM_OK) {\ diff --git a/src/lib/json/base.h b/src/lib/json/base.h index a8dadeba3e..75a5906820 100644 --- a/src/lib/json/base.h +++ b/src/lib/json/base.h @@ -34,14 +34,9 @@ RCSIDH(json_h, "$Id$") #ifdef HAVE_JSON # if defined(HAVE_JSONMC_JSON_H) -#ifdef __clang__ -DIAG_OFF(documentation-deprecated-sync) -#endif +DIAG_OFF_OPTIONAL(documentation-deprecated-sync) # include - -#ifdef __clang__ -DIAG_ON(documentation-deprecated-sync) -#endif +DIAG_ON_OPTIONAL(documentation-deprecated-sync) # elif defined(HAVE_JSON_JSON_H) # include diff --git a/src/lib/json/json_missing.h b/src/lib/json/json_missing.h index 161d0693fb..ae614b0bbd 100644 --- a/src/lib/json/json_missing.h +++ b/src/lib/json/json_missing.h @@ -29,13 +29,9 @@ RCSIDH(jsonc_missing_h, "$Id$") #ifdef HAVE_JSON # if defined(HAVE_JSONMC_JSON_H) -#ifdef __clang__ -DIAG_OFF(documentation-deprecated-sync) -#endif +DIAG_OFF_OPTIONAL(documentation-deprecated-sync) # include -#ifdef __clang__ -DIAG_ON(documentation-deprecated-sync) -#endif +DIAG_ON_OPTIONAL(documentation-deprecated-sync) # elif defined(HAVE_JSON_JSON_H) # include diff --git a/src/lib/util/dbuff_tests.c b/src/lib/util/dbuff_tests.c index 70fe95a5bc..cb8c730c3a 100644 --- a/src/lib/util/dbuff_tests.c +++ b/src/lib/util/dbuff_tests.c @@ -13,8 +13,6 @@ * the floats are equal on a *bit* level, not on a *semantic* * level. */ -DIAG_OFF(float-equal) - #define TEST_CHECK_LEN(_got, _exp) \ do { \ size_t _our_got = (_got); \ diff --git a/src/lib/util/event.c b/src/lib/util/event.c index 3741f16753..1a6535226a 100644 --- a/src/lib/util/event.c +++ b/src/lib/util/event.c @@ -50,8 +50,7 @@ RCSID("$Id$") * Turn off documentation warnings as file/line * args aren't used for non-debug builds. */ -DIAG_OPTIONAL -DIAG_OFF(documentation) +DIAG_OFF_OPTIONAL(documentation) #endif #define FR_EV_BATCH_FDS (256) diff --git a/src/modules/rlm_mruby/rlm_mruby.c b/src/modules/rlm_mruby/rlm_mruby.c index b0a33aae4e..991b3c68ae 100644 --- a/src/modules/rlm_mruby/rlm_mruby.c +++ b/src/modules/rlm_mruby/rlm_mruby.c @@ -413,13 +413,9 @@ static unlang_action_t CC_HINT(nonnull) do_mruby(rlm_rcode_t *p_result, request_ mruby_set_vps(request, mrb, mruby_request, "@control", &request->control_pairs); mruby_set_vps(request, mrb, mruby_request, "@session_state", &request->session_state_pairs); -#ifdef __clang__ -DIAG_OFF(class-varargs) -#endif +DIAG_OFF_OPTIONAL(class-varargs) mruby_result = mrb_funcall(mrb, mrb_obj_value(inst->mruby_module), function_name, 1, mruby_request); -#ifdef __clang__ -DIAG_ON(class-varargs) -#endif +DIAG_ON_OPTIONAL(class-varargs) /* Two options for the return value: * - a fixnum: convert to rlm_rcode_t, and return that diff --git a/src/modules/rlm_mruby/rlm_mruby.h b/src/modules/rlm_mruby/rlm_mruby.h index bb88612f19..0c067dcf17 100644 --- a/src/modules/rlm_mruby/rlm_mruby.h +++ b/src/modules/rlm_mruby/rlm_mruby.h @@ -23,9 +23,7 @@ * @copyright 2016 The FreeRADIUS server project */ -#ifdef HAVE_WDOCUMENTATION -DIAG_OFF(documentation) -#endif +DIAG_OFF_OPTIONAL(documentation) #include #include #include @@ -33,8 +31,6 @@ DIAG_OFF(documentation) #include #include #include -#ifdef HAVE_WDOCUMENTATION -DIAG_ON(documentation) -#endif +DIAG_ON_OPTIONAL(documentation) struct RClass *mruby_request_class(mrb_state *mrb, struct RClass *parent); diff --git a/src/modules/rlm_perl/rlm_perl.c b/src/modules/rlm_perl/rlm_perl.c index 40797d0309..8cabde4fbf 100644 --- a/src/modules/rlm_perl/rlm_perl.c +++ b/src/modules/rlm_perl/rlm_perl.c @@ -197,7 +197,7 @@ static void rlm_perl_close_handles(void **handles) talloc_free(handles); } -DIAG_OFF(shadow) +DIAG_OFF_OPTIONAL(shadow) static void rlm_perl_destruct(PerlInterpreter *perl) { dTHXa(perl); @@ -223,7 +223,7 @@ static void rlm_perl_destruct(PerlInterpreter *perl) perl_destruct(perl); perl_free(perl); } -DIAG_ON(shadow) +DIAG_ON_OPTIONAL(shadow) static void rlm_destroy_perl(PerlInterpreter *perl) { diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index 6d5c43c809..749e423db3 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -96,9 +96,6 @@ const http_body_type_t http_body_type_supported[REST_HTTP_BODY_NUM_ENTRIES] = { * * #define curl_easy_setopt(handle,opt,param) curl_easy_setopt(handle,opt,param) */ -DIAG_OPTIONAL -DIAG_OFF(disabled-macro-expansion) - const unsigned long http_curl_auth[REST_HTTP_AUTH_NUM_ENTRIES] = { [REST_HTTP_AUTH_UNKNOWN] = 0, [REST_HTTP_AUTH_NONE] = 0, diff --git a/src/modules/rlm_unbound/io.h b/src/modules/rlm_unbound/io.h index 9469b4cdb0..bbfb49ac3b 100644 --- a/src/modules/rlm_unbound/io.h +++ b/src/modules/rlm_unbound/io.h @@ -30,14 +30,10 @@ RCSIDH(rlm_unbound_io_h, "$Id$") extern "C" { #endif -#ifdef HAVE_WDOCUMENTATION -DIAG_OFF(documentation) -#endif +DIAG_OFF_OPTIONAL(documentation) #include #include -#ifdef HAVE_WDOCUMENTATION -DIAG_ON(documentation) -#endif +DIAG_ON_OPTIONAL(documentation) /** Wrapper around our event loop specifying callbacks for creating new event handles * diff --git a/src/modules/rlm_unbound/log.h b/src/modules/rlm_unbound/log.h index 32131f46f3..0643d1fcea 100644 --- a/src/modules/rlm_unbound/log.h +++ b/src/modules/rlm_unbound/log.h @@ -32,19 +32,15 @@ extern "C" { #include -#ifdef HAVE_WDOCUMENTATION -DIAG_OFF(documentation) -#endif +DIAG_OFF_OPTIONAL(documentation) #include -#ifdef HAVE_WDOCUMENTATION -DIAG_ON(documentation) -#endif +DIAG_ON_OPTIONAL(documentation) /** Logging state * */ typedef struct { - request_t *request; //!< Request we're logging to. + request_t *request; //!< Request we're logging to. FILE *stream; //!< Stream we use to interface with the ///< FreeRADIUS logging functions. } unbound_log_t;