summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml6
-rw-r--r--CHANGELOG.md2
-rw-r--r--Makefile17
-rw-r--r--adapters/libevent.h24
-rw-r--r--adapters/libuv.h5
-rw-r--r--appveyor.yml17
-rw-r--r--async.c5
-rw-r--r--fmacros.h21
-rw-r--r--hiredis.c7
-rw-r--r--hiredis.h4
-rw-r--r--net.c5
-rw-r--r--net.h2
-rw-r--r--read.c2
-rw-r--r--sds.c2
14 files changed, 67 insertions, 52 deletions
diff --git a/.travis.yml b/.travis.yml
index ad08076..faf2ce6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,12 @@ os:
- linux
- osx
+branches:
+ only:
+ - staging
+ - trying
+ - master
+
before_script:
- if [ "$TRAVIS_OS_NAME" == "osx" ] ; then brew update; brew install redis; fi
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f92bcb3..f40ec53 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -94,7 +94,7 @@ The parser, standalone since v0.12.0, can now be compiled on Windows
* Add IPv6 support
-* Remove possiblity of multiple close on same fd
+* Remove possibility of multiple close on same fd
* Add ability to bind source address on connect
diff --git a/Makefile b/Makefile
index 9a4de83..28a7849 100644
--- a/Makefile
+++ b/Makefile
@@ -36,13 +36,13 @@ endef
export REDIS_TEST_CONFIG
# Fallback to gcc when $CC is not in $PATH.
-CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
-CXX:=$(shell sh -c 'type $(CXX) >/dev/null 2>/dev/null && echo $(CXX) || echo g++')
+CC:=$(shell sh -c 'type $${CC%% *} >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
+CXX:=$(shell sh -c 'type $${CXX%% *} >/dev/null 2>/dev/null && echo $(CXX) || echo g++')
OPTIMIZATION?=-O3
WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings
DEBUG_FLAGS?= -g -ggdb
-REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG_FLAGS) $(ARCH)
-REAL_LDFLAGS=$(LDFLAGS) $(ARCH)
+REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG_FLAGS)
+REAL_LDFLAGS=$(LDFLAGS)
DYLIBSUFFIX=so
STLIBSUFFIX=a
@@ -94,7 +94,7 @@ hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME)
$(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -lev $(STLIBNAME)
hiredis-example-glib: examples/example-glib.c adapters/glib.h $(STLIBNAME)
- $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) $(shell pkg-config --cflags --libs glib-2.0) -I. $< $(STLIBNAME)
+ $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< $(shell pkg-config --cflags --libs glib-2.0) $(STLIBNAME)
hiredis-example-ivykis: examples/example-ivykis.c adapters/ivykis.h $(STLIBNAME)
$(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -livykis $(STLIBNAME)
@@ -161,7 +161,7 @@ clean:
dep:
$(CC) -MM *.c
-ifeq ($(uname_S),SunOS)
+ifeq ($(uname_S),$(filter $(uname_S),SunOS OpenBSD))
INSTALL?= cp -r
endif
@@ -181,8 +181,9 @@ $(PKGCONFNAME): hiredis.h
@echo Cflags: -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@
install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME)
- mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
- $(INSTALL) hiredis.h async.h read.h sds.h adapters $(INSTALL_INCLUDE_PATH)
+ mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL_LIBRARY_PATH)
+ $(INSTALL) hiredis.h async.h read.h sds.h $(INSTALL_INCLUDE_PATH)
+ $(INSTALL) adapters/*.h $(INSTALL_INCLUDE_PATH)/adapters
$(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME)
cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIBNAME)
$(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
diff --git a/adapters/libevent.h b/adapters/libevent.h
index 1c2b271..7d2bef1 100644
--- a/adapters/libevent.h
+++ b/adapters/libevent.h
@@ -30,13 +30,13 @@
#ifndef __HIREDIS_LIBEVENT_H__
#define __HIREDIS_LIBEVENT_H__
-#include <event.h>
+#include <event2/event.h>
#include "../hiredis.h"
#include "../async.h"
typedef struct redisLibeventEvents {
redisAsyncContext *context;
- struct event rev, wev;
+ struct event *rev, *wev;
} redisLibeventEvents;
static void redisLibeventReadEvent(int fd, short event, void *arg) {
@@ -53,28 +53,28 @@ static void redisLibeventWriteEvent(int fd, short event, void *arg) {
static void redisLibeventAddRead(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
- event_add(&e->rev,NULL);
+ event_add(e->rev,NULL);
}
static void redisLibeventDelRead(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
- event_del(&e->rev);
+ event_del(e->rev);
}
static void redisLibeventAddWrite(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
- event_add(&e->wev,NULL);
+ event_add(e->wev,NULL);
}
static void redisLibeventDelWrite(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
- event_del(&e->wev);
+ event_del(e->wev);
}
static void redisLibeventCleanup(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
- event_del(&e->rev);
- event_del(&e->wev);
+ event_free(e->rev);
+ event_free(e->wev);
free(e);
}
@@ -99,10 +99,10 @@ static int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) {
ac->ev.data = e;
/* Initialize and install read/write events */
- event_set(&e->rev,c->fd,EV_READ,redisLibeventReadEvent,e);
- event_set(&e->wev,c->fd,EV_WRITE,redisLibeventWriteEvent,e);
- event_base_set(base,&e->rev);
- event_base_set(base,&e->wev);
+ e->rev = event_new(base, c->fd, EV_READ, redisLibeventReadEvent, e);
+ e->wev = event_new(base, c->fd, EV_WRITE, redisLibeventWriteEvent, e);
+ event_add(e->rev, NULL);
+ event_add(e->wev, NULL);
return REDIS_OK;
}
#endif
diff --git a/adapters/libuv.h b/adapters/libuv.h
index 3cdf3d3..ff08c25 100644
--- a/adapters/libuv.h
+++ b/adapters/libuv.h
@@ -20,10 +20,10 @@ static void redisLibuvPoll(uv_poll_t* handle, int status, int events) {
return;
}
- if (events & UV_READABLE) {
+ if (p->context != NULL && (events & UV_READABLE)) {
redisAsyncHandleRead(p->context);
}
- if (events & UV_WRITABLE) {
+ if (p->context != NULL && (events & UV_WRITABLE)) {
redisAsyncHandleWrite(p->context);
}
}
@@ -83,6 +83,7 @@ static void on_close(uv_handle_t* handle) {
static void redisLibuvCleanup(void *privdata) {
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
+ p->context = NULL; // indicate that context might no longer exist
uv_close((uv_handle_t*)&p->handle, on_close);
}
diff --git a/appveyor.yml b/appveyor.yml
index 06bbef1..819efbd 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,24 +1,13 @@
# Appveyor configuration file for CI build of hiredis on Windows (under Cygwin)
environment:
matrix:
- - CYG_ROOT: C:\cygwin64
- CYG_SETUP: setup-x86_64.exe
- CYG_MIRROR: http://cygwin.mirror.constant.com
- CYG_CACHE: C:\cygwin64\var\cache\setup
- CYG_BASH: C:\cygwin64\bin\bash
+ - CYG_BASH: C:\cygwin64\bin\bash
CC: gcc
- - CYG_ROOT: C:\cygwin
- CYG_SETUP: setup-x86.exe
- CYG_MIRROR: http://cygwin.mirror.constant.com
- CYG_CACHE: C:\cygwin\var\cache\setup
- CYG_BASH: C:\cygwin\bin\bash
+ - CYG_BASH: C:\cygwin\bin\bash
CC: gcc
TARGET: 32bit
TARGET_VARS: 32bit-vars
-# Cache Cygwin files to speed up build
-cache:
- - '%CYG_CACHE%'
clone_depth: 1
# Attempt to ensure we don't try to convert line endings to Win32 CRLF as this will cause build to fail
@@ -27,8 +16,6 @@ init:
# Install needed build dependencies
install:
- - ps: 'Start-FileDownload "http://cygwin.com/$env:CYG_SETUP" -FileName "$env:CYG_SETUP"'
- - '%CYG_SETUP% --quiet-mode --no-shortcuts --only-site --root "%CYG_ROOT%" --site "%CYG_MIRROR%" --local-package-dir "%CYG_CACHE%" --packages automake,bison,gcc-core,libtool,make,gettext-devel,gettext,intltool,pkg-config,clang,llvm > NUL 2>&1'
- '%CYG_BASH% -lc "cygcheck -dc cygwin"'
build_script:
diff --git a/async.c b/async.c
index c27e012..cb5b841 100644
--- a/async.c
+++ b/async.c
@@ -336,7 +336,8 @@ static void __redisAsyncDisconnect(redisAsyncContext *ac) {
if (ac->err == 0) {
/* For clean disconnects, there should be no pending callbacks. */
- assert(__redisShiftCallback(&ac->replies,NULL) == REDIS_ERR);
+ int ret = __redisShiftCallback(&ac->replies,NULL);
+ assert(ret == REDIS_ERR);
} else {
/* Disconnection is caused by an error, make sure that pending
* callbacks cannot call new commands. */
@@ -702,6 +703,8 @@ int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *priv
int len;
int status;
len = redisFormatSdsCommandArgv(&cmd,argc,argv,argvlen);
+ if (len < 0)
+ return REDIS_ERR;
status = __redisAsyncCommand(ac,fn,privdata,cmd,len);
sdsfree(cmd);
return status;
diff --git a/fmacros.h b/fmacros.h
index 14fed60..4cdbc13 100644
--- a/fmacros.h
+++ b/fmacros.h
@@ -10,16 +10,29 @@
#include <sys/cdefs.h>
#endif
-#if defined(__sun__)
-#define _POSIX_C_SOURCE 200112L
-#else
-#if !(defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__)
#define _XOPEN_SOURCE 600
+#elif defined(__APPLE__) && defined(__MACH__)
+#define _XOPEN_SOURCE
+#elif defined(__FreeBSD__)
+// intentionally left blank, don't define _XOPEN_SOURCE
+#elif defined(AIX)
+// intentionally left blank, don't define _XOPEN_SOURCE
+#else
+#define _XOPEN_SOURCE
#endif
+
+#if defined(__sun__)
+#define _POSIX_C_SOURCE 200112L
#endif
#if defined(__APPLE__) && defined(__MACH__)
#define _OSX
#endif
+#ifndef AIX
+# define _XOPEN_SOURCE_EXTENDED 1
+# define _ALL_SOURCE
+#endif
+
#endif
diff --git a/hiredis.c b/hiredis.c
index 18bdfc9..b344962 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -710,6 +710,8 @@ redisContext *redisConnectNonBlock(const char *ip, int port) {
redisContext *redisConnectBindNonBlock(const char *ip, int port,
const char *source_addr) {
redisContext *c = redisContextInit();
+ if (c == NULL)
+ return NULL;
c->flags &= ~REDIS_BLOCK;
redisContextConnectBindTcp(c,ip,port,NULL,source_addr);
return c;
@@ -718,6 +720,8 @@ redisContext *redisConnectBindNonBlock(const char *ip, int port,
redisContext *redisConnectBindNonBlockWithReuse(const char *ip, int port,
const char *source_addr) {
redisContext *c = redisContextInit();
+ if (c == NULL)
+ return NULL;
c->flags &= ~REDIS_BLOCK;
c->flags |= REDIS_REUSEADDR;
redisContextConnectBindTcp(c,ip,port,NULL,source_addr);
@@ -1007,9 +1011,8 @@ void *redisvCommand(redisContext *c, const char *format, va_list ap) {
void *redisCommand(redisContext *c, const char *format, ...) {
va_list ap;
- void *reply = NULL;
va_start(ap,format);
- reply = redisvCommand(c,format,ap);
+ void *reply = redisvCommand(c,format,ap);
va_end(ap);
return reply;
}
diff --git a/hiredis.h b/hiredis.h
index d2a6e90..77d5797 100644
--- a/hiredis.h
+++ b/hiredis.h
@@ -99,7 +99,7 @@
* need to copy the result into our private buffer. */ \
if (err_str != (buf)) { \
strncpy((buf), err_str, ((len) - 1)); \
- buf[(len)-1] = '\0'; \
+ (buf)[(len)-1] = '\0'; \
} \
} while (0)
#endif
@@ -133,7 +133,7 @@ void redisFreeSdsCommand(sds cmd);
enum redisConnectionType {
REDIS_CONN_TCP,
- REDIS_CONN_UNIX,
+ REDIS_CONN_UNIX
};
/* Context for a connection to Redis */
diff --git a/net.c b/net.c
index 7d41209..33d9a82 100644
--- a/net.c
+++ b/net.c
@@ -65,12 +65,13 @@ static void redisContextCloseFd(redisContext *c) {
}
static void __redisSetErrorFromErrno(redisContext *c, int type, const char *prefix) {
+ int errorno = errno; /* snprintf() may change errno */
char buf[128] = { 0 };
size_t len = 0;
if (prefix != NULL)
len = snprintf(buf,sizeof(buf),"%s: ",prefix);
- __redis_strerror_r(errno, (char *)(buf + len), sizeof(buf) - len);
+ __redis_strerror_r(errorno, (char *)(buf + len), sizeof(buf) - len);
__redisSetError(c,type,buf);
}
@@ -142,7 +143,6 @@ int redisKeepAlive(redisContext *c, int interval) {
}
#else
#if defined(__GLIBC__) && !defined(__FreeBSD_kernel__)
- val = interval;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) {
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
return REDIS_ERR;
@@ -356,6 +356,7 @@ addrretry:
n = 1;
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*) &n,
sizeof(n)) < 0) {
+ freeaddrinfo(bservinfo);
goto error;
}
}
diff --git a/net.h b/net.h
index 2f1a0bf..fc8ddd3 100644
--- a/net.h
+++ b/net.h
@@ -37,7 +37,7 @@
#include "hiredis.h"
-#if defined(__sun)
+#if defined(__sun) || defined(AIX)
#define AF_LOCAL AF_UNIX
#endif
diff --git a/read.c b/read.c
index 50333b5..061bbda 100644
--- a/read.c
+++ b/read.c
@@ -416,7 +416,7 @@ static int processItem(redisReader *r) {
redisReader *redisReaderCreateWithFunctions(redisReplyObjectFunctions *fn) {
redisReader *r;
- r = calloc(sizeof(redisReader),1);
+ r = calloc(1,sizeof(redisReader));
if (r == NULL)
return NULL;
diff --git a/sds.c b/sds.c
index b31ccf2..923ffd8 100644
--- a/sds.c
+++ b/sds.c
@@ -89,9 +89,9 @@ sds sdsnewlen(const void *init, size_t initlen) {
unsigned char *fp; /* flags pointer. */
sh = s_malloc(hdrlen+initlen+1);
+ if (sh == NULL) return NULL;
if (!init)
memset(sh, 0, hdrlen+initlen+1);
- if (sh == NULL) return NULL;
s = (char*)sh+hdrlen;
fp = ((unsigned char*)s)-1;
switch(type) {