From a2b2d88f384c4ad3e812cceccd4720a9c650207c Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 6 Dec 2018 11:23:23 +0100 Subject: RESP3: hiredis: initial double implementation. --- deps/hiredis/.travis.yml | 6 ++++++ deps/hiredis/hiredis.c | 21 +++++++++++++++++++++ deps/hiredis/hiredis.h | 1 + deps/hiredis/read.c | 36 +++++++++++++++++++++++++++++++++++- deps/hiredis/read.h | 1 + 5 files changed, 64 insertions(+), 1 deletion(-) (limited to 'deps/hiredis') diff --git a/deps/hiredis/.travis.yml b/deps/hiredis/.travis.yml index ad08076d8..faf2ce684 100644 --- a/deps/hiredis/.travis.yml +++ b/deps/hiredis/.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/deps/hiredis/hiredis.c b/deps/hiredis/hiredis.c index 42d0f8dd1..13b961871 100644 --- a/deps/hiredis/hiredis.c +++ b/deps/hiredis/hiredis.c @@ -47,6 +47,7 @@ static redisReply *createReplyObject(int type); static void *createStringObject(const redisReadTask *task, char *str, size_t len); static void *createArrayObject(const redisReadTask *task, int elements); static void *createIntegerObject(const redisReadTask *task, long long value); +static void *createDoubleObject(const redisReadTask *task, double value); static void *createNilObject(const redisReadTask *task); /* Default set of functions to build the reply. Keep in mind that such a @@ -55,6 +56,7 @@ static redisReplyObjectFunctions defaultFunctions = { createStringObject, createArrayObject, createIntegerObject, + createDoubleObject, createNilObject, freeReplyObject }; @@ -179,6 +181,25 @@ static void *createIntegerObject(const redisReadTask *task, long long value) { return r; } +static void *createDoubleObject(const redisReadTask *task, double value) { + redisReply *r, *parent; + + r = createReplyObject(REDIS_REPLY_DOUBLE); + if (r == NULL) + return NULL; + + r->dval = value; + + if (task->parent) { + parent = task->parent->obj; + assert(parent->type == REDIS_REPLY_ARRAY || + parent->type == REDIS_REPLY_MAP || + parent->type == REDIS_REPLY_SET); + parent->element[task->idx] = r; + } + return r; +} + static void *createNilObject(const redisReadTask *task) { redisReply *r, *parent; diff --git a/deps/hiredis/hiredis.h b/deps/hiredis/hiredis.h index 1b0d5e659..40719fe2d 100644 --- a/deps/hiredis/hiredis.h +++ b/deps/hiredis/hiredis.h @@ -88,6 +88,7 @@ extern "C" { typedef struct redisReply { int type; /* REDIS_REPLY_* */ long long integer; /* The integer when type is REDIS_REPLY_INTEGER */ + double dval; /* The double when type is REDIS_REPLY_DOUBLE */ size_t len; /* Length of string */ char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */ size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */ diff --git a/deps/hiredis/read.c b/deps/hiredis/read.c index 221438883..d6a479741 100644 --- a/deps/hiredis/read.c +++ b/deps/hiredis/read.c @@ -29,7 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ - #include "fmacros.h" #include #include @@ -40,6 +39,7 @@ #include #include #include +#include #include "read.h" #include "sds.h" @@ -278,6 +278,36 @@ static int processLineItem(redisReader *r) { } else { obj = (void*)REDIS_REPLY_INTEGER; } + } else if (cur->type == REDIS_REPLY_DOUBLE) { + if (r->fn && r->fn->createDouble) { + char buf[326], *eptr; + double d; + + if ((size_t)len-1 >= sizeof(buf)) { + __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + "Double value is too large"); + return REDIS_ERR; + } + + memcpy(buf,p+1,len-1); + buf[len-1] = '\0'; + + if (strcasecmp(buf,",inf") == 0) { + d = 1.0/0.0; /* Positive infinite. */ + } else if (strcasecmp(buf,",-inf") == 0) { + d = -1.0/0.0; /* Nevative infinite. */ + } else { + d = strtod((char*)buf,&eptr); + if (eptr[0] != '\0' || isnan(d)) { + __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + "Bad double value"); + return REDIS_ERR; + } + } + obj = r->fn->createDouble(cur,d); + } else { + obj = (void*)REDIS_REPLY_DOUBLE; + } } else { /* Type will be error or status. */ if (r->fn && r->fn->createString) @@ -460,6 +490,9 @@ static int processItem(redisReader *r) { case ':': cur->type = REDIS_REPLY_INTEGER; break; + case ',': + cur->type = REDIS_REPLY_DOUBLE; + break; case '$': cur->type = REDIS_REPLY_STRING; break; @@ -487,6 +520,7 @@ static int processItem(redisReader *r) { case REDIS_REPLY_ERROR: case REDIS_REPLY_STATUS: case REDIS_REPLY_INTEGER: + case REDIS_REPLY_DOUBLE: return processLineItem(r); case REDIS_REPLY_STRING: return processBulkItem(r); diff --git a/deps/hiredis/read.h b/deps/hiredis/read.h index 84ee15cb6..e7c4bd308 100644 --- a/deps/hiredis/read.h +++ b/deps/hiredis/read.h @@ -81,6 +81,7 @@ typedef struct redisReplyObjectFunctions { void *(*createString)(const redisReadTask*, char*, size_t); void *(*createArray)(const redisReadTask*, int); void *(*createInteger)(const redisReadTask*, long long); + void *(*createDouble)(const redisReadTask*, double); void *(*createNil)(const redisReadTask*); void (*freeObject)(void*); } redisReplyObjectFunctions; -- cgit v1.2.1