ctype C library call always returns 0 with Python3

Johannes Bauer dfnsonfsduifb at gmx.de
Sat May 19 05:30:46 EDT 2012


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 of all functions is always zero in my case, however.

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'm working on a x86-64 Gentoo Linux and can reproduce this behavior
with Python 3.1.4 and Python 3.2.3.

On Python 2.7.3 and Python 2.6.6 the example works fine on my system.

Since I'd like to use Python3, I'm curious to know what changed in the
behavior and how I can get this to run. Any help is greatly appreciated.

Best regards,
Joe

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1 at speranza.aioe.org>



More information about the Python-list mailing list