mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
ANSI-C compatibility changes
This commit is contained in:
parent
29fac6170a
commit
a4d1ba9a73
4
anet.c
4
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
|
/* Like read(2) but make sure 'count' is read before to return
|
||||||
* (unless error or EOF condition is encountered) */
|
* (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;
|
int nread, totlen = 0;
|
||||||
while(totlen != count) {
|
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
|
/* Like write(2) but make sure 'count' is read before to return
|
||||||
* (unless error is encountered) */
|
* (unless error is encountered) */
|
||||||
int anetWrite(int fd, void *buf, int count)
|
int anetWrite(int fd, char *buf, int count)
|
||||||
{
|
{
|
||||||
int nwritten, totlen = 0;
|
int nwritten, totlen = 0;
|
||||||
while(totlen != count) {
|
while(totlen != count) {
|
||||||
|
4
anet.h
4
anet.h
@ -37,11 +37,11 @@
|
|||||||
|
|
||||||
int anetTcpConnect(char *err, char *addr, int port);
|
int anetTcpConnect(char *err, char *addr, int port);
|
||||||
int anetTcpNonBlockConnect(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 anetResolve(char *err, char *host, char *ipbuf);
|
||||||
int anetTcpServer(char *err, int port, char *bindaddr);
|
int anetTcpServer(char *err, int port, char *bindaddr);
|
||||||
int anetAccept(char *err, int serversock, char *ip, int *port);
|
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 anetNonBlock(char *err, int fd);
|
||||||
int anetTcpNoDelay(char *err, int fd);
|
int anetTcpNoDelay(char *err, int fd);
|
||||||
int anetTcpKeepAlive(char *err, int fd);
|
int anetTcpKeepAlive(char *err, int fd);
|
||||||
|
37
redis.c
37
redis.c
@ -95,7 +95,9 @@
|
|||||||
* 00|000000 => if the two MSB are 00 the len is the 6 bits of this byte
|
* 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
|
* 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
|
* 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
|
* Lenghts up to 63 are stored using a single byte, most DB keys, and may
|
||||||
* values, will fit inside. */
|
* values, will fit inside. */
|
||||||
@ -105,6 +107,14 @@
|
|||||||
#define REDIS_RDB_64BITLEN 3
|
#define REDIS_RDB_64BITLEN 3
|
||||||
#define REDIS_RDB_LENERR UINT_MAX
|
#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 */
|
/* Client flags */
|
||||||
#define REDIS_CLOSE 1 /* This client connection should be closed ASAP */
|
#define REDIS_CLOSE 1 /* This client connection should be closed ASAP */
|
||||||
#define REDIS_SLAVE 2 /* This client is a slave server */
|
#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]);
|
used = dictGetHashTableUsed(server.dict[j]);
|
||||||
if (!(loops % 5) && used > 0) {
|
if (!(loops % 5) && used > 0) {
|
||||||
redisLog(REDIS_DEBUG,"DB %d: %d keys in %d slots HT.",j,used,size);
|
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 &&
|
if (size && used && size > REDIS_HT_MINSLOTS &&
|
||||||
(used*100/size < REDIS_HT_MINFILL)) {
|
(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) {
|
if (c->flags & REDIS_MASTER) {
|
||||||
nwritten = objlen - c->sentlen;
|
nwritten = objlen - c->sentlen;
|
||||||
} else {
|
} 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;
|
if (nwritten <= 0) break;
|
||||||
}
|
}
|
||||||
c->sentlen += nwritten;
|
c->sentlen += nwritten;
|
||||||
@ -1822,11 +1832,11 @@ static void setGenericCommand(redisClient *c, int nx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void setCommand(redisClient *c) {
|
static void setCommand(redisClient *c) {
|
||||||
return setGenericCommand(c,0);
|
setGenericCommand(c,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setnxCommand(redisClient *c) {
|
static void setnxCommand(redisClient *c) {
|
||||||
return setGenericCommand(c,1);
|
setGenericCommand(c,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getCommand(redisClient *c) {
|
static void getCommand(redisClient *c) {
|
||||||
@ -1907,21 +1917,21 @@ static void incrDecrCommand(redisClient *c, int incr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void incrCommand(redisClient *c) {
|
static void incrCommand(redisClient *c) {
|
||||||
return incrDecrCommand(c,1);
|
incrDecrCommand(c,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decrCommand(redisClient *c) {
|
static void decrCommand(redisClient *c) {
|
||||||
return incrDecrCommand(c,-1);
|
incrDecrCommand(c,-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void incrbyCommand(redisClient *c) {
|
static void incrbyCommand(redisClient *c) {
|
||||||
int incr = atoi(c->argv[2]->ptr);
|
int incr = atoi(c->argv[2]->ptr);
|
||||||
return incrDecrCommand(c,incr);
|
incrDecrCommand(c,incr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decrbyCommand(redisClient *c) {
|
static void decrbyCommand(redisClient *c) {
|
||||||
int incr = atoi(c->argv[2]->ptr);
|
int incr = atoi(c->argv[2]->ptr);
|
||||||
return incrDecrCommand(c,-incr);
|
incrDecrCommand(c,-incr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================= Type agnostic commands ========================= */
|
/* ========================= Type agnostic commands ========================= */
|
||||||
@ -2439,8 +2449,9 @@ static void lremCommand(redisClient *c) {
|
|||||||
}
|
}
|
||||||
ln = fromtail ? list->tail : list->head;
|
ln = fromtail ? list->tail : list->head;
|
||||||
while (ln) {
|
while (ln) {
|
||||||
next = fromtail ? ln->prev : ln->next;
|
|
||||||
robj *ele = listNodeValue(ln);
|
robj *ele = listNodeValue(ln);
|
||||||
|
|
||||||
|
next = fromtail ? ln->prev : ln->next;
|
||||||
if (sdscmp(ele->ptr,c->argv[3]->ptr) == 0) {
|
if (sdscmp(ele->ptr,c->argv[3]->ptr) == 0) {
|
||||||
listDelNode(list,ln);
|
listDelNode(list,ln);
|
||||||
server.dirty++;
|
server.dirty++;
|
||||||
@ -2696,7 +2707,7 @@ robj *lookupKeyByPattern(dict *dict, robj *pattern, robj *subst) {
|
|||||||
keyobj.ptr = ((char*)&keyname)+(sizeof(long)*2);
|
keyobj.ptr = ((char*)&keyname)+(sizeof(long)*2);
|
||||||
|
|
||||||
de = dictFind(dict,&keyobj);
|
de = dictFind(dict,&keyobj);
|
||||||
// printf("lookup '%s' => %p\n", keyname.buf,de);
|
/* printf("lookup '%s' => %p\n", keyname.buf,de); */
|
||||||
if (!de) return NULL;
|
if (!de) return NULL;
|
||||||
return dictGetEntryVal(de);
|
return dictGetEntryVal(de);
|
||||||
}
|
}
|
||||||
@ -2986,7 +2997,7 @@ static int flushClientOutput(redisClient *c) {
|
|||||||
return REDIS_OK;
|
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;
|
ssize_t nwritten, ret = size;
|
||||||
time_t start = time(NULL);
|
time_t start = time(NULL);
|
||||||
|
|
||||||
@ -3006,7 +3017,7 @@ static int syncWrite(int fd, void *ptr, ssize_t size, int timeout) {
|
|||||||
return ret;
|
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;
|
ssize_t nread, totread = 0;
|
||||||
time_t start = time(NULL);
|
time_t start = time(NULL);
|
||||||
|
|
||||||
|
4
sds.c
4
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++) {
|
for (j = 0; j < (len-(seplen-1)); j++) {
|
||||||
/* make sure there is room for the next element and the final one */
|
/* make sure there is room for the next element and the final one */
|
||||||
if (slots < elements+2) {
|
if (slots < elements+2) {
|
||||||
|
sds *newtokens;
|
||||||
|
|
||||||
slots *= 2;
|
slots *= 2;
|
||||||
sds *newtokens = zrealloc(tokens,sizeof(sds)*slots);
|
newtokens = zrealloc(tokens,sizeof(sds)*slots);
|
||||||
if (newtokens == NULL) {
|
if (newtokens == NULL) {
|
||||||
#ifdef SDS_ABORT_ON_OOM
|
#ifdef SDS_ABORT_ON_OOM
|
||||||
sdsOomAbort();
|
sdsOomAbort();
|
||||||
|
@ -38,7 +38,7 @@ void *zmalloc(size_t size) {
|
|||||||
|
|
||||||
*((size_t*)ptr) = size;
|
*((size_t*)ptr) = size;
|
||||||
used_memory += size+sizeof(size_t);
|
used_memory += size+sizeof(size_t);
|
||||||
return ptr+sizeof(size_t);
|
return (char*)ptr+sizeof(size_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *zrealloc(void *ptr, size_t size) {
|
void *zrealloc(void *ptr, size_t size) {
|
||||||
@ -47,7 +47,7 @@ void *zrealloc(void *ptr, size_t size) {
|
|||||||
void *newptr;
|
void *newptr;
|
||||||
|
|
||||||
if (ptr == NULL) return zmalloc(size);
|
if (ptr == NULL) return zmalloc(size);
|
||||||
realptr = ptr-sizeof(size_t);
|
realptr = (char*)ptr-sizeof(size_t);
|
||||||
oldsize = *((size_t*)realptr);
|
oldsize = *((size_t*)realptr);
|
||||||
newptr = realloc(realptr,size+sizeof(size_t));
|
newptr = realloc(realptr,size+sizeof(size_t));
|
||||||
if (!newptr) return NULL;
|
if (!newptr) return NULL;
|
||||||
@ -55,7 +55,7 @@ void *zrealloc(void *ptr, size_t size) {
|
|||||||
*((size_t*)newptr) = size;
|
*((size_t*)newptr) = size;
|
||||||
used_memory -= oldsize;
|
used_memory -= oldsize;
|
||||||
used_memory += size;
|
used_memory += size;
|
||||||
return newptr+sizeof(size_t);
|
return (char*)newptr+sizeof(size_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void zfree(void *ptr) {
|
void zfree(void *ptr) {
|
||||||
@ -63,7 +63,7 @@ void zfree(void *ptr) {
|
|||||||
size_t oldsize;
|
size_t oldsize;
|
||||||
|
|
||||||
if (ptr == NULL) return;
|
if (ptr == NULL) return;
|
||||||
realptr = ptr-sizeof(size_t);
|
realptr = (char*)ptr-sizeof(size_t);
|
||||||
oldsize = *((size_t*)realptr);
|
oldsize = *((size_t*)realptr);
|
||||||
used_memory -= oldsize+sizeof(size_t);
|
used_memory -= oldsize+sizeof(size_t);
|
||||||
free(realptr);
|
free(realptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user