[libvirt PATCH 01/11] glibcompat: Add wrapper for g_auto*

Pavel Hrdina phrdina at redhat.com
Wed Aug 25 15:02:30 UTC 2021


On Wed, Aug 25, 2021 at 02:43:20PM +0200, Tim Wiederhake wrote:
> See comment for rationale.
> 
> Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
> ---
>  src/util/glibcompat.h | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h
> index 697687b967..fe495c5c32 100644
> --- a/src/util/glibcompat.h
> +++ b/src/util/glibcompat.h
> @@ -86,3 +86,23 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args)
>  #define g_fsync vir_g_fsync
>  
>  void vir_g_source_unref(GSource *src, GMainContext *ctx);
> +
> +/*
> + * Clang falsely tags variable definitions as unused if the only access happens
> + * during the variables destruction at scope exit. See
> + * https://bugs.llvm.org/show_bug.cgi?id=3888 and
> + * https://bugs.llvm.org/show_bug.cgi?id=43482.
> + */
> +#if defined(__clang__)
> +# define vir_g_auto(X) g_auto(X) G_GNUC_UNUSED
> +# define vir_g_autolist(X) g_autolist(X) G_GNUC_UNUSED
> +# define vir_g_autoptr(X) g_autoptr(X) G_GNUC_UNUSED
> +# define vir_g_autoqueue(X) g_autoqueue(X) G_GNUC_UNUSED
> +# define vir_g_autoslist(X) g_autoslist(X) G_GNUC_UNUSED
> +#else
> +# define vir_g_auto(X) g_auto(X)
> +# define vir_g_autolist(X) g_autolist(X)
> +# define vir_g_autoptr(X) g_autoptr(X)
> +# define vir_g_autoqueue(X) g_autoqueue(X)
> +# define vir_g_autoslist(X) g_autoslist(X)
> +#endif /* __clang__ */

I don't think this belongs into this file. It is meant to workaround
bugs in glib, not in compilers. In addition I don't think we would like
to mix vir_g_auto and g_auto within libvirt codebase. If we need to
introduce our own wrappers we should undefine the original symbol and
replace it like we do with g_fsync for example:

Pavel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210825/294301b5/attachment-0001.sig>


More information about the libvir-list mailing list