Make code compatible with yajl 2.0 *and* 1.0

This commit is contained in:
Michael Stapelberg 2011-04-27 20:04:34 +02:00
parent b78b23de97
commit 7cc3dae079
3 changed files with 33 additions and 1 deletions

View File

@ -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

View File

@ -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;

View File

@ -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