]> git.sur5r.net Git - i3/i3/commitdiff
Make code compatible with yajl 2.0 *and* 1.0
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 27 Apr 2011 18:04:34 +0000 (20:04 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 27 Apr 2011 18:05:02 +0000 (20:05 +0200)
common.mk
src/ipc.c
yajl-fallback/yajl/yajl_version.h [new file with mode: 0644]

index e3a9f80bf09de5ba6e2ee9196fae5d7e66dfea9c..d45286a8f63b81e886646ee3aeaee46f6701d4da 100644 (file)
--- a/common.mk
+++ b/common.mk
@@ -73,6 +73,10 @@ ifeq ($(UNAME),FreeBSD)
 LDFLAGS += -liconv
 endif
 
+# Fallback for libyajl 1 which did not include yajl_version.h. We need
+# YAJL_MAJOR from that file to decide which code path should be used.
+CFLAGS += -idirafter yajl-fallback
+
 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
 CFLAGS += -D_GNU_SOURCE
 endif
index fcda355e0b10a76cab2c00f7e04eb1186d5fe900..d2f0def01f6f93d198ed7300c9eea93ce082d1d1 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -3,7 +3,7 @@
  *
  * i3 - an improved dynamic tiling window manager
  *
- * © 2009-2010 Michael Stapelberg and contributors
+ * © 2009-2011 Michael Stapelberg and contributors
  *
  * See file LICENSE for license information.
  *
@@ -26,6 +26,7 @@
 #include <ev.h>
 #include <yajl/yajl_gen.h>
 #include <yajl/yajl_parse.h>
+#include <yajl/yajl_version.h>
 
 #include "queue.h"
 #include "ipc.h"
@@ -182,7 +183,11 @@ IPC_HANDLER(get_workspaces) {
         if (last_focused == SLIST_END(&(c_ws->focus_stack)))
                 last_focused = NULL;
 
+#if YAJL_MAJOR >= 2
+        yajl_gen gen = yajl_gen_alloc(NULL);
+#else
         yajl_gen gen = yajl_gen_alloc(NULL, NULL);
+#endif
         y(array_open);
 
         TAILQ_FOREACH(ws, workspaces, workspaces) {
@@ -226,7 +231,11 @@ IPC_HANDLER(get_workspaces) {
         y(array_close);
 
         const unsigned char *payload;
+#if YAJL_MAJOR >= 2
+        size_t length;
+#else
         unsigned int length;
+#endif
         y(get_buf, &payload, &length);
 
         ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_WORKSPACES, length);
@@ -241,7 +250,11 @@ IPC_HANDLER(get_workspaces) {
 IPC_HANDLER(get_outputs) {
         Output *output;
 
+#if YAJL_MAJOR >= 2
+        yajl_gen gen = yajl_gen_alloc(NULL);
+#else
         yajl_gen gen = yajl_gen_alloc(NULL, NULL);
+#endif
         y(array_open);
 
         TAILQ_FOREACH(output, &outputs, outputs) {
@@ -276,7 +289,11 @@ IPC_HANDLER(get_outputs) {
         y(array_close);
 
         const unsigned char *payload;
+#if YAJL_MAJOR >= 2
+        size_t length;
+#else
         unsigned int length;
+#endif
         y(get_buf, &payload, &length);
 
         ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_OUTPUTS, length);
@@ -338,7 +355,11 @@ IPC_HANDLER(subscribe) {
         memset(&callbacks, 0, sizeof(yajl_callbacks));
         callbacks.yajl_string = add_subscription;
 
+#if YAJL_MAJOR >= 2
+        p = yajl_alloc(&callbacks, NULL, (void*)client);
+#else
         p = yajl_alloc(&callbacks, NULL, NULL, (void*)client);
+#endif
         stat = yajl_parse(p, (const unsigned char*)message, message_size);
         if (stat != yajl_status_ok) {
                 unsigned char *err;
diff --git a/yajl-fallback/yajl/yajl_version.h b/yajl-fallback/yajl/yajl_version.h
new file mode 100644 (file)
index 0000000..c6da442
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef YAJL_VERSION_H_
+#define YAJL_VERSION_H_
+/* Fallback for libyajl 1 which does not provide yajl_version.h */
+#define YAJL_MAJOR 1
+#define YAJL_MINOR 0
+#define YAJL_MICRO 0
+#endif