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

Thomas Heller theller at ctypes.org
Wed May 21 13:22:22 CEST 2008


Maciej Fijalkowski schrieb:
>> Ha, that's the best approach I have seen so far to get the name if the
>> msvcrt runtime library.  Hope you don't mind if I steal it for 'official'
>> ctypes (I will check if it works in win64 also before) ?
>>
>> -- Thanks, Thomas
> 
> Cool :)
> 
> Besides, can you take a look at small script here:
> http://codespeak.net/svn/pypy/dist/pypy/lib/ctypes_support.py? It
> tries to address two issues - "how to find c library" and "how to get
> errno", what do you think?
> 
> Cheers,
> fijal

Even cooler that I can read from day to day how you reimplemented
ctypes for pypy :-)

"how to find c library" - is only a problem on windows (which I hope can
now be solved better).  On linux (not sure about *nix) simply call
LoadLibrary(None) [=> dlopen(NULL) in C], and you can get all functions
from all loaded shared libs from that handle.

"how to get errno" - the problem with this is that errno is only valid
(in the calling thread) until another stdlib library function has been
called in this thread.

So, since arbitrary code can run (in CPython's ctypes, at least) between
the time a function in a shared lib has been called and the time you access
errno there is no guarantee that it is still valid.
There has been some discussion on the ctypes-users list some months ago
about that, and the only reliable way to get errno for the function call
seems to be to get errno immediately after the function call.
The question is how to make this value available to the calling Python code.
Two ways were discussed: To attach the errno value in thread local storage
to the function object itself, or to pass it to the '.errcheck' function.
Nothing of this has yet been implemented in ctypes.

-- 
Thanks,
Thomas



More information about the Pypy-dev mailing list