Problem with Hiredis Binding

2012-01-05 Thread Puming Zhao
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

Re: Problem with Hiredis Binding

2012-01-05 Thread Joshua Reusch
Am 05.01.2012 17:21, schrieb Puming Zhao: 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

Re: Problem with Hiredis Binding

2012-01-05 Thread Timon Gehr
On 01/05/2012 07:14 PM, Joshua Reusch wrote: Am 05.01.2012 17:21, schrieb Puming Zhao: 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 cl

Re: Problem with Hiredis Binding

2012-01-05 Thread Johannes Pfau
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

Re: Problem with Hiredis Binding

2012-01-05 Thread Joshua Reusch
Am 05.01.2012 19:44, schrieb Timon Gehr: On 01/05/2012 07:14 PM, Joshua Reusch wrote: Am 05.01.2012 17:21, schrieb Puming Zhao: 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

Re: Problem with Hiredis Binding

2012-01-05 Thread Joshua Reusch
Sure ? dlang.org says they are not: http://www.d-programming-language.org/arrays.html#strings Sorry, in the printf section: "String literals already have a 0 appended to them, so can be used directly" I missed this.

Re: Problem with Hiredis Binding

2012-01-05 Thread Andrej Mitrovic
Your problem is that you're calling printf on a static char array. If you're going to use printf you have to use it on the .ptr (pointer) field of the static array. Replace this call: printf("Connection error: %s\n", c.errstr); with printf("Connection error: %s\n", c.errstr.ptr); On my en

Re: Problem with Hiredis Binding

2012-01-05 Thread bearophile
Andrej Mitrovic: > I think `long long` in C is 8 bytes, which is the > equivalent to D's long type. I think C just requires: sizeof(long long int) >= sizeof(long int). For the actual size I think you have to ask to the C compiler. Bye, bearophile

Re: Problem with Hiredis Binding

2012-01-05 Thread Puming
On Thursday, 5 January 2012 at 22:02:25 UTC, Andrej Mitrovic wrote: Your problem is that you're calling printf on a static char array. If you're going to use printf you have to use it on the .ptr (pointer) field of the static array. Replace this call: printf("Connection error: %s\n", c.err

Re: Problem with Hiredis Binding

2012-01-05 Thread Puming
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? Thanks. I've changed `int integer` to `c_long integer` according to this page http://dlang.org/interfaceToC.html c_long is in cor

Re: Problem with Hiredis Binding

2012-01-05 Thread Mike Parker
On 1/6/2012 11:38 AM, Puming wrote: On Thursday, 5 January 2012 at 22:02:25 UTC, Andrej Mitrovic wrote: Your problem is that you're calling printf on a static char array. If you're going to use printf you have to use it on the .ptr (pointer) field of the static array. Replace this call: printf

Re: Problem with Hiredis Binding

2012-01-05 Thread Puming
I think the problem still lies with your declaration of the integer field. c_long in D is supposed to be equivalent to the long type in C, *not* long long. It is declared as 32 bits on a 32-bit system and 64 bits on a 64-bit system. I believe that in practice, most C compilers implement long

Re: Problem with Hiredis Binding

2012-01-05 Thread Puming
Here is what I've got so far: 1. "long long" in C is always 64bit, so in D it's "long"; 2. C's char* string should be converted to!string when used in "writeln"; 3. String literals in D -IS- zero terminated; And now it's working fine. Thanks everybody :)

Re: Problem with Hiredis Binding

2012-01-06 Thread Mike Parker
On 1/6/2012 2:34 PM, Puming wrote: In http://dlang.org/interfaceToC.html it says in 32bit system c_long is equivalent to `long long` in C. Is this wrong? Well, either the documentation is wrong or the implementation is. Looks like one for Bugzilla.

Re: Problem with Hiredis Binding

2012-01-06 Thread Johannes Pfau
Mike Parker wrote: > On 1/6/2012 2:34 PM, Puming wrote: >> >>> >> In http://dlang.org/interfaceToC.html it says in 32bit system c_long is >> equivalent to `long long` in C. Is this wrong? > > Well, either the documentation is wrong or the implementation is. Looks > like one for Bugzilla. The doc

Re: Problem with Hiredis Binding

2012-01-06 Thread bearophile
Puming: > 1. "long long" in C is always 64bit, so in D it's "long"; In C "long long" isn't always 64 bit. Bye, bearophile

Re: Problem with Hiredis Binding

2012-01-06 Thread Andrej Mitrovic
On 1/6/12, Johannes Pfau wrote: > The documentation is wrong. That was my fault. I was going to fix the original docs which had no mention of c_long/c_ulong and I ended up screwing up the tables. Sorry!