[libvirt] [PATCH 02/11] build: link to glib, gobject, gio libraries

Daniel P. Berrangé berrange at redhat.com
Fri Sep 27 17:17:24 UTC 2019


Add the main glib.h to internal.h so that all common code can use it.

Historically glib allowed applications to register an alternative
memory allocator, so mixing g_malloc/g_free with malloc/free was not
safe.

This was feature was dropped in 2.46.0 with:

      commit 3be6ed60aa58095691bd697344765e715a327fc1
      Author: Alexander Larsson <alexl at redhat.com>
      Date:   Sat Jun 27 18:38:42 2015 +0200

        Deprecate and drop support for memory vtables

Applications are still encourged to match g_malloc/g_free, but it is no
longer a mandatory requirement for correctness, just stylistic. This is
explicitly clarified in

    commit 1f24b36607bf708f037396014b2cdbc08d67b275
    Author: Daniel P. Berrangé <berrange at redhat.com>
    Date:   Thu Sep 5 14:37:54 2019 +0100

        gmem: clarify that g_malloc always uses the system allocator

Applications can still use custom allocators in general, but they must
do this by linking to a library that replaces the core malloc/free
implemenentation entirely, instead of via a glib specific call.

This means that libvirt does not need to be concerned about use of
g_malloc/g_free causing an ABI change in the public libary, and can
avoid memory copying when talking to external libraries.

This patch probes for glib, gobject and gio.  Glib provides the
foundation layer with a collection of data structures, helper
APIs, and platform portability logic. GObject provides the object
type system, built on glib. GIO builds on GObject, providing objects
for various interesting tasks, most notably including DBus client
and server support and portable sockets APIs, but much more too.

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 m4/virt-glib.m4            | 4 ++--
 src/Makefile.am            | 2 ++
 src/internal.h             | 1 +
 src/lxc/Makefile.inc.am    | 2 ++
 src/remote/Makefile.inc.am | 1 +
 src/util/Makefile.inc.am   | 1 +
 tests/Makefile.am          | 3 ++-
 tools/Makefile.am          | 1 +
 8 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/m4/virt-glib.m4 b/m4/virt-glib.m4
