ctype C library call always returns 0 with Python3

2012-05-19 Thread Johannes Bauer
Hi group, I'm playing with ctypes and using it to do regressions on some C code that I compile as a shared library. Python is the testing framework. This works nicely as long as I do not need the return value (i.e. calling works as expected and parameters are passed correctly). The return value

Re: ctype C library call always returns 0 with Python3

2012-05-19 Thread Nobody
On Sat, 19 May 2012 11:30:46 +0200, Johannes Bauer wrote: import ctypes libc = ctypes.cdll.LoadLibrary(/lib64/libc-2.14.1.so) print(libc.strchr(abcdef, ord(d))) In 3.x, a string will be passed as a wchar_t*, not a char*. IOW, the memory pointed to by the first argument to strchr() will

Re: ctype C library call always returns 0 with Python3

2012-05-19 Thread Colin McPhail
On 19/05/2012 10:30, Johannes Bauer wrote: Even the example in the standard library fails: import ctypes libc = ctypes.cdll.LoadLibrary(/lib64/libc-2.14.1.so) print(libc.strchr(abcdef, ord(d))) Always returns 0. I think there may be two problems with this code: (1) You are using a 64-bit

Re: ctype C library call always returns 0 with Python3

2012-05-19 Thread Hans Mulder
On 19/05/12 13:20:24, Nobody wrote: On Sat, 19 May 2012 11:30:46 +0200, Johannes Bauer wrote: import ctypes libc = ctypes.cdll.LoadLibrary(/lib64/libc-2.14.1.so) print(libc.strchr(abcdef, ord(d))) In 3.x, a string will be passed as a wchar_t*, not a char*. IOW, the memory pointed to by