1
0
mirror of https://github.com/fluencelabs/redis synced 2025-03-31 14:51:04 +00:00

fixed signedness and disambiguate variable names

This commit is contained in:
Pieter Noordhuis 2010-05-31 21:44:12 +02:00
parent 2796f6da7b
commit b6eb970394
3 changed files with 39 additions and 39 deletions

36
redis.c

@ -4788,16 +4788,16 @@ static robj *lPop(robj *subject, int where) {
robj *value = NULL; robj *value = NULL;
if (subject->encoding == REDIS_ENCODING_ZIPLIST) { if (subject->encoding == REDIS_ENCODING_ZIPLIST) {
unsigned char *p; unsigned char *p;
char *v; unsigned char *vstr;
unsigned int vlen; unsigned int vlen;
long long vval; long long vlong;
int pos = (where == REDIS_HEAD) ? 0 : -1; int pos = (where == REDIS_HEAD) ? 0 : -1;
p = ziplistIndex(subject->ptr,pos); p = ziplistIndex(subject->ptr,pos);
if (ziplistGet(p,&v,&vlen,&vval)) { if (ziplistGet(p,&vstr,&vlen,&vlong)) {
if (v) { if (vstr) {
value = createStringObject(v,vlen); value = createStringObject((char*)vstr,vlen);
} else { } else {
value = createStringObjectFromLongLong(vval); value = createStringObjectFromLongLong(vlong);
} }
/* We only need to delete an element when it exists */ /* We only need to delete an element when it exists */
subject->ptr = ziplistDelete(subject->ptr,&p); subject->ptr = ziplistDelete(subject->ptr,&p);
@ -4902,15 +4902,15 @@ static robj *lGet(lEntry *entry) {
lIterator *li = entry->li; lIterator *li = entry->li;
robj *value = NULL; robj *value = NULL;
if (li->encoding == REDIS_ENCODING_ZIPLIST) { if (li->encoding == REDIS_ENCODING_ZIPLIST) {
char *v; unsigned char *vstr;
unsigned int vlen; unsigned int vlen;
long long vval; long long vlong;
redisAssert(entry->zi != NULL); redisAssert(entry->zi != NULL);
if (ziplistGet(entry->zi,&v,&vlen,&vval)) { if (ziplistGet(entry->zi,&vstr,&vlen,&vlong)) {
if (v) { if (vstr) {
value = createStringObject(v,vlen); value = createStringObject((char*)vstr,vlen);
} else { } else {
value = createStringObjectFromLongLong(vval); value = createStringObjectFromLongLong(vlong);
} }
} }
} else if (li->encoding == REDIS_ENCODING_LIST) { } else if (li->encoding == REDIS_ENCODING_LIST) {
@ -5009,15 +5009,15 @@ static void lindexCommand(redisClient *c) {
if (o->encoding == REDIS_ENCODING_ZIPLIST) { if (o->encoding == REDIS_ENCODING_ZIPLIST) {
unsigned char *p; unsigned char *p;
char *v; unsigned char *vstr;
unsigned int vlen; unsigned int vlen;
long long vval; long long vlong;
p = ziplistIndex(o->ptr,index); p = ziplistIndex(o->ptr,index);
if (ziplistGet(p,&v,&vlen,&vval)) { if (ziplistGet(p,&vstr,&vlen,&vlong)) {
if (v) { if (vstr) {
value = createStringObject(v,vlen); value = createStringObject((char*)vstr,vlen);
} else { } else {
value = createStringObjectFromLongLong(vval); value = createStringObjectFromLongLong(vlong);
} }
addReplyBulk(c,value); addReplyBulk(c,value);
decrRefCount(value); decrRefCount(value);

@ -63,7 +63,7 @@ typedef struct zlentry {
} zlentry; } zlentry;
/* Return bytes needed to store integer encoded by 'encoding' */ /* Return bytes needed to store integer encoded by 'encoding' */
static unsigned int zipEncodingSize(char encoding) { static unsigned int zipEncodingSize(unsigned char encoding) {
if (encoding == ZIP_ENC_SHORT) { if (encoding == ZIP_ENC_SHORT) {
return sizeof(short int); return sizeof(short int);
} else if (encoding == ZIP_ENC_INT) { } else if (encoding == ZIP_ENC_INT) {
@ -173,12 +173,12 @@ static int zipPrevLenByteDiff(unsigned char *p, unsigned int len) {
/* Check if string pointed to by 'entry' can be encoded as an integer. /* Check if string pointed to by 'entry' can be encoded as an integer.
* Stores the integer value in 'v' and its encoding in 'encoding'. * Stores the integer value in 'v' and its encoding in 'encoding'.
* Warning: this function requires a NULL-terminated string! */ * Warning: this function requires a NULL-terminated string! */
static int zipTryEncoding(char *entry, long long *v, char *encoding) { static int zipTryEncoding(unsigned char *entry, long long *v, unsigned char *encoding) {
long long value; long long value;
char *eptr; char *eptr;
if (entry[0] == '-' || (entry[0] >= '0' && entry[0] <= '9')) { if (entry[0] == '-' || (entry[0] >= '0' && entry[0] <= '9')) {
value = strtoll(entry,&eptr,10); value = strtoll((char*)entry,&eptr,10);
if (eptr[0] != '\0') return 0; if (eptr[0] != '\0') return 0;
if (value >= SHRT_MIN && value <= SHRT_MAX) { if (value >= SHRT_MIN && value <= SHRT_MAX) {
*encoding = ZIP_ENC_SHORT; *encoding = ZIP_ENC_SHORT;
@ -194,7 +194,7 @@ static int zipTryEncoding(char *entry, long long *v, char *encoding) {
} }
/* Store integer 'value' at 'p', encoded as 'encoding' */ /* Store integer 'value' at 'p', encoded as 'encoding' */
static void zipSaveInteger(unsigned char *p, long long value, char encoding) { static void zipSaveInteger(unsigned char *p, long long value, unsigned char encoding) {
short int s; short int s;
int i; int i;
long long l; long long l;
@ -213,7 +213,7 @@ static void zipSaveInteger(unsigned char *p, long long value, char encoding) {
} }
/* Read integer encoded as 'encoding' from 'p' */ /* Read integer encoded as 'encoding' from 'p' */
static long long zipLoadInteger(unsigned char *p, char encoding) { static long long zipLoadInteger(unsigned char *p, unsigned char encoding) {
short int s; short int s;
int i; int i;
long long l, ret; long long l, ret;
@ -269,7 +269,7 @@ static unsigned char *ziplistResize(unsigned char *zl, unsigned int len) {
} }
/* Delete "num" entries, starting at "p". Returns pointer to the ziplist. */ /* Delete "num" entries, starting at "p". Returns pointer to the ziplist. */
static unsigned char *__ziplistDelete(unsigned char *zl, unsigned char *p, int num) { static unsigned char *__ziplistDelete(unsigned char *zl, unsigned char *p, unsigned int num) {
unsigned int i, totlen, deleted = 0; unsigned int i, totlen, deleted = 0;
int nextdiff = 0; int nextdiff = 0;
zlentry first = zipEntry(p); zlentry first = zipEntry(p);
@ -306,11 +306,11 @@ static unsigned char *__ziplistDelete(unsigned char *zl, unsigned char *p, int n
} }
/* Insert item at "p". */ /* Insert item at "p". */
static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, char *s, unsigned int slen) { static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, unsigned char *s, unsigned int slen) {
unsigned int curlen = ZIPLIST_BYTES(zl), reqlen, prevlen = 0; unsigned int curlen = ZIPLIST_BYTES(zl), reqlen, prevlen = 0;
unsigned int offset, nextdiff = 0; unsigned int offset, nextdiff = 0;
unsigned char *tail; unsigned char *tail;
char encoding = ZIP_ENC_RAW; unsigned char encoding = ZIP_ENC_RAW;
long long value; long long value;
zlentry entry; zlentry entry;
@ -372,7 +372,7 @@ static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, char
return zl; return zl;
} }
unsigned char *ziplistPush(unsigned char *zl, char *s, unsigned int slen, int where) { unsigned char *ziplistPush(unsigned char *zl, unsigned char *s, unsigned int slen, int where) {
unsigned char *p; unsigned char *p;
p = (where == ZIPLIST_HEAD) ? ZIPLIST_ENTRY_HEAD(zl) : ZIPLIST_ENTRY_END(zl); p = (where == ZIPLIST_HEAD) ? ZIPLIST_ENTRY_HEAD(zl) : ZIPLIST_ENTRY_END(zl);
return __ziplistInsert(zl,p,s,slen); return __ziplistInsert(zl,p,s,slen);
@ -455,7 +455,7 @@ unsigned char *ziplistPrev(unsigned char *zl, unsigned char *p) {
* on the encoding of the entry. 'e' is always set to NULL to be able * on the encoding of the entry. 'e' is always set to NULL to be able
* to find out whether the string pointer or the integer value was set. * to find out whether the string pointer or the integer value was set.
* Return 0 if 'p' points to the end of the zipmap, 1 otherwise. */ * Return 0 if 'p' points to the end of the zipmap, 1 otherwise. */
unsigned int ziplistGet(unsigned char *p, char **sstr, unsigned int *slen, long long *sval) { unsigned int ziplistGet(unsigned char *p, unsigned char **sstr, unsigned int *slen, long long *sval) {
zlentry entry; zlentry entry;
if (p == NULL || p[0] == ZIP_END) return 0; if (p == NULL || p[0] == ZIP_END) return 0;
if (sstr) *sstr = NULL; if (sstr) *sstr = NULL;
@ -464,7 +464,7 @@ unsigned int ziplistGet(unsigned char *p, char **sstr, unsigned int *slen, long
if (entry.encoding == ZIP_ENC_RAW) { if (entry.encoding == ZIP_ENC_RAW) {
if (sstr) { if (sstr) {
*slen = entry.len; *slen = entry.len;
*sstr = (char*)p+entry.headersize; *sstr = p+entry.headersize;
} }
} else { } else {
if (sval) { if (sval) {
@ -475,7 +475,7 @@ unsigned int ziplistGet(unsigned char *p, char **sstr, unsigned int *slen, long
} }
/* Insert an entry at "p". */ /* Insert an entry at "p". */
unsigned char *ziplistInsert(unsigned char *zl, unsigned char *p, char *s, unsigned int slen) { unsigned char *ziplistInsert(unsigned char *zl, unsigned char *p, unsigned char *s, unsigned int slen) {
return __ziplistInsert(zl,p,s,slen); return __ziplistInsert(zl,p,s,slen);
} }
@ -501,10 +501,10 @@ unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigne
} }
/* Compare entry pointer to by 'p' with 'entry'. Return 1 if equal. */ /* Compare entry pointer to by 'p' with 'entry'. Return 1 if equal. */
unsigned int ziplistCompare(unsigned char *p, char *sstr, unsigned int slen) { unsigned int ziplistCompare(unsigned char *p, unsigned char *sstr, unsigned int slen) {
zlentry entry; zlentry entry;
char sencoding; unsigned char sencoding;
long long val, sval; long long zval, sval;
if (p[0] == ZIP_END) return 0; if (p[0] == ZIP_END) return 0;
entry = zipEntry(p); entry = zipEntry(p);
@ -519,8 +519,8 @@ unsigned int ziplistCompare(unsigned char *p, char *sstr, unsigned int slen) {
/* Try to compare encoded values */ /* Try to compare encoded values */
if (zipTryEncoding(sstr,&sval,&sencoding)) { if (zipTryEncoding(sstr,&sval,&sencoding)) {
if (entry.encoding == sencoding) { if (entry.encoding == sencoding) {
val = zipLoadInteger(p+entry.headersize,entry.encoding); zval = zipLoadInteger(p+entry.headersize,entry.encoding);
return val == sval; return zval == sval;
} }
} }
} }

@ -2,15 +2,15 @@
#define ZIPLIST_TAIL 1 #define ZIPLIST_TAIL 1
unsigned char *ziplistNew(void); unsigned char *ziplistNew(void);
unsigned char *ziplistPush(unsigned char *zl, char *s, unsigned int slen, int where); unsigned char *ziplistPush(unsigned char *zl, unsigned char *s, unsigned int slen, int where);
unsigned char *ziplistPop(unsigned char *zl, sds *target, int where); unsigned char *ziplistPop(unsigned char *zl, sds *target, int where);
unsigned char *ziplistIndex(unsigned char *zl, int index); unsigned char *ziplistIndex(unsigned char *zl, int index);
unsigned char *ziplistNext(unsigned char *zl, unsigned char *p); unsigned char *ziplistNext(unsigned char *zl, unsigned char *p);
unsigned char *ziplistPrev(unsigned char *zl, unsigned char *p); unsigned char *ziplistPrev(unsigned char *zl, unsigned char *p);
unsigned int ziplistGet(unsigned char *p, char **sstr, unsigned int *slen, long long *sval); unsigned int ziplistGet(unsigned char *p, unsigned char **sval, unsigned int *slen, long long *lval);
unsigned char *ziplistInsert(unsigned char *zl, unsigned char *p, char *s, unsigned int slen); unsigned char *ziplistInsert(unsigned char *zl, unsigned char *p, unsigned char *s, unsigned int slen);
unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p); unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p);
unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigned int num); unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigned int num);
unsigned int ziplistCompare(unsigned char *p, char *entry, unsigned int elen); unsigned int ziplistCompare(unsigned char *p, unsigned char *s, unsigned int slen);
unsigned int ziplistLen(unsigned char *zl); unsigned int ziplistLen(unsigned char *zl);
unsigned int ziplistSize(unsigned char *zl); unsigned int ziplistSize(unsigned char *zl);