[Spice-devel,protocol] macros: Use GLib's G_DEPRECATED macro if available

Submitted by Francois Gouget on Oct. 28, 2016, 9:27 a.m.

Details

Message ID E1c03RG-0006U3-Th@amboise
State New
Headers show
Series "macros: Use GLib's G_DEPRECATED macro if available" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Francois Gouget Oct. 28, 2016, 9:27 a.m.
This gains us automatic support for whichever compilers GLib supports in
this macro when used in projects that use GLib.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
---

This can make sense if we consider GLib to be a platform similar to gcc, 
MSVC: it just provides a G_XXX API instead of an __attribute((xxx)) or 
__declspec(xxx) one.

Also note that the same thing could be done with a number of other 
macros like SPICE_GNUC_WARN_UNUSED_RESULT, SPICE_GNUC_MAY_ALIAS, 
SPICE_GNUC_CONST, etc. Let me know if I should submit one patch for 
each, one for all or something else...

 spice/macros.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/spice/macros.h b/spice/macros.h
index a0413f3..42916b9 100644
--- a/spice/macros.h
+++ b/spice/macros.h
@@ -78,7 +78,9 @@ 
 #define SPICE_GNUC_NO_INSTRUMENT
 #endif  /* !__GNUC__ */
 
-#if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+#ifdef G_DEPRECATED
+#define SPICE_GNUC_DEPRECATED  G_DEPRECATED
+#elif  __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
 #define SPICE_GNUC_DEPRECATED  __attribute__((__deprecated__))
 #else
 #define SPICE_GNUC_DEPRECATED

Comments

Hey,

On Fri, Oct 28, 2016 at 11:27:02AM +0200, Francois Gouget wrote:
> This gains us automatic support for whichever compilers GLib supports in
> this macro when used in projects that use GLib.
> 
> Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
> ---
> 
> This can make sense if we consider GLib to be a platform similar to gcc, 
> MSVC: it just provides a G_XXX API instead of an __attribute((xxx)) or 
> __declspec(xxx) one.
> 
> Also note that the same thing could be done with a number of other 
> macros like SPICE_GNUC_WARN_UNUSED_RESULT, SPICE_GNUC_MAY_ALIAS, 
> SPICE_GNUC_CONST, etc. Let me know if I should submit one patch for 
> each, one for all or something else...

I believe all of these were more or less directly imported from glib.
Grepping around, I could only find SPICE_GNUC_VISIBLE, SPICE_GNUC_NORETURN,
SPICE_GNUC_UNUSED, SPICE_GNUC_PRINTF and SPICE_GNUC_DEPRECATED being
used. At this point, I'd just make sure the other ones emit a (compile
time) warning when they are used unless some magic define is set, and
drop them after a while.

Christophe
On Fri, Oct 28, 2016 at 11:27:02AM +0200, Francois Gouget wrote:
> This gains us automatic support for whichever compilers GLib supports in
> this macro when used in projects that use GLib.
> 
> Signed-off-by: Francois Gouget <fgouget@codeweavers.com>

Looks good to me, though the #endif /* __GNUC__ */ needs to be changed
too, I've done that locally so no need to resend.

Christophe
On Wed, 9 Nov 2016, Christophe Fergeau wrote:
[...]
> I believe all of these were more or less directly imported from glib.
> Grepping around, I could only find SPICE_GNUC_VISIBLE, SPICE_GNUC_NORETURN,
> SPICE_GNUC_UNUSED, SPICE_GNUC_PRINTF and SPICE_GNUC_DEPRECATED being
> used. At this point, I'd just make sure the other ones emit a (compile
> time) warning when they are used unless some magic define is set, and
> drop them after a while.

I'm not sure how to do that:
 * If I'm not mistaken a #warning directive must be used alone on a 
   line but this is not how __attribute__ is used. Furthermore I doubt 
   #warning would even work if put inside a macro and putting it inside 
   the #ifdef would warn about the macro being defined, not about it 
   being used.

 * I could define the macro to something like 'define FOO to use this 
   macro' but this would generate a compilation error, not a compilation 
   warning.
On Mon, Nov 21, 2016 at 07:13:42PM +0100, Francois Gouget wrote:
> On Wed, 9 Nov 2016, Christophe Fergeau wrote:
> [...]
> > I believe all of these were more or less directly imported from glib.
> > Grepping around, I could only find SPICE_GNUC_VISIBLE, SPICE_GNUC_NORETURN,
> > SPICE_GNUC_UNUSED, SPICE_GNUC_PRINTF and SPICE_GNUC_DEPRECATED being
> > used. At this point, I'd just make sure the other ones emit a (compile
> > time) warning when they are used unless some magic define is set, and
> > drop them after a while.
> 
> I'm not sure how to do that:
>  * If I'm not mistaken a #warning directive must be used alone on a 
>    line but this is not how __attribute__ is used. Furthermore I doubt 
>    #warning would even work if put inside a macro and putting it inside 
>    the #ifdef would warn about the macro being defined, not about it 
>    being used.
> 
>  * I could define the macro to something like 'define FOO to use this 
>    macro' but this would generate a compilation error, not a compilation 
>    warning.

Ah, good point, forgot that they are macros, and that G_DEPRECATED can't
be used with them. Given that most of them go with function
prototypes, we could do something like

#define SPICE_GNUC_PURE  __attribute__ ((__pure__, warning("deprecated, use -DFOO or GG_GNUC_PURE instead")))

Christophe