index 5a5bc19660..e9992e9824 100644
--- a/m4/virt-glib.m4
+++ b/m4/virt-glib.m4
@@ -24,10 +24,10 @@ AC_DEFUN([LIBVIRT_ARG_GLIB], [
 AC_DEFUN([LIBVIRT_CHECK_GLIB],[
   GLIB_REQUIRED=2.48.0
 
-  LIBVIRT_CHECK_PKG([GLIB], [glib-2.0], [$GLIB_REQUIRED])
+  LIBVIRT_CHECK_PKG([GLIB], [glib-2.0 gobject-2.0 gio-2.0], [$GLIB_REQUIRED])
 
   if test "$with_glib" = "no" ; then
-    AC_MSG_ERROR([glib-2.0 >= $GLIB_REQUIRED is required for libvirt])
+    AC_MSG_ERROR([glib-2.0, gobject-2.0, gio-2.0 >= $GLIB_REQUIRED is required for libvirt])
   fi
 ])
 
diff --git a/src/Makefile.am b/src/Makefile.am
index cd955ee552..66ba710e50 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,7 @@ AM_CPPFLAGS =	-I../gnulib/lib \
 WARN_CFLAGS += $(STRICT_FRAME_LIMIT_CFLAGS)
 
 AM_CFLAGS =	$(LIBXML_CFLAGS) \
+		$(GLIB_CFLAGS) \
 		$(WARN_CFLAGS) \
 		$(LOCK_CHECKING_CFLAGS) \
 		$(WIN32_EXTRA_CFLAGS) \
@@ -559,6 +560,7 @@ libvirt_admin_la_LIBADD += \
 		$(YAJL_LIBS) \
 		$(DEVMAPPER_LIBS) \
 		$(LIBXML_LIBS) \
+		$(GLIB_LIBS) \
 		$(SSH2_LIBS) \
 		$(SASL_LIBS) \
 		$(GNUTLS_LIBS) \
diff --git a/src/internal.h b/src/internal.h
index adc1e3f496..55aaf937cf 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -27,6 +27,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
+#include <glib.h>
 
 #if STATIC_ANALYSIS
 # undef NDEBUG /* Don't let a prior NDEBUG definition cause trouble.  */
diff --git a/src/lxc/Makefile.inc.am b/src/lxc/Makefile.inc.am
index b4d560702c..0c9618e185 100644
--- a/src/lxc/Makefile.inc.am
+++ b/src/lxc/Makefile.inc.am
@@ -184,6 +184,7 @@ libvirt_lxc_LDFLAGS = \
 	$(PIE_LDFLAGS) \
 	$(CAPNG_LIBS) \
 	$(LIBXML_LIBS) \
+	$(GLIB_LIBS) \
 	$(NULL)
 libvirt_lxc_LDADD = \
 	libvirt.la \
@@ -200,6 +201,7 @@ libvirt_lxc_CFLAGS = \
 	$(PIE_CFLAGS) \
 	$(CAPNG_CFLAGS) \
 	$(LIBXML_CFLAGS) \
+	$(GLIB_CFLAGS) \
 	$(LIBNL_CFLAGS) \
 	$(FUSE_CFLAGS) \
 	$(DBUS_CFLAGS) \
diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am
index 5a5c90a922..e02c20d47c 100644
--- a/src/remote/Makefile.inc.am
+++ b/src/remote/Makefile.inc.am
@@ -38,6 +38,7 @@ REMOTE_DAEMON_SOURCES = \
 
 REMOTE_DAEMON_CFLAGS = \
 	$(LIBXML_CFLAGS) \
+	$(GLIB_CFLAGS) \
 	$(GNUTLS_CFLAGS) \
 	$(SASL_CFLAGS) \
 	$(XDR_CFLAGS) \
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index 482b657a90..a415378fe2 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -289,6 +289,7 @@ libvirt_util_la_LIBADD = \
 	$(DBUS_LIBS) \
 	$(WIN32_EXTRA_LIBS) \
 	$(LIBXML_LIBS) \
+	$(GLIB_LIBS) \
 	$(SECDRIVER_LIBS) \
 	$(NUMACTL_LIBS) \
 	$(ACL_LIBS) \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d88ad7f686..7b81ee88f1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -35,6 +35,7 @@ AM_CFLAGS = \
 	-Dabs_srcdir="\"$(abs_srcdir)\"" \
 	-Dabs_top_srcdir="\"$(abs_top_srcdir)\"" \
 	$(LIBXML_CFLAGS) \
+	$(GLIB_CFLAGS) \
 	$(LIBNL_CFLAGS) \
 	$(GNUTLS_CFLAGS) \
 	$(SASL_CFLAGS) \
@@ -525,7 +526,7 @@ libxlxml2domconfigtest_LDADD = $(libxl_LDADDS) $(LIBXML_LIBS)
 
 libxlmock_la_SOURCES = \
 	libxlmock.c
-libxlmock_la_CFLAGS = $(LIBXL_CFLAGS) $(LIBXML_CFLAGS)
+libxlmock_la_CFLAGS = $(LIBXL_CFLAGS) $(LIBXML_CFLAGS) $(GLIB_CFLAGS)
 libxlmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
 libxlmock_la_LIBADD = $(MOCKLIBS_LIBS)
 
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 29fdbfe846..9489cb35db 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -36,6 +36,7 @@ AM_CFLAGS = \
 	$(COVERAGE_CFLAGS) \
 	$(PIE_CFLAGS) \
 	$(LIBXML_CFLAGS) \
+	$(GLIB_CFLAGS) \
 	$(NULL)
 
 AM_LDFLAGS = \
-- 
2.21.0




More information about the libvir-list mailing list