X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/994ed2bc552f4114b1f0c8dd3fd8aefaec6beeae..7112580cb3368d08f0672360b856e8a0d9892051:/src/object.c diff --git a/src/object.c b/src/object.c index ce13429a..c1df4d1d 100644 --- a/src/object.c +++ b/src/object.c @@ -192,6 +192,23 @@ void decrRefCount(void *obj) { } } +/* This function set the ref count to zero without freeing the object. + * It is useful in order to pass a new object to functions incrementing + * the ref count of the received object. Example: + * + * functionThatWillIncrementRefCount(resetRefCount(CreateObject(...))); + * + * Otherwise you need to resort to the less elegant pattern: + * + * *obj = createObject(...); + * functionThatWillIncrementRefCount(obj); + * decrRefCount(obj); + */ +robj *resetRefCount(robj *obj) { + obj->refcount = 0; + return obj; +} + int checkType(redisClient *c, robj *o, int type) { if (o->type != type) { addReply(c,shared.wrongtypeerr);