Message67550
Here is a patch implementing the plan. This text could serve as a start for the
documentation, but it also describes the current implementation. Usage recipes
should probably be added:
/*
ctypes maintains a module-global, but thread-local, variable that contains
an error number; called 'ctypes_errno' for this discussion. This variable
is a private copy of the stdlib 'errno' value; it is swapped with the
'errno' variable on several occasions.
Foreign functions created with CDLL(..., use_errno=True), when called, swap
the values just before they are actual function call, and swapped again
afterwards. The 'use_errno' parameter defaults to False, in this case
ctypes_errno is not touched.
The values are also swapped immeditately before and after ctypes callback
functions are called, if the callbacks are constructed using the new
optional use_errno parameter for CFUNCTYPE(..., use_errno=TRUE) or
WINFUNCTYPE(..., use_errno=True).
Two new ctypes functions are provided to access the 'ctypes_errno' value
from Python:
- ctypes.set_errno(value) sets ctypes_errno to 'value', the previous
ctypes_errno value is returned.
- ctypes.get_errno() returns the current ctypes_errno value.
The same scheme is implemented on Windows for GetLastError() and
SetLastError(), and the CDLL and WinDLL optional parameter is named
'use_LastError', and also defaults to False.
On Windows, TlsSetValue and TlsGetValue calls are used to provide thread
local storage for the variables; ctypes compiled with __GNUC__ uses __thread
variables.
*/ |
|
Date |
User |
Action |
Args |
2008-05-30 20:40:27 | theller | set | spambayes_score: 0.00795624 -> 0.007956238 recipients:
+ theller, loewis, arigo, amaury.forgeotdarc, fijal |
2008-05-30 20:40:25 | theller | link | issue1798 messages |
2008-05-30 20:40:25 | theller | create | |
|