[minicoredumper] [PATCH 2/6] Fix g_type_init warning

Simon Marchi simon.marchi at ericsson.com
Tue Oct 13 23:56:20 CEST 2015


When compiling with glib >= 2.36, we get this warning:

main.c:115:2: warning: ‘g_type_init’ is deprecated (declared at /usr/include/glib-2.0/gobject/gtype.h:667) [-Wdeprecated-declarations]
  g_type_init();

It is necessary to call it for earlier versions though.  The strategy
used by other projects I contributed to was to make "compatibility"
functions to deal with different version of libs or the kernel.  This
has the advantage of not polluting the code with #ifdefs.

Signed-off-by: Simon Marchi <simon.marchi at ericsson.com>
---
 src/compat/compat_mcd.h                | 39 ++++++++++++++++++++++++++++++++++
 src/libminicoredumper/Makefile.am      |  2 +-
 src/libminicoredumper/dbus_mcd.c       |  3 ++-
 src/minicoredumper/Makefile.am         |  2 +-
 src/minicoredumper/dbus_mcd.c          |  5 ++++-
 src/minicoredumper_dbusd/Makefile.am   |  1 +
 src/minicoredumper_dbusd/daemon.c      |  4 +++-
 src/minicoredumper_trigger/Makefile.am |  1 +
 src/minicoredumper_trigger/main.c      |  5 ++++-
 9 files changed, 56 insertions(+), 6 deletions(-)
 create mode 100644 src/compat/compat_mcd.h

diff --git a/src/compat/compat_mcd.h b/src/compat/compat_mcd.h
new file mode 100644
index 0000000..4ef9b54
--- /dev/null
+++ b/src/compat/compat_mcd.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015 Ericsson AB
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MCD_COMPAT_H__
+#define __MCD_COMPAT_H__
+
+static void g_type_init_compat(void)
+{
+	/* Starting with glib 2.36, it is unnecessary to call g_type_init (and
+	   will even throw a warning if it is called). */
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+	g_type_init();
+#endif
+}
+
+#endif
diff --git a/src/libminicoredumper/Makefile.am b/src/libminicoredumper/Makefile.am
index 2a07388..cc64563 100644
--- a/src/libminicoredumper/Makefile.am
+++ b/src/libminicoredumper/Makefile.am
@@ -23,7 +23,7 @@ libminicoredumper_la_SOURCES = mcd.c dump_data_private.h
 
 if USE_DBUS
 libminicoredumper_la_SOURCES += dbus_mcd.c
-dbus_CFLAGS += -DUSE_DBUS -I$(top_srcdir)/src/dbus
+dbus_CFLAGS += -DUSE_DBUS -I$(top_srcdir)/src/dbus -I$(top_srcdir)/src/compat
 endif
 
 libminicoredumper_la_CFLAGS = -g -Wall -std=c99 -D_GNU_SOURCE $(MCD_WERROR) \
diff --git a/src/libminicoredumper/dbus_mcd.c b/src/libminicoredumper/dbus_mcd.c
index fe0aab2..bebc0aa 100644
--- a/src/libminicoredumper/dbus_mcd.c
+++ b/src/libminicoredumper/dbus_mcd.c
@@ -26,6 +26,7 @@
 
 #include "common.h"
 #include "dbus_mcd.h"
+#include "compat_mcd.h"
 
 extern int dump_data_walk(char *path, int dump_scope);
 
@@ -117,7 +118,7 @@ void *start_dbus_gloop(void *arg)
 	/* unused */
 	(void)arg;
 
-	g_type_init();
+	g_type_init_compat();
 
 	uuid_generate_time_safe(uuid);
 
diff --git a/src/minicoredumper/Makefile.am b/src/minicoredumper/Makefile.am
index 7e5d392..c1ecaa1 100644
--- a/src/minicoredumper/Makefile.am
+++ b/src/minicoredumper/Makefile.am
@@ -21,7 +21,7 @@ minicoredumper_SOURCES = corestripper.c corestripper.h \
 
 if USE_DBUS
 minicoredumper_SOURCES += dbus_mcd.c
