[Spice-devel,protocol,1/3] macros: Improve the SPICE_GNUC_DEPRECATED* macros

Submitted by Francois Gouget on Aug. 11, 2016, 2:30 p.m.

Details

Message ID f15255930b71d881e83dc97a866e434dd46c496a.1470923646.git.fgouget@free.fr
State New
Headers show
Series "Fixing the *_DEPRECATED set of macros" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Francois Gouget Aug. 11, 2016, 2:30 p.m.
If the user specifically requests access to the deprecated APIs by
defining the SPICE_DEPRECATED macro, then turn off the
SPICE_GNUC_DEPRECATED* warnings.
Also automatically use G_GNUC_DEPRECATED if available.
Add SPICE_GNUC_DEPRECATED_FOR().

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
---
 spice/macros.h | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/spice/macros.h b/spice/macros.h
index a0413f3..6e2dbce 100644
--- a/spice/macros.h
+++ b/spice/macros.h
@@ -78,11 +78,25 @@ 
 #define SPICE_GNUC_NO_INSTRUMENT
 #endif  /* !__GNUC__ */
 
-#if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
-#define SPICE_GNUC_DEPRECATED  __attribute__((__deprecated__))
+#if     defined(SPICE_DEPRECATED)
+/* Don't warn when deprecated APIs have been explicitly asked for */
+#  define SPICE_GNUC_DEPRECATED
+#elif   defined(G_GNUC_DEPRECATED)
+#  define SPICE_GNUC_DEPRECATED G_GNUC_DEPRECATED
+#elif   __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+#  define SPICE_GNUC_DEPRECATED  __attribute__((__deprecated__))
 #else
-#define SPICE_GNUC_DEPRECATED
-#endif /* __GNUC__ */
+#  define SPICE_GNUC_DEPRECATED
+#endif  /* __GNUC__ */
+
+#if     defined(SPICE_DEPRECATED)
+/* Don't warn when deprecated APIs have been explicitly asked for */
+#  define SPICE_GNUC_DEPRECATED_FOR(f)
+#elif   __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#  define SPICE_GNUC_DEPRECATED_FOR(f) __attribute__((deprecated("Use " #f " instead")))
+#else
+#  define SPICE_GNUC_DEPRECATED_FOR(f) SPICE_GNUC_DEPRECATED
+#endif  /* __GNUC__ */
 
 #if     __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
 #  define SPICE_GNUC_MAY_ALIAS __attribute__((may_alias))

Comments

> 
> If the user specifically requests access to the deprecated APIs by
> defining the SPICE_DEPRECATED macro, then turn off the
> SPICE_GNUC_DEPRECATED* warnings.
> Also automatically use G_GNUC_DEPRECATED if available.
> Add SPICE_GNUC_DEPRECATED_FOR().
> 

I'm not really sure it's a good idea to disable deprecation
warnings. If a program does want to ignore warnings I will
just force to avoid -Werror and tolerate the warnings.

> Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
> ---
>  spice/macros.h | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/spice/macros.h b/spice/macros.h
> index a0413f3..6e2dbce 100644
> --- a/spice/macros.h
> +++ b/spice/macros.h
> @@ -78,11 +78,25 @@
>  #define SPICE_GNUC_NO_INSTRUMENT
>  #endif  /* !__GNUC__ */
>  
> -#if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
> -#define SPICE_GNUC_DEPRECATED  __attribute__((__deprecated__))
> +#if     defined(SPICE_DEPRECATED)
> +/* Don't warn when deprecated APIs have been explicitly asked for */
> +#  define SPICE_GNUC_DEPRECATED
> +#elif   defined(G_GNUC_DEPRECATED)
> +#  define SPICE_GNUC_DEPRECATED G_GNUC_DEPRECATED
> +#elif   __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
> +#  define SPICE_GNUC_DEPRECATED  __attribute__((__deprecated__))
>  #else
> -#define SPICE_GNUC_DEPRECATED
> -#endif /* __GNUC__ */
> +#  define SPICE_GNUC_DEPRECATED
> +#endif  /* __GNUC__ */
> +
> +#if     defined(SPICE_DEPRECATED)
> +/* Don't warn when deprecated APIs have been explicitly asked for */
> +#  define SPICE_GNUC_DEPRECATED_FOR(f)
> +#elif   __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
> +#  define SPICE_GNUC_DEPRECATED_FOR(f) __attribute__((deprecated("Use " #f "
> instead")))
> +#else
> +#  define SPICE_GNUC_DEPRECATED_FOR(f) SPICE_GNUC_DEPRECATED
> +#endif  /* __GNUC__ */
>  
>  #if     __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
>  #  define SPICE_GNUC_MAY_ALIAS __attribute__((may_alias))

Frediano
On Fri, 12 Aug 2016, Frediano Ziglio wrote:

> > 
> > If the user specifically requests access to the deprecated APIs by
> > defining the SPICE_DEPRECATED macro, then turn off the
> > SPICE_GNUC_DEPRECATED* warnings.
> > Also automatically use G_GNUC_DEPRECATED if available.
> > Add SPICE_GNUC_DEPRECATED_FOR().
> > 
> 
> I'm not really sure it's a good idea to disable deprecation
> warnings. If a program does want to ignore warnings I will
> just force to avoid -Werror and tolerate the warnings.

The deprecation warnings are only disabled if one defines 
SPICE_DEPRECATED, which is obviously not the case by default.

This is needed by spice-gtk so it can implement those deprecated APIs 
that other applications may want to use without getting warnings 
itself.

That said, an additional patch could potentially move the 
-DSPICE_DEPRECATED from Makefile.am to a #define SPICE_DEPRECATED in the 
relevant C files so it does not have as large a footprint.
> 
> On Fri, 12 Aug 2016, Frediano Ziglio wrote:
> 
> > > 
> > > If the user specifically requests access to the deprecated APIs by
> > > defining the SPICE_DEPRECATED macro, then turn off the
> > > SPICE_GNUC_DEPRECATED* warnings.
> > > Also automatically use G_GNUC_DEPRECATED if available.
> > > Add SPICE_GNUC_DEPRECATED_FOR().
> > > 
> > 
> > I'm not really sure it's a good idea to disable deprecation
> > warnings. If a program does want to ignore warnings I will
> > just force to avoid -Werror and tolerate the warnings.
> 
> The deprecation warnings are only disabled if one defines
> SPICE_DEPRECATED, which is obviously not the case by default.
> 
> This is needed by spice-gtk so it can implement those deprecated APIs
> that other applications may want to use without getting warnings
> itself.
> 

in spice-core.h these lines:

#ifdef SPICE_SERVER_INTERNAL
#undef SPICE_GNUC_DEPRECATED
#define SPICE_GNUC_DEPRECATED
#endif

are used to do it.

> That said, an additional patch could potentially move the
> -DSPICE_DEPRECATED from Makefile.am to a #define SPICE_DEPRECATED in the
> relevant C files so it does not have as large a footprint.
> 

Frediano
On Fri, 12 Aug 2016, Frediano Ziglio wrote:

> > 
> > On Fri, 12 Aug 2016, Frediano Ziglio wrote:
> > 
> > > > 
> > > > If the user specifically requests access to the deprecated APIs by
> > > > defining the SPICE_DEPRECATED macro, then turn off the
> > > > SPICE_GNUC_DEPRECATED* warnings.
> > > > Also automatically use G_GNUC_DEPRECATED if available.
> > > > Add SPICE_GNUC_DEPRECATED_FOR().
> > > > 
> > > 
> > > I'm not really sure it's a good idea to disable deprecation
> > > warnings. If a program does want to ignore warnings I will
> > > just force to avoid -Werror and tolerate the warnings.
> > 
> > The deprecation warnings are only disabled if one defines
> > SPICE_DEPRECATED, which is obviously not the case by default.
> > 
> > This is needed by spice-gtk so it can implement those deprecated APIs
> > that other applications may want to use without getting warnings
> > itself.
> > 
> 
> in spice-core.h these lines:
> 
> #ifdef SPICE_SERVER_INTERNAL
> #undef SPICE_GNUC_DEPRECATED
> #define SPICE_GNUC_DEPRECATED
> #endif
> 
> are used to do it.

That seems redundant with the SPICE_DEPRECATED mechanism. Also, as in 
spice-gtk, it's again global (-DSPICE_SERVER_INTERNAL in 
server/Makefile.am), impacting all the Spice server source files, even 
those that have no business using the deprecated APIs.

It's also yet another way of achieving the same thing:
 * spice-protocol -> define SPICE_DEPRECATED
 * spice-gtk      -> define SPICE_NO_DEPRECATED
 * spice          -> define SPICE_SERVER_INTERNAL
On Thu, Aug 11, 2016 at 04:30:44PM +0200, Francois Gouget wrote:
> If the user specifically requests access to the deprecated APIs by
> defining the SPICE_DEPRECATED macro, then turn off the
> SPICE_GNUC_DEPRECATED* warnings.

Ok, that's one thing

> Also automatically use G_GNUC_DEPRECATED if available.

And this is something totally unrelated to the first. Not sure how
comfortable I am with this automagic use of glib in a module not
depending on it at all. I think I can live with it, but that's still
odd.

> Add SPICE_GNUC_DEPRECATED_FOR().

And that's a 3rd different thing. Can you split please ? :)

Christophe