[PATCH] build: work around jansson-2.1's API change

Jim Meyering jim at meyering.net
Mon Jul 4 08:18:44 UTC 2011


As reported in http://bugzilla.redhat.com/718249, iwhd failed to build due
to an incompatible API change in jansson-2.1 (a new "flags" argument is
required in two of the json_load* functions we use.  The fix is to insert
a "0," parameter on newer systems.  The fix below adds the configure-time
test to detect that and adjusts the code to use the result of that test.


>From 6bbc52f0a7ad647e35209b91b6ec13e876883622 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Mon, 4 Jul 2011 09:47:31 +0200
Subject: [PATCH] build: work around jansson-2.1's API change

* configure.ac: Add a compile-test to detect whether we need to
insert the new "flags" argument in each json_loads and json_load_file
argument list.
* setup.c (parse_config, auto_config): Use JANSSON_LOAD_FLAG.
* dc-rhev-image.c (main): Likewise.
* NEWS (Infrastructure): Mention this.
Reported by Chris Lalancette in http://bugzilla.redhat.com/718249
---
 NEWS            |    5 +++++
 configure.ac    |   12 ++++++++++++
 dc-rhev-image.c |    2 +-
 setup.c         |    4 ++--
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index ecd8847..2476201 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,11 @@ iwhd NEWS                                                   -*- outline -*-
   On Fedora systems, /etc/iwhd/conf.js is not overwritten anymore when
   upgrading the package (added %config(noreplace)).

+** Infrastructure
+
+  Adapt to jansson-1.2's new, incompatible changed API, so we can build
+  both with it and the older API.
+

 * Noteworthy changes in release 0.96 (2011-06-15) [stable]

diff --git a/configure.ac b/configure.ac
index 8945f7c..61199c2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,6 +85,18 @@ AC_CHECK_HEADER([mongo/client/dbclient.h], ,
   [#undef VERSION])
 AC_LANG_POP

+# Starting in jansson 2.1, file-loading functions require an
+# additional "flags" argument.  Test for this.
+AC_CACHE_CHECK([whether json_load_file takes 3 arguments],
+  [iw_cv_func_jansson_flag],
+  [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+    #include <jansson.h>
+    json_t *f (void) { return json_load_file ("file", 0, NULL); }]])],
+      [iw_cv_func_jansson_flag=0,],
+      [iw_cv_func_jansson_flag=])])
+AC_DEFINE_UNQUOTED([JANSSON_LOAD_FLAG], $iw_cv_func_jansson_flag,
+  [Define to "0," if json_load_file and json_loads require a flags arguments.])
+
 # from http://www.gnu.org/software/autoconf-archive/
 AX_BOOST_BASE
 AX_BOOST_SYSTEM
diff --git a/dc-rhev-image.c b/dc-rhev-image.c
index 7599fb8..c768445 100644
--- a/dc-rhev-image.c
+++ b/dc-rhev-image.c
@@ -2329,7 +2329,7 @@ int main(int argc, char **argv, char **envp)

 	memset(&cfg, 0, sizeof(struct config));

-	jcfg = json_load_file(cfgname, &err);
+	jcfg = json_load_file(cfgname, JANSSON_LOAD_FLAG &err);
 	if (!jcfg) {
 		fprintf(stderr, "ERROR configuration JSON error %s:%d: %s\n",
 		    cfgname, err.line, err.text);
diff --git a/setup.c b/setup.c
index caeb430..af2bb22 100644
--- a/setup.c
+++ b/setup.c
@@ -583,7 +583,7 @@ parse_config (char *cfg_file)
 		return NULL;
 	}

-	config = json_load_file(cfg_file,&err);
+	config = json_load_file(cfg_file, JANSSON_LOAD_FLAG &err);
 	if (!config) {
 		error(0,0,_("JSON error on line %d: %s"),err.line,err.text);
 		return NULL;
@@ -614,7 +614,7 @@ auto_config(void)
 		return NULL;
 	}

-	config = json_loads(auto_json,&err);
+	config = json_loads(auto_json, JANSSON_LOAD_FLAG &err);
 	if (!config) {
 		error(0, 0, _("JSON error on line %d: %s"), err.line, err.text);
 		return NULL;
--
1.7.6.370.gfeac5


More information about the iwhd-devel mailing list