ctypes not working (Fwd: [pypy-dev] 2.6.1 and freebsd-9)

David Naylor dbn at freebsd.org
Mon Aug 24 21:11:37 UTC 2015


Hi list,

Please see the correspondence below from the pypy team about some failing 
tests.  Specifically, why is test.py producing None whereas test.c is 
producing the desired results?  

Regards

----------  Forwarded Message  ----------

Subject: Re: [pypy-dev] 2.6.1 and freebsd-9
Date: Monday, 24 August 2015, 23:07:20
From: David Naylor <naylor.b.david at gmail.com>
To: pypy-dev at python.org
CC: Matti Picus <matti.picus at gmail.com>

On Saturday, 22 August 2015 21:25:44 Matti Picus wrote:
> I would like to add the freebsd-9-x86-64 binary tgz to our released
> downloads. We still have a number of failing tests showing up on
> http://buildbot.pypy.org/summary?category=freebsd64
> among them many
> DLOpenError: "opening 'libm.so' with ctypes.CDLL() works, but not with
> c_dlopen()??"
> and the more worrying SIGSEGV in
> http://buildbot.pypy.org/summary/longrepr?testname=unmodified&builder=pypy-c
> -jit-freebsd-9-x86-64&build=655&mod=lib-python.2.7.test.test_io
> 
> Could someone proficient in freebsd suggest what is going on?

Hi Matti,

I am able to reproduce this on FreeBSD 10.2:
# cat > test.py << __EOF
from ctypes import *

libc = CDLL("libc.so.7")
dlopen = libc["dlopen"]

# see <dlfnc.h>: void    *dlopen(const char *, int);
dlopen.argtypes = [c_char_p, c_int]
dlopen.restype = c_void_p

print dlopen(c_char_p("libm.so"), c_int(0))
__EOF
# python test.py
None

However, contract this with the C equivalent:
# cat > test.c << __EOF
#include <dlfcn.h>
#include <stdio.h>

int main(int argc, char** argv)
{
    printf("%p\n", dlopen("libm.so", RTLD_LOCAL));
}
__EOF
# cc -o test test.c
# ./test
0x800620800

<snip/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 949 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freebsd.org/pipermail/freebsd-python/attachments/20150824/0d66ddf7/attachment.bin>


More information about the freebsd-python mailing list