-dbus_CFLAGS += -DUSE_DBUS -I$(top_srcdir)/src/dbus
+dbus_CFLAGS += -DUSE_DBUS -I$(top_srcdir)/src/dbus -I$(top_srcdir)/src/compat
 endif
 
 minicoredumper_LDADD = $(top_builddir)/lib/libjson.a -lelf -lthread_db \
diff --git a/src/minicoredumper/dbus_mcd.c b/src/minicoredumper/dbus_mcd.c
index 430c5ba..f43e9b6 100644
--- a/src/minicoredumper/dbus_mcd.c
+++ b/src/minicoredumper/dbus_mcd.c
@@ -51,6 +51,9 @@
 #include "corestripper.h"
 #include "dbus_mcd.h"
 
+/* Pull in compatibility layer functions. */
+#include "compat_mcd.h"
+
 /* Define the time out in ms */
 #define TIME_OUT 500
 
@@ -123,7 +126,7 @@ int start_dbus_gloop(void *_di)
 	info("pid        : %i", localstate.pid);
 	info("dump scope : %i", localstate.dump_scope);
 
-	g_type_init();
+	g_type_init_compat();
 
 	mainloop = g_main_loop_new(NULL, FALSE);
 
diff --git a/src/minicoredumper_dbusd/Makefile.am b/src/minicoredumper_dbusd/Makefile.am
index 128da9b..8644bf7 100644
--- a/src/minicoredumper_dbusd/Makefile.am
+++ b/src/minicoredumper_dbusd/Makefile.am
@@ -20,4 +20,5 @@ dbus_CFLAGS += -I$(top_srcdir)/src/dbus
 
 minicoredumper_dbusd_LDADD = @dbus_LIBS@
 minicoredumper_dbusd_CFLAGS = -g -Wall -std=c99 -D_GNU_SOURCE $(MCD_WERROR) \
+			      -I$(top_srcdir)/src/compat \
 			      $(dbus_CFLAGS)
diff --git a/src/minicoredumper_dbusd/daemon.c b/src/minicoredumper_dbusd/daemon.c
index 3434d96..87d2a5a 100644
--- a/src/minicoredumper_dbusd/daemon.c
+++ b/src/minicoredumper_dbusd/daemon.c
@@ -32,6 +32,8 @@
 
 #include "common.h"
 
+#include "compat_mcd.h"
+
 #define APPNAME "minicoredumper_dbusd"
 
 typedef enum {
@@ -484,7 +486,7 @@ int main(void)
 	guint result;
 	GError *error = NULL;
 
-	g_type_init();
+	g_type_init_compat();
 
 	mainloop = g_main_loop_new(NULL, FALSE);
 	if (!mainloop) {
diff --git a/src/minicoredumper_trigger/Makefile.am b/src/minicoredumper_trigger/Makefile.am
index e2703c5..ff96b68 100644
--- a/src/minicoredumper_trigger/Makefile.am
+++ b/src/minicoredumper_trigger/Makefile.am
@@ -24,4 +24,5 @@ minicoredumper_trigger_CFLAGS = -g -Wall -std=c99 -D_GNU_SOURCE $(MCD_WERROR) \
 			-D_LARGEFILE64_SOURCE $(dbus_CFLAGS) \
 			-I$(top_srcdir)/lib \
 			-I$(top_srcdir)/src/api \
+			-I$(top_srcdir)/src/compat \
 			-I$(top_srcdir)/src/libminicoredumper
diff --git a/src/minicoredumper_trigger/main.c b/src/minicoredumper_trigger/main.c
index a51f503..c4921b6 100644
--- a/src/minicoredumper_trigger/main.c
+++ b/src/minicoredumper_trigger/main.c
@@ -49,6 +49,9 @@
    dbus-binding-tool */
 #include "dbus_mcd.h"
 
+/* Pull in compatibility layer functions. */
+#include "compat_mcd.h"
+
 /* Define the time out in ms */
 #define TIME_OUT 5000
 
@@ -112,7 +115,7 @@ int main(int argc, char *argv[])
 	mkdir(argv[1], 01777);
 	chmod(argv[1], 01777);
 
-	g_type_init();
+	g_type_init_compat();
 
 	mainloop = g_main_loop_new(NULL, FALSE);
 
-- 
2.5.1





More information about the minicoredumper mailing list