From: antirez Date: Fri, 27 Mar 2009 19:48:32 +0000 (+0100) Subject: ANSI-C compatibility changes X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/a4d1ba9a73e459d68423c4da623f8cf1663c70ba ANSI-C compatibility changes --- diff --git a/anet.c b/anet.c index bcb99057..d58e85b6 100644 --- a/anet.c +++ b/anet.c @@ -177,7 +177,7 @@ int anetTcpNonBlockConnect(char *err, char *addr, int port) /* Like read(2) but make sure 'count' is read before to return * (unless error or EOF condition is encountered) */ -int anetRead(int fd, void *buf, int count) +int anetRead(int fd, char *buf, int count) { int nread, totlen = 0; while(totlen != count) { @@ -192,7 +192,7 @@ int anetRead(int fd, void *buf, int count) /* Like write(2) but make sure 'count' is read before to return * (unless error is encountered) */ -int anetWrite(int fd, void *buf, int count) +int anetWrite(int fd, char *buf, int count) { int nwritten, totlen = 0; while(totlen != count) { diff --git a/anet.h b/anet.h index c43405d9..b1e9a567 100644 --- a/anet.h +++ b/anet.h @@ -37,11 +37,11 @@ int anetTcpConnect(char *err, char *addr, int port); int anetTcpNonBlockConnect(char *err, char *addr, int port); -int anetRead(int fd, void *buf, int count); +int anetRead(int fd, char *buf, int count); int anetResolve(char *err, char *host, char *ipbuf); int anetTcpServer(char *err, int port, char *bindaddr); int anetAccept(char *err, int serversock, char *ip, int *port); -int anetWrite(int fd, void *buf, int count); +int anetWrite(int fd, char *buf, int count); int anetNonBlock(char *err, int fd); int anetTcpNoDelay(char *err, int fd); int anetTcpKeepAlive(char *err, int fd); diff --git a/redis.c b/redis.c index fb18e090..cf3d6675 100644 --- a/redis.c +++ b/redis.c @@ -95,7 +95,9 @@ * 00|000000 => if the two MSB are 00 the len is the 6 bits of this byte * 01|000000 00000000 => 01, the len is 14 byes, 6 bits + 8 bits of next byte * 10|000000 [32 bit integer] => if it's 01, a full 32 bit len will follow - * 11|000000 reserved for future uses + * 11|000000 this means: specially encoded object will follow. The six bits + * number specify the kind of object that follows. + * See the REDIS_RDB_ENC_* defines. * * Lenghts up to 63 are stored using a single byte, most DB keys, and may * values, will fit inside. */ @@ -105,6 +107,14 @@ #define REDIS_RDB_64BITLEN 3 #define REDIS_RDB_LENERR UINT_MAX +/* When a length of a string object stored on disk has the first two bits + * set, the remaining two bits specify a special encoding for the object + * accordingly to the following defines: */ +#define REDIS_RDB_ENC_INT8 0 /* 8 bit signed integer */ +#define REDIS_RDB_ENC_INT16 1 /* 16 bit signed integer */ +#define REDIS_RDB_ENC_INT32 2 /* 32 bit signed integer */ +#define REDIS_RDB_ENC_FLZ 3 /* string compressed with FASTLZ */ + /* Client flags */ #define REDIS_CLOSE 1 /* This client connection should be closed ASAP */ #define REDIS_SLAVE 2 /* This client is a slave server */ @@ -620,7 +630,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { used = dictGetHashTableUsed(server.dict[j]); if (!(loops % 5) && used > 0) { redisLog(REDIS_DEBUG,"DB %d: %d keys in %d slots HT.",j,used,size); - // dictPrintStats(server.dict); + /* dictPrintStats(server.dict); */ } if (size && used && size > REDIS_HT_MINSLOTS && (used*100/size < REDIS_HT_MINFILL)) { @@ -1027,7 +1037,7 @@ static void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) if (c->flags & REDIS_MASTER) { nwritten = objlen - c->sentlen; } else { - nwritten = write(fd, o->ptr+c->sentlen, objlen - c->sentlen); + nwritten = write(fd, ((char*)o->ptr)+c->sentlen, objlen - c->sentlen); if (nwritten <= 0) break; } c->sentlen += nwritten; @@ -1822,11 +1832,11 @@ static void setGenericCommand(redisClient *c, int nx) { } static void setCommand(redisClient *c) { - return setGenericCommand(c,0); + setGenericCommand(c,0); } static void setnxCommand(redisClient *c) { - return setGenericCommand(c,1); + setGenericCommand(c,1); } static void getCommand(redisClient *c) { @@ -1907,21 +1917,21 @@ static void incrDecrCommand(redisClient *c, int incr) { } static void incrCommand(redisClient *c) { - return incrDecrCommand(c,1); + incrDecrCommand(c,1); } static void decrCommand(redisClient *c) { - return incrDecrCommand(c,-1); + incrDecrCommand(c,-1); } static void incrbyCommand(redisClient *c) { int incr = atoi(c->argv[2]->ptr); - return incrDecrCommand(c,incr); + incrDecrCommand(c,incr); } static void decrbyCommand(redisClient *c) { int incr = atoi(c->argv[2]->ptr); - return incrDecrCommand(c,-incr); + incrDecrCommand(c,-incr); } /* ========================= Type agnostic commands ========================= */ @@ -2439,8 +2449,9 @@ static void lremCommand(redisClient *c) { } ln = fromtail ? list->tail : list->head; while (ln) { - next = fromtail ? ln->prev : ln->next; robj *ele = listNodeValue(ln); + + next = fromtail ? ln->prev : ln->next; if (sdscmp(ele->ptr,c->argv[3]->ptr) == 0) { listDelNode(list,ln); server.dirty++; @@ -2696,7 +2707,7 @@ robj *lookupKeyByPattern(dict *dict, robj *pattern, robj *subst) { keyobj.ptr = ((char*)&keyname)+(sizeof(long)*2); de = dictFind(dict,&keyobj); - // printf("lookup '%s' => %p\n", keyname.buf,de); + /* printf("lookup '%s' => %p\n", keyname.buf,de); */ if (!de) return NULL; return dictGetEntryVal(de); } @@ -2986,7 +2997,7 @@ static int flushClientOutput(redisClient *c) { return REDIS_OK; } -static int syncWrite(int fd, void *ptr, ssize_t size, int timeout) { +static int syncWrite(int fd, char *ptr, ssize_t size, int timeout) { ssize_t nwritten, ret = size; time_t start = time(NULL); @@ -3006,7 +3017,7 @@ static int syncWrite(int fd, void *ptr, ssize_t size, int timeout) { return ret; } -static int syncRead(int fd, void *ptr, ssize_t size, int timeout) { +static int syncRead(int fd, char *ptr, ssize_t size, int timeout) { ssize_t nread, totread = 0; time_t start = time(NULL); diff --git a/sds.c b/sds.c index ca77a079..d2b7543e 100644 --- a/sds.c +++ b/sds.c @@ -278,8 +278,10 @@ sds *sdssplitlen(char *s, int len, char *sep, int seplen, int *count) { for (j = 0; j < (len-(seplen-1)); j++) { /* make sure there is room for the next element and the final one */ if (slots < elements+2) { + sds *newtokens; + slots *= 2; - sds *newtokens = zrealloc(tokens,sizeof(sds)*slots); + newtokens = zrealloc(tokens,sizeof(sds)*slots); if (newtokens == NULL) { #ifdef SDS_ABORT_ON_OOM sdsOomAbort(); diff --git a/zmalloc.c b/zmalloc.c index b5cb7d6a..92285659 100644 --- a/zmalloc.c +++ b/zmalloc.c @@ -38,7 +38,7 @@ void *zmalloc(size_t size) { *((size_t*)ptr) = size; used_memory += size+sizeof(size_t); - return ptr+sizeof(size_t); + return (char*)ptr+sizeof(size_t); } void *zrealloc(void *ptr, size_t size) { @@ -47,7 +47,7 @@ void *zrealloc(void *ptr, size_t size) { void *newptr; if (ptr == NULL) return zmalloc(size); - realptr = ptr-sizeof(size_t); + realptr = (char*)ptr-sizeof(size_t); oldsize = *((size_t*)realptr); newptr = realloc(realptr,size+sizeof(size_t)); if (!newptr) return NULL; @@ -55,7 +55,7 @@ void *zrealloc(void *ptr, size_t size) { *((size_t*)newptr) = size; used_memory -= oldsize; used_memory += size; - return newptr+sizeof(size_t); + return (char*)newptr+sizeof(size_t); } void zfree(void *ptr) { @@ -63,7 +63,7 @@ void zfree(void *ptr) { size_t oldsize; if (ptr == NULL) return; - realptr = ptr-sizeof(size_t); + realptr = (char*)ptr-sizeof(size_t); oldsize = *((size_t*)realptr); used_memory -= oldsize+sizeof(size_t); free(realptr);