Revert privdata in context callbacks to being non-const

This commit is contained in:
Pieter Noordhuis 2010-10-19 14:19:47 +02:00
parent f9596db90b
commit ba42ab2ef8
3 changed files with 16 additions and 16 deletions

View File

@ -631,20 +631,20 @@ redisContext *redisConnectNonBlock(const char *ip, int port, redisReplyFunctions
}
/* Register callback that is triggered when redisDisconnect is called. */
void redisSetDisconnectCallback(redisContext *c, redisContextCallbackFn *fn, const void *privdata) {
void redisSetDisconnectCallback(redisContext *c, redisContextCallbackFn *fn, void *privdata) {
c->cbDisconnect.fn = fn;
c->cbDisconnect.privdata = privdata;
}
/* Register callback that is triggered when a command is put in the output
* buffer when the context is non-blocking. */
void redisSetCommandCallback(redisContext *c, redisContextCallbackFn *fn, const void *privdata) {
void redisSetCommandCallback(redisContext *c, redisContextCallbackFn *fn, void *privdata) {
c->cbCommand.fn = fn;
c->cbCommand.privdata = privdata;
}
/* Register callback that is triggered when the context is free'd. */
void redisSetFreeCallback(redisContext *c, redisContextCallbackFn *fn, const void *privdata) {
void redisSetFreeCallback(redisContext *c, redisContextCallbackFn *fn, void *privdata) {
c->cbFree.fn = fn;
c->cbFree.privdata = privdata;
}

View File

@ -77,7 +77,7 @@ typedef struct redisReplyObjectFunctions {
struct redisContext; /* need forward declaration of redisContext */
/* Callbacks triggered on non-reply events. */
typedef void (redisContextCallbackFn)(struct redisContext*, const void*);
typedef void (redisContextCallbackFn)(struct redisContext*, void*);
/* Reply callback prototype and container */
typedef void (redisCallbackFn)(struct redisContext*, redisReply*, const void*);
@ -85,7 +85,7 @@ typedef void (redisCallbackFn)(struct redisContext*, redisReply*, const void*);
/* Callback containers */
typedef struct redisContextCallback {
redisContextCallbackFn *fn;
const void *privdata;
void *privdata;
} redisContextCallback;
typedef struct redisCallback {
@ -135,16 +135,16 @@ int redisProcessCallbacks(redisContext *c);
/* The disconnect callback is called *immediately* when redisDisconnect()
* is called. It is called only once for every redisContext (since hiredis
* currently does not support reconnecting an existing context). */
void redisSetDisconnectCallback(redisContext *c, redisContextCallbackFn *fn, const void *privdata);
void redisSetDisconnectCallback(redisContext *c, redisContextCallbackFn *fn, void *privdata);
/* The command callback is called every time redisCommand() is called in a
* non-blocking context. It is called *after* the formatted command has been
* appended to the write buffer. */
void redisSetCommandCallback(redisContext *c, redisContextCallbackFn *fn, const void *privdata);
void redisSetCommandCallback(redisContext *c, redisContextCallbackFn *fn, void *privdata);
/* The free callback is called *before* all allocations are free'd. Use it to
* release resources that depend/use the redisContext that is being free'd. */
void redisSetFreeCallback(redisContext *c, redisContextCallbackFn *fn, const void *privdata);
void redisSetFreeCallback(redisContext *c, redisContextCallbackFn *fn, void *privdata);
/* Issue a command to Redis. In a blocking context, it returns the reply. When
* an error occurs, it returns NULL and you should read redisContext->error

16
test.c
View File

@ -195,7 +195,7 @@ static void cleanup() {
}
static long __test_callback_flags = 0;
static void __test_callback(redisContext *c, const void *privdata) {
static void __test_callback(redisContext *c, void *privdata) {
((void)c);
/* Shift to detect execution order */
__test_callback_flags <<= 8;
@ -218,7 +218,7 @@ static void test_nonblocking_connection() {
__test_callback_flags = 0;
test("Calls command callback when command is issued: ");
c = redisConnectNonBlock("127.0.0.1", 6379, NULL);
redisSetCommandCallback(c,__test_callback,(const void*)1);
redisSetCommandCallback(c,__test_callback,(void*)1);
redisCommand(c,"PING");
test_cond(__test_callback_flags == 1);
redisFree(c);
@ -226,7 +226,7 @@ static void test_nonblocking_connection() {
__test_callback_flags = 0;
test("Calls disconnect callback on redisDisconnect: ");
c = redisConnectNonBlock("127.0.0.1", 6379, NULL);
redisSetDisconnectCallback(c,__test_callback,(const void*)2);
redisSetDisconnectCallback(c,__test_callback,(void*)2);
redisDisconnect(c);
test_cond(__test_callback_flags == 2);
redisFree(c);
@ -234,8 +234,8 @@ static void test_nonblocking_connection() {
__test_callback_flags = 0;
test("Calls disconnect callback and free callback on redisFree: ");
c = redisConnectNonBlock("127.0.0.1", 6379, NULL);
redisSetDisconnectCallback(c,__test_callback,(const void*)2);
redisSetFreeCallback(c,__test_callback,(const void*)4);
redisSetDisconnectCallback(c,__test_callback,(void*)2);
redisSetFreeCallback(c,__test_callback,(void*)4);
redisFree(c);
test_cond(__test_callback_flags == ((2 << 8) | 4));
@ -262,9 +262,9 @@ static void test_nonblocking_connection() {
wdone = __test_reply_callback_flags = 0;
test("Process callbacks in the right sequence: ");
c = redisConnectNonBlock("127.0.0.1", 6379, NULL);
redisCommandWithCallback(c,__test_reply_callback,(const void*)1,"PING");
redisCommandWithCallback(c,__test_reply_callback,(const void*)2,"PING");
redisCommandWithCallback(c,__test_reply_callback,(const void*)3,"PING");
redisCommandWithCallback(c,__test_reply_callback,(void*)1,"PING");
redisCommandWithCallback(c,__test_reply_callback,(void*)2,"PING");
redisCommandWithCallback(c,__test_reply_callback,(void*)3,"PING");
/* Write output buffer */
while(!wdone) {