Skip to content

Commit

Permalink
replaced redisAssert() with redisAssertWithInfo() in a shitload of pl…
Browse files Browse the repository at this point in the history
…aces.
  • Loading branch information
antirez committed Oct 4, 2011
1 parent bab205f commit eab0e26
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 85 deletions.
30 changes: 15 additions & 15 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ void clusterCommand(redisClient *c) {

retval = del ? clusterDelSlot(j) :
clusterAddSlot(server.cluster.myself,j);
redisAssert(retval == REDIS_OK);
redisAssertWithInfo(c,NULL,retval == REDIS_OK);
}
}
zfree(slots);
Expand Down Expand Up @@ -1462,23 +1462,23 @@ void migrateCommand(redisClient *c) {
}

rioInitWithBuffer(&cmd,sdsempty());
redisAssert(rioWriteBulkCount(&cmd,'*',2));
redisAssert(rioWriteBulkString(&cmd,"SELECT",6));
redisAssert(rioWriteBulkLongLong(&cmd,dbid));
redisAssertWithInfo(c,NULL,rioWriteBulkCount(&cmd,'*',2));
redisAssertWithInfo(c,NULL,rioWriteBulkString(&cmd,"SELECT",6));
redisAssertWithInfo(c,NULL,rioWriteBulkLongLong(&cmd,dbid));

ttl = getExpire(c->db,c->argv[3]);
redisAssert(rioWriteBulkCount(&cmd,'*',4));
redisAssert(rioWriteBulkString(&cmd,"RESTORE",7));
redisAssert(c->argv[3]->encoding == REDIS_ENCODING_RAW);
redisAssert(rioWriteBulkString(&cmd,c->argv[3]->ptr,sdslen(c->argv[3]->ptr)));
redisAssert(rioWriteBulkLongLong(&cmd,(ttl == -1) ? 0 : ttl));
redisAssertWithInfo(c,NULL,rioWriteBulkCount(&cmd,'*',4));
redisAssertWithInfo(c,NULL,rioWriteBulkString(&cmd,"RESTORE",7));
redisAssertWithInfo(c,NULL,c->argv[3]->encoding == REDIS_ENCODING_RAW);
redisAssertWithInfo(c,NULL,rioWriteBulkString(&cmd,c->argv[3]->ptr,sdslen(c->argv[3]->ptr)));
redisAssertWithInfo(c,NULL,rioWriteBulkLongLong(&cmd,(ttl == -1) ? 0 : ttl));

/* Finally the last argument that is the serailized object payload
* in the form: <type><rdb-serialized-object>. */
rioInitWithBuffer(&payload,sdsempty());
redisAssert(rdbSaveObjectType(&payload,o));
redisAssert(rdbSaveObject(&payload,o) != -1);
redisAssert(rioWriteBulkString(&cmd,payload.io.buffer.ptr,sdslen(payload.io.buffer.ptr)));
redisAssertWithInfo(c,NULL,rdbSaveObjectType(&payload,o));
redisAssertWithInfo(c,NULL,rdbSaveObject(&payload,o) != -1);
redisAssertWithInfo(c,NULL,rioWriteBulkString(&cmd,payload.io.buffer.ptr,sdslen(payload.io.buffer.ptr)));
sdsfree(payload.io.buffer.ptr);

