Problem with Hiredis Binding
Johannes Pfau
spam at example.com
Thu Jan 5 11:06:53 PST 2012
Puming Zhao wrote:
> Hi, I'm new in D programming, and does not have much C experience either.
> After reading TDPL book and playing with some sample codes, I came to
> decide to try something more `practical`. I began with a Redis client
> binding from Hiredis C code. Hiredis is a small lib, and seems very simple
> to bind to D.
>
> My code on github:
>
> https://github.com/zhaopuming/dredis
>
> But I went into problems that I don't know how to solve. When running
> example.d I went into segment fault, and can't get redisReply from a redis
> command. I tried to google it but got nothing.
>
> So my question is, could some one with more knowledge in redis or C/D look
> into my code and see what's wrong ? Or is there already a Redis binding
> exists?
in hiredis.d
------------------------
struct redisReply {
int type; /* REDIS_REPLY_* */
int integer; /* The integer when type is REDIS_REPLY_INTEGER */
int len; /* Length of string */
char* str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
redisReply** element; /* elements vector for REDIS_REPLY_ARRAY */
};
------------------------
but in hiredis.h
------------------------
typedef struct redisReply {
int type; /* REDIS_REPLY_* */
long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
int len; /* Length of string */
char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
} redisReply;
------------------------
So you have "int integer;" in D and "long long integer;" in C, which doesn't
match. I'm not sure what size "long long" is in C, but I guess you need
"long" in D?
More information about the Digitalmars-d-learn
mailing list