[PATCH v2 02/23] build: link to glib library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
      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@xxxxxxxxxx>
    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, which provides the foundation layer with
a collection of data structures, helper APIs, and platform portability
logic.

Later patches will introduce linkage to gobject which provides the
object type system, built on glib, and gio which providing objects
for various interesting tasks, most notably including DBus client
and server support and portable sockets APIs, but much more too.

Reviewed-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 docs/hacking.html.in       | 21 +++++++++++++++++++++
 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, 31 insertions(+), 1 deletion(-)

diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index edf2f54ce3..93b451591e 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -989,6 +989,27 @@ BAD:
       it points to, or it is aliased to another pointer that is.
     </p>
 
+    <h2><a id="glib">Adoption of GLib APIs</a></h2>
+ 
+    <p>
+      Libvirt has adopted use of the
+      <a href="https://developer.gnome.org/glib/stable/";>GLib library</a>.
+      Due to libvirt's long history of development, there are many APIs
+      in libvirt, for which GLib provides an alternative solution. The
+      general rule to follow is that the standard GLib solution will be
+      preferred over historical libvirt APIs. Existing code will be
+      ported over to use GLib APIs over time, but new code should use
+      the GLib APIs straight away where possible.
+    </p>
+
+    <p>
+      The following is a list of libvirt APIs that should no longer be
+      used in new code, and their suggested GLib replacements:
+    </p>
+
+    <dl>
+    </dl>
+
     <h2><a id="memalloc">Low level memory management</a></h2>
 
     <p>
diff --git a/src/Makefile.am b/src/Makefile.am
index bd03b09cb2..9d21395892 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) \
@@ -558,6 +559,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 e1a69be9f2..56e99241b0 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.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 9747816fac..454f8e1a8c 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -290,6 +290,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 ece70384e6..94fb4ecb8b 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux