Pino Toscano
2020-Jun-19 16:03 UTC
[Libguestfs] [v2v PATCH] libosinfo: declare autocleanup funcs with libosinfo < 1.8.0
libosinfo 1.8.0 declares them automatically for all of its classes, so
there is no need to declare ours. This requires fixing the definition of
the IS_LIBOSINFO_VERSION macro to wrap its body in brackets.
While in the process, simplify the workaround for a related bug by
removing a now-useless check.
---
v2v/libosinfo-c.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/v2v/libosinfo-c.c b/v2v/libosinfo-c.c
index e5327dff..322e7d3d 100644
--- a/v2v/libosinfo-c.c
+++ b/v2v/libosinfo-c.c
@@ -40,8 +40,13 @@
#define V2V_LIBOSINFO_VERSION_HEX \
MAKE_VERSION_HEX(OSINFO_MAJOR_VERSION, OSINFO_MINOR_VERSION,
OSINFO_MICRO_VERSION)
#define IS_LIBOSINFO_VERSION(maj, min, mic) \
- V2V_LIBOSINFO_VERSION_HEX >= MAKE_VERSION_HEX(maj, min, mic)
+ (V2V_LIBOSINFO_VERSION_HEX >= MAKE_VERSION_HEX(maj, min, mic))
+/*
+ * libosinfo 1.8.0 provides auto-cleanup functions for all its classes,
+ * so avoid declaring our own.
+ */
+#if !IS_LIBOSINFO_VERSION(1, 8, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoFilter, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoLoader, g_object_unref)
/*
@@ -50,11 +55,13 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoLoader, g_object_unref)
* avoid declaring this when:
* - libosinfo is >= 1.7.0 and < 1.8.0
* - glib is >= 2.63.3
+ * (the 1.8.0 check is not done, as already covered by the check above)
*/
-#if !IS_LIBOSINFO_VERSION(1, 7, 0) || IS_LIBOSINFO_VERSION(1, 8, 0) ||
!GLIB_CHECK_VERSION(2, 63, 3)
+#if !IS_LIBOSINFO_VERSION(1, 7, 0) || !GLIB_CHECK_VERSION(2, 63, 3)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoList, g_object_unref)
#endif
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoOsList, g_object_unref)
+#endif
typedef OsinfoDb *OsinfoDb_t;
typedef OsinfoOs *OsinfoOs_t;
--
2.25.4
Richard W.M. Jones
2020-Jun-19 20:09 UTC
Re: [Libguestfs] [v2v PATCH] libosinfo: declare autocleanup funcs with libosinfo < 1.8.0
On Fri, Jun 19, 2020 at 06:03:40PM +0200, Pino Toscano wrote:> libosinfo 1.8.0 declares them automatically for all of its classes, so > there is no need to declare ours. This requires fixing the definition of > the IS_LIBOSINFO_VERSION macro to wrap its body in brackets. > > While in the process, simplify the workaround for a related bug by > removing a now-useless check. > --- > v2v/libosinfo-c.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/v2v/libosinfo-c.c b/v2v/libosinfo-c.c > index e5327dff..322e7d3d 100644 > --- a/v2v/libosinfo-c.c > +++ b/v2v/libosinfo-c.c > @@ -40,8 +40,13 @@ > #define V2V_LIBOSINFO_VERSION_HEX \ > MAKE_VERSION_HEX(OSINFO_MAJOR_VERSION, OSINFO_MINOR_VERSION, OSINFO_MICRO_VERSION) > #define IS_LIBOSINFO_VERSION(maj, min, mic) \ > - V2V_LIBOSINFO_VERSION_HEX >= MAKE_VERSION_HEX(maj, min, mic) > + (V2V_LIBOSINFO_VERSION_HEX >= MAKE_VERSION_HEX(maj, min, mic)) > > +/* > + * libosinfo 1.8.0 provides auto-cleanup functions for all its classes, > + * so avoid declaring our own. > + */ > +#if !IS_LIBOSINFO_VERSION(1, 8, 0) > G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoFilter, g_object_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoLoader, g_object_unref) > /* > @@ -50,11 +55,13 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoLoader, g_object_unref) > * avoid declaring this when: > * - libosinfo is >= 1.7.0 and < 1.8.0 > * - glib is >= 2.63.3 > + * (the 1.8.0 check is not done, as already covered by the check above) > */ > -#if !IS_LIBOSINFO_VERSION(1, 7, 0) || IS_LIBOSINFO_VERSION(1, 8, 0) || !GLIB_CHECK_VERSION(2, 63, 3) > +#if !IS_LIBOSINFO_VERSION(1, 7, 0) || !GLIB_CHECK_VERSION(2, 63, 3) > G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoList, g_object_unref) > #endif > G_DEFINE_AUTOPTR_CLEANUP_FUNC(OsinfoOsList, g_object_unref) > +#endif > > typedef OsinfoDb *OsinfoDb_t; > typedef OsinfoOs *OsinfoOs_t;This fixes virt-v2v with osinfo 1.8.0. But with libosinfo 1.7.1 I still get lots of errors (see attached). Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Reasonably Related Threads
- [v2v PATCH v2] libosinfo: do not declare OsinfoList auto-cleanup in certain situations
- [v2v PATCH v2 0/3] Use libosinfo for query device drivers
- [v2v PATCH] libosinfo: remove auto-cleanup for OsinfoList
- [v2v PATCH] libosinfo: declare OsinfoList auto-cleanup with glib < 2.63.3
- virt-v2v: error: redefinition of 'glib_autoptr_clear_OsinfoList'