[Spice-devel] [protocol] macros: Mark unused SPICE_GNUC_XXX macros as deprecated

Christophe Fergeau cfergeau at redhat.com
Wed Dec 14 16:58:13 UTC 2016


On Tue, Dec 13, 2016 at 06:50:02AM +0100, Francois Gouget wrote:
> We don't want to maintain more macros than necessary and in the end
> the equivalent G_GNUC_XXX macros should be preferred.
> Should any project actually depend on these macros they can keep using 
> them by defining the usual SPICE_DEPRECATED macro until they migrate 
> away from them or the macros are reinstated.
> 
> Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
> ---
> 
> Is this what you had in mind?
> 

Yup, this looks like it. Can be made more readable with a macro I think, see below.
However __attribute__(warning()) is not bullet-proof, it fails when gcc decides
not to emit code for the function (I've failed to get a warning with __pure__ or __const__)

diff --git a/spice/macros.h b/spice/macros.h
index 1f8a5c8..a13f364 100644
--- a/spice/macros.h
+++ b/spice/macros.h
@@ -33,8 +33,14 @@
 
 #include <spice/types.h>
 
+#ifndef SPICE_DEPRECATED
+#define SPICE_ATTRIBUTE_DEPRECATED(attribute) __attribute__((attribute, warning("deprecated, use -DSPICE_DEPRECATED or G_GNUC_CONST instead")))
+#else
+#define SPICE_ATTRIBUTE_DEPRECATED(attribute) __attribute__((attribute))
+#endif
+
 #if    __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
-#define SPICE_GNUC_PURE __attribute__((__pure__))
+#define SPICE_GNUC_PURE SPICE_ATTRIBUTE_DEPRECATED(__pure__)
 #define SPICE_GNUC_MALLOC __attribute__((__malloc__))
 #else
 #define SPICE_GNUC_PURE
@@ -42,7 +48,7 @@
 #endif
 
 #if     __GNUC__ >= 4
-#define SPICE_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
+#define SPICE_GNUC_NULL_TERMINATED SPICE_ATTRIBUTE_DEPRECATED(__sentinel__)
 #else
 #define SPICE_GNUC_NULL_TERMINATED
 #endif
@@ -62,12 +68,12 @@
 
 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
 #define SPICE_GNUC_PRINTF( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
-#define SPICE_GNUC_SCANF( format_idx, arg_idx ) __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
-#define SPICE_GNUC_FORMAT( arg_idx ) __attribute__((__format_arg__ (arg_idx)))
+#define SPICE_GNUC_SCANF( format_idx, arg_idx ) SPICE_ATTRIBUTE_DEPRECATED(__format__ (__scanf__, format_idx, arg_idx))
+#define SPICE_GNUC_FORMAT( arg_idx ) SPICE_ATTRIBUTE_DEPRECATED(__format_arg__ (arg_idx))
 #define SPICE_GNUC_NORETURN __attribute__((__noreturn__))
-#define SPICE_GNUC_CONST __attribute__((__const__))
+#define SPICE_GNUC_CONST SPICE_ATTRIBUTE_DEPRECATED(__const__)
 #define SPICE_GNUC_UNUSED __attribute__((__unused__))
-#define SPICE_GNUC_NO_INSTRUMENT __attribute__((__no_instrument_function__))
+#define SPICE_GNUC_NO_INSTRUMENT SPICE_ATTRIBUTE_DEPRECATED(__no_instrument_function__)
 #else   /* !__GNUC__ */
 #define SPICE_GNUC_PRINTF( format_idx, arg_idx )
 #define SPICE_GNUC_SCANF( format_idx, arg_idx )

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20161214/dc4871ad/attachment.sig>


More information about the Spice-devel mailing list