From 646fcc3dbc5e981d741a0637158472f1a86cd5d3 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 27 Apr 2011 20:04:34 +0200 Subject: [PATCH] Make code compatible with yajl 2.0 *and* 1.0 --- common.mk | 4 ++++ src/ipc.c | 23 ++++++++++++++++++++++- yajl-fallback/yajl/yajl_version.h | 7 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 yajl-fallback/yajl/yajl_version.h diff --git a/common.mk b/common.mk index bcb77142..1a1143de 100644 --- a/common.mk +++ b/common.mk @@ -72,6 +72,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 diff --git a/src/ipc.c b/src/ipc.c index 1937d55d..b3052a2f 100644 --- 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 #include #include +#include #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 index 00000000..c6da442e --- /dev/null +++ b/yajl-fallback/yajl/yajl_version.h @@ -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