/* Tranfer the query to the other node in 64K chunks. */
Expand Down Expand Up @@ -1561,8 +1561,8 @@ void dumpCommand(redisClient *c) {
/* Serialize the object in a RDB-like format. It consist of an object type
* byte followed by the serialized object. This is understood by RESTORE. */
rioInitWithBuffer(&payload,sdsempty());
redisAssert(rdbSaveObjectType(&payload,o));
redisAssert(rdbSaveObject(&payload,o));
redisAssertWithInfo(c,NULL,rdbSaveObjectType(&payload,o));
redisAssertWithInfo(c,NULL,rdbSaveObject(&payload,o));

/* Transfer to the client */
dumpobj = createObject(REDIS_STRING,payload.io.buffer.ptr);
Expand Down Expand Up @@ -1632,7 +1632,7 @@ clusterNode *getNodeByQuery(redisClient *c, struct redisCommand *cmd, robj **arg

slot = keyHashSlot((char*)firstkey->ptr, sdslen(firstkey->ptr));
n = server.cluster.slots[slot];
redisAssert(n != NULL);
redisAssertWithInfo(c,firstkey,n != NULL);
} else {
/* If it is not the first key, make sure it is exactly
* the same key as the first we saw. */
Expand Down
6 changes: 3 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ void loadServerConfig(char *filename) {
void configSetCommand(redisClient *c) {
robj *o;
long long ll;
redisAssert(c->argv[2]->encoding == REDIS_ENCODING_RAW);
redisAssert(c->argv[3]->encoding == REDIS_ENCODING_RAW);
redisAssertWithInfo(c,c->argv[2],c->argv[2]->encoding == REDIS_ENCODING_RAW);
redisAssertWithInfo(c,c->argv[2],c->argv[3]->encoding == REDIS_ENCODING_RAW);
o = c->argv[3];

if (!strcasecmp(c->argv[2]->ptr,"dbfilename")) {
Expand Down Expand Up @@ -503,7 +503,7 @@ void configGetCommand(redisClient *c) {
char *pattern = o->ptr;
char buf[128];
int matches = 0;
redisAssert(o->encoding == REDIS_ENCODING_RAW);
redisAssertWithInfo(c,o,o->encoding == REDIS_ENCODING_RAW);

if (stringmatch(pattern,"dir",0)) {
char buf[1024];
Expand Down
12 changes: 6 additions & 6 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void dbAdd(redisDb *db, robj *key, robj *val) {
sds copy = sdsdup(key->ptr);
int retval = dictAdd(db->dict, copy, val);

redisAssert(retval == REDIS_OK);
redisAssertWithInfo(NULL,key,retval == REDIS_OK);
if (server.cluster_enabled) SlotToKeyAdd(key);
}

Expand All @@ -91,7 +91,7 @@ void dbAdd(redisDb *db, robj *key, robj *val) {
void dbOverwrite(redisDb *db, robj *key, robj *val) {
struct dictEntry *de = dictFind(db->dict,key->ptr);

redisAssert(de != NULL);
redisAssertWithInfo(NULL,key,de != NULL);
dictReplace(db->dict, key->ptr, val);
}

Expand Down Expand Up @@ -419,7 +419,7 @@ void moveCommand(redisClient *c) {
int removeExpire(redisDb *db, robj *key) {
/* An expire may only be removed if there is a corresponding entry in the
* main dict. Otherwise, the key will never be freed. */
redisAssert(dictFind(db->dict,key->ptr) != NULL);
redisAssertWithInfo(NULL,key,dictFind(db->dict,key->ptr) != NULL);
return dictDelete(db->expires,key->ptr) == DICT_OK;
}

Expand All @@ -428,7 +428,7 @@ void setExpire(redisDb *db, robj *key, time_t when) {

/* Reuse the sds from the main dict in the expire dict */
de = dictFind(db->dict,key->ptr);
redisAssert(de != NULL);
redisAssertWithInfo(NULL,key,de != NULL);
dictReplace(db->expires,dictGetEntryKey(de),(void*)when);
}

Expand All @@ -443,7 +443,7 @@ time_t getExpire(redisDb *db, robj *key) {

/* The entry was found in the expire dict, this means it should also
* be present in the main dict (safety check). */
redisAssert(dictFind(db->dict,key->ptr) != NULL);
redisAssertWithInfo(NULL,key,dictFind(db->dict,key->ptr) != NULL);
return (time_t) dictGetEntryVal(de);
}

Expand Down Expand Up @@ -525,7 +525,7 @@ void expireGenericCommand(redisClient *c, robj *key, robj *param, long offset) {
if (seconds <= 0 && !server.loading && !server.masterhost) {
robj *aux;

redisAssert(dbDelete(c->db,key));
redisAssertWithInfo(c,key,dbDelete(c->db,key));
server.dirty++;

/* Replicate/AOF this as an explicit DEL. */
Expand Down
2 changes: 1 addition & 1 deletion src/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void unwatchAllKeys(redisClient *c) {
* from the list */
wk = listNodeValue(ln);
clients = dictFetchValue(wk->db->watched_keys, wk->key);
redisAssert(clients != NULL);
redisAssertWithInfo(c,NULL,clients != NULL);
listDelNode(clients,listSearchKey(clients,c));
/* Kill the entry at all if this was the only client */
if (listLength(clients) == 0)
Expand Down
12 changes: 6 additions & 6 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ int processMultibulkBuffer(redisClient *c) {

if (c->multibulklen == 0) {
/* The client should have been reset */
redisAssert(c->argc == 0);
redisAssertWithInfo(c,NULL,c->argc == 0);

/* Multi bulk length cannot be read without a \r\n */
newline = strchr(c->querybuf,'\r');
Expand All @@ -716,7 +716,7 @@ int processMultibulkBuffer(redisClient *c) {

/* We know for sure there is a whole line since newline != NULL,
* so go ahead and find out the multi bulk length. */
redisAssert(c->querybuf[0] == '*');
redisAssertWithInfo(c,NULL,c->querybuf[0] == '*');
ok = string2ll(c->querybuf+1,newline-(c->querybuf+1),&ll);
if (!ok || ll > 1024*1024) {
addReplyError(c,"Protocol error: invalid multibulk length");
Expand All @@ -737,7 +737,7 @@ int processMultibulkBuffer(redisClient *c) {
c->argv = zmalloc(sizeof(robj*)*c->multibulklen);
}

redisAssert(c->multibulklen > 0);
redisAssertWithInfo(c,NULL,c->multibulklen > 0);
while(c->multibulklen) {
/* Read bulk length if unknown */
if (c->bulklen == -1) {
Expand Down Expand Up @@ -970,7 +970,7 @@ void rewriteClientCommandVector(redisClient *c, int argc, ...) {
c->argv = argv;
c->argc = argc;
c->cmd = lookupCommand(c->argv[0]->ptr);
redisAssert(c->cmd != NULL);
redisAssertWithInfo(c,NULL,c->cmd != NULL);
va_end(ap);
}

Expand All @@ -979,7 +979,7 @@ void rewriteClientCommandVector(redisClient *c, int argc, ...) {
void rewriteClientCommandArgument(redisClient *c, int i, robj *newval) {
robj *oldval;

redisAssert(i < c->argc);
redisAssertWithInfo(c,NULL,i < c->argc);
oldval = c->argv[i];
c->argv[i] = newval;
incrRefCount(newval);
Expand All @@ -988,6 +988,6 @@ void rewriteClientCommandArgument(redisClient *c, int i, robj *newval) {
/* If this is the command name make sure to fix c->cmd. */
if (i == 0) {
c->cmd = lookupCommand(c->argv[0]->ptr);
redisAssert(c->cmd != NULL);
redisAssertWithInfo(c,NULL,c->cmd != NULL);
}
}
14 changes: 7 additions & 7 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ robj *createStringObjectFromLongLong(long long value) {
}

robj *dupStringObject(robj *o) {
redisAssert(o->encoding == REDIS_ENCODING_RAW);
redisAssertWithInfo(NULL,o,o->encoding == REDIS_ENCODING_RAW);
return createStringObject(o->ptr,sdslen(o->ptr));
}

Expand Down Expand Up @@ -218,7 +218,7 @@ int checkType(redisClient *c, robj *o, int type) {
}

int isObjectRepresentableAsLongLong(robj *o, long long *llval) {
redisAssert(o->type == REDIS_STRING);
redisAssertWithInfo(NULL,o,o->type == REDIS_STRING);
if (o->encoding == REDIS_ENCODING_INT) {
if (llval) *llval = (long) o->ptr;
return REDIS_OK;
Expand All @@ -241,7 +241,7 @@ robj *tryObjectEncoding(robj *o) {
if (o->refcount > 1) return o;

/* Currently we try to encode only strings */
redisAssert(o->type == REDIS_STRING);
redisAssertWithInfo(NULL,o,o->type == REDIS_STRING);

/* Check if we can represent this string as a long integer */
if (!string2l(s,sdslen(s),&value)) return o;
Expand Down Expand Up @@ -296,7 +296,7 @@ robj *getDecodedObject(robj *o) {
* sdscmp() from sds.c will apply memcmp() so this function ca be considered
* binary safe. */
int compareStringObjects(robj *a, robj *b) {
redisAssert(a->type == REDIS_STRING && b->type == REDIS_STRING);
redisAssertWithInfo(NULL,a,a->type == REDIS_STRING && b->type == REDIS_STRING);
char bufa[128], bufb[128], *astr, *bstr;
int bothsds = 1;

Expand Down Expand Up @@ -331,7 +331,7 @@ int equalStringObjects(robj *a, robj *b) {
}

size_t stringObjectLen(robj *o) {
redisAssert(o->type == REDIS_STRING);
redisAssertWithInfo(NULL,o,o->type == REDIS_STRING);
if (o->encoding == REDIS_ENCODING_RAW) {
return sdslen(o->ptr);
} else {
Expand All @@ -348,7 +348,7 @@ int getDoubleFromObject(robj *o, double *target) {
if (o == NULL) {
value = 0;
} else {
redisAssert(o->type == REDIS_STRING);
redisAssertWithInfo(NULL,o,o->type == REDIS_STRING);
if (o->encoding == REDIS_ENCODING_RAW) {
value = strtod(o->ptr, &eptr);
if (eptr[0] != '\0' || isnan(value)) return REDIS_ERR;
Expand Down Expand Up @@ -385,7 +385,7 @@ int getLongLongFromObject(robj *o, long long *target) {
if (o == NULL) {
value = 0;
} else {
redisAssert(o->type == REDIS_STRING);
redisAssertWithInfo(NULL,o,o->type == REDIS_STRING);
if (o->encoding == REDIS_ENCODING_RAW) {
value = strtoll(o->ptr, &eptr, 10);
if (eptr[0] != '\0') return REDIS_ERR;
Expand Down
4 changes: 2 additions & 2 deletions src/pubsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ int pubsubUnsubscribeChannel(redisClient *c, robj *channel, int notify) {
retval = 1;
/* Remove the client from the channel -> clients list hash table */
de = dictFind(server.pubsub_channels,channel);
redisAssert(de != NULL);
redisAssertWithInfo(c,NULL,de != NULL);
clients = dictGetEntryVal(de);
ln = listSearchKey(clients,c);
redisAssert(ln != NULL);
redisAssertWithInfo(c,NULL,ln != NULL);
listDelNode(clients,ln);
if (listLength(clients) == 0) {
/* Free the list and associated hash entry at all if this was
Expand Down
4 changes: 2 additions & 2 deletions src/rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ int rdbSaveStringObject(rio *rdb, robj *obj) {
if (obj->encoding == REDIS_ENCODING_INT) {
return rdbSaveLongLongAsStringObject(rdb,(long)obj->ptr);
} else {
redisAssert(obj->encoding == REDIS_ENCODING_RAW);
redisAssertWithInfo(NULL,obj,obj->encoding == REDIS_ENCODING_RAW);
return rdbSaveRawString(rdb,obj->ptr,sdslen(obj->ptr));
}
}
Expand Down Expand Up @@ -553,7 +553,7 @@ int rdbSaveObject(rio *rdb, robj *o) {
* we could switch to a faster solution. */
off_t rdbSavedObjectLen(robj *o) {
int len = rdbSaveObject(NULL,o);
redisAssert(len != -1);
redisAssertWithInfo(NULL,o,len != -1);
return len;
}

Expand Down
4 changes: 2 additions & 2 deletions src/scripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ void evalGenericCommand(redisClient *c, int evalsha) {
{
int retval = dictAdd(server.lua_scripts,
sdsnewlen(funcname+2,40),c->argv[1]);
redisAssert(retval == DICT_OK);
redisAssertWithInfo(c,NULL,retval == DICT_OK);
incrRefCount(c->argv[1]);
}
}
Expand Down Expand Up @@ -583,7 +583,7 @@ void evalGenericCommand(redisClient *c, int evalsha) {
if (evalsha) {
robj *script = dictFetchValue(server.lua_scripts,c->argv[1]->ptr);

redisAssert(script != NULL);
redisAssertWithInfo(c,NULL,script != NULL);
rewriteClientCommandArgument(c,0,
resetRefCount(createStringObject("EVAL",4)));
rewriteClientCommandArgument(c,1,script);
Expand Down
11 changes: 6 additions & 5 deletions src/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void sortCommand(redisClient *c) {
} else {
redisPanic("Unknown type");
}
redisAssert(j == vectorlen);
redisAssertWithInfo(c,sortval,j == vectorlen);

/* Now it's time to load the right scores in the sorting vector */
if (dontsort == 0) {
Expand All @@ -273,7 +273,7 @@ void sortCommand(redisClient *c) {
* far. We can just cast it */
vector[j].u.score = (long)byval->ptr;
} else {
redisAssert(1 != 1);
redisAssertWithInfo(c,sortval,1 != 1);
}
}

Expand Down Expand Up @@ -330,7 +330,8 @@ void sortCommand(redisClient *c) {
decrRefCount(val);
}
} else {
redisAssert(sop->type == REDIS_SORT_GET); /* always fails */
/* Always fails */
redisAssertWithInfo(c,sortval,sop->type == REDIS_SORT_GET);
}
}
}
Expand Down Expand Up @@ -360,8 +361,8 @@ void sortCommand(redisClient *c) {
listTypePush(sobj,val,REDIS_TAIL);
decrRefCount(val);
} else {
/* always fails */
redisAssert(sop->type == REDIS_SORT_GET);
/* Always fails */
redisAssertWithInfo(c,sortval,sop->type == REDIS_SORT_GET);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/t_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ hashTypeIterator *hashTypeInitIterator(robj *subject) {
} else if (hi->encoding == REDIS_ENCODING_HT) {
hi->di = dictGetIterator(subject->ptr);
} else {
redisAssert(NULL);
redisAssertWithInfo(NULL,subject,0);
}
return hi;
}
Expand Down Expand Up @@ -250,7 +250,7 @@ void convertToRealHash(robj *o) {
unsigned int klen, vlen;
dict *dict = dictCreate(&hashDictType,NULL);

redisAssert(o->type == REDIS_HASH && o->encoding != REDIS_ENCODING_HT);
redisAssertWithInfo(NULL,o,o->type == REDIS_HASH && o->encoding != REDIS_ENCODING_HT);
p = zipmapRewind(zm);
while((p = zipmapNext(p,&key,&klen,&val,&vlen)) != NULL) {
robj *keyobj, *valobj;
Expand Down
Loading

0 comments on commit eab0e26

Please sign in to comment.