Author theller
Recipients amaury.forgeotdarc, arigo, fijal, loewis, theller
Date 2008-05-30.20:40:25
SpamBayes Score 0.00795624
Marked as misclassified No
Message-id <4840662F.8040701@ctypes.org>
In-reply-to <483EFC77.1060704@ctypes.org>
Content
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.
*/
Files
File name Uploaded
ctypes-errno-3.patch theller, 2008-05-30.20:40:20
History
Date User Action Args
2008-05-30 20:40:27thellersetspambayes_score: 0.00795624 -> 0.00795624
recipients: + theller, loewis, arigo, amaury.forgeotdarc, fijal
2008-05-30 20:40:25thellerlinkissue1798 messages
2008-05-30 20:40:25thellercreate