[pypy-dev] r55005 - in pypy/branch/win32port/pypy: lib lib/_ctypes module/_rawffi module/_rawffi/test rlib rlib/test

Maciej Fijalkowski fijall at gmail.com
Wed May 21 21:27:24 CEST 2008


> I've cc'd to ctypes.users.

Thank you, subscribed

> theller at tubu610:~$ python
> Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from ctypes import *
>>>> from ctypes.util import find_library
>>>> m = CDLL(find_library("m"))
>>>> m
> <CDLL 'libm.so.6', handle b7f652b0 at b7d867ac>
>>>> c = CDLL(find_library("c"))
>>>> c
> <CDLL 'libc.so.6', handle b7f65558 at b7d8606c>
>>>> c.printf
> <_FuncPtr object at 0xb7da41cc>
>>>> m.printf
> <_FuncPtr object at 0xb7da4234>
>>>> c.printf("hello, world\n")
> hello, world
> 13
>>>> m.printf("hello, world\n")
> hello, world
> 13
>>>> find_library("c")
> 'libc.so.6'
>>>> find_library("m")
> 'libm.so.6'
>>>>
>
> It may be possible to get different behaviour when the libraries are loaded
> using different RTLD_ flags.

yes, it depends on RTLD_GLOBAL vs RTLD_LOCAL. Note, that unless you
specify RTLD_GLOBAL, you don't get this behavior (RTLD_LOCAL is the
default for C and accidentally for pypy as well).

For me details on top of cpython are slightly different and it's very
platform dependent. (ie libm has no qsort, but libc has sqrt,
obscure).

I would rather like to keep it clean and not populate namespace if not
necessary, hence libc helper finder would be cool.

Thomas: thanks for feedback

Cheers,
fijal



More information about the Pypy-dev mailing list