From 8a24ad83c91551e1c6eaa05a0f1dac022cf4887a Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sat, 11 Jul 2015 10:03:57 +0100 Subject: [PATCH] Add macros for deprecating macros We want to be able to deprecate macros, but right now the best we can do is to wrap them with things like: #ifndef CLUTTER_DISABLE_DEPRECATED # define A_MACRO_I_WANT_TO_DEPRECATE ... #endif Which requires adding a new symbol to the build, and will cause a build error instead of a compiler/pre-processor warning. Fortunately, we can use the _Pragma() keyword introduced by C99 and supported by GCC to add a warning to the output, while leaving the macro itself intact. GCC does not have a "deprecated" pragma, so we have to use a generic warning; this also means we cannot do nifty things like concatenating strings and the like, as we do for the "deprecated" attribute. The macro deprecation symbol should have the same affordances as the function deprecation one, and evaluate to nothing if the required version is lower than the current version; or if the global toggle for deprecation warnings is in effect. --- clutter/clutter-macros.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clutter/clutter-macros.h b/clutter/clutter-macros.h index e38ec23a1..349269936 100644 --- a/clutter/clutter-macros.h +++ b/clutter/clutter-macros.h @@ -96,6 +96,12 @@ #define _CLUTTER_EXTERN extern #endif +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#define _CLUTTER_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x)) +#define _CLUTTER_DEPRECATED_MACRO _CLUTTER_GNUC_DO_PRAGMA(GCC warning "Deprecated macro") +#define _CLUTTER_DEPRECATED_MACRO_FOR(f) _CLUTTER_GNUC_DO_PRAGMA(GCC warning #f) +#endif + /* these macros are used to mark deprecated functions, and thus have to be * exposed in a public header. * @@ -106,10 +112,14 @@ #define CLUTTER_DEPRECATED _CLUTTER_EXTERN #define CLUTTER_DEPRECATED_FOR(f) _CLUTTER_EXTERN #define CLUTTER_UNAVAILABLE(maj,min) _CLUTTER_EXTERN +#define CLUTTER_DEPRECATED_MACRO +#define CLUTTER_DEPRECATED_MACRO_FOR(f) #else #define CLUTTER_DEPRECATED G_DEPRECATED _CLUTTER_EXTERN #define CLUTTER_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _CLUTTER_EXTERN #define CLUTTER_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _CLUTTER_EXTERN +#define CLUTTER_DEPRECATED_MACRO _CLUTTER_DEPRECATED_MACRO +#define CLUTTER_DEPRECATED_MACRO_FOR(f) _CLUTTER_DEPRECATED_MACRO_FOR(f) #endif #define CLUTTER_AVAILABLE_IN_ALL _CLUTTER_EXTERN @@ -341,9 +351,13 @@ #if CLUTTER_VERSION_MIN_REQUIRED >= CLUTTER_VERSION_1_24 # define CLUTTER_DEPRECATED_IN_1_24 CLUTTER_DEPRECATED # define CLUTTER_DEPRECATED_IN_1_24_FOR(f) CLUTTER_DEPRECATED_FOR(f) +# define CLUTTER_MACRO_DEPRECATED_IN_1_24 CLUTTER_DEPRECATED_MACRO +# define CLUTTER_MACRO_DEPRECATED_IN_1_24_FOR(f) CLUTTER_DEPRECATED_MACRO_FOR(f) #else # define CLUTTER_DEPRECATED_IN_1_24 _CLUTTER_EXTERN # define CLUTTER_DEPRECATED_IN_1_24_FOR(f) _CLUTTER_EXTERN +# define CLUTTER_MACRO_DEPRECATED_IN_1_24 +# define CLUTTER_MACRO_DEPRECATED_IN_1_24_FOR(f) #endif #if CLUTTER_VERSION_MAX_ALLOWED < CLUTTER_VERSION_1_24