cpython/Modules/_ctypes
Thomas Heller fbb9c0bf3c Issue #1798: Add ctypes calling convention that allows safe access of errno.
ctypes maintains thread-local storage that has space for two error
numbers: private copies of the system 'errno' value and, on Windows,
the system error code accessed by the GetLastError() and
SetLastError() api functions.

Foreign functions created with CDLL(..., use_errno=True), when called,
swap the system 'errno' value with the private copy just before the
actual function call, and swapped again immediately afterwards.  The
'use_errno' parameter defaults to False, in this case 'ctypes_errno'
is not touched.

On Windows, foreign functions created with CDLL(...,
use_last_error=True) or WinDLL(..., use_last_error=True) swap the
system LastError value with the ctypes private copy.

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 set to True: CFUNCTYPE(...,
use_errno=TRUE) or WINFUNCTYPE(..., use_errno=True).

New ctypes functions are provided to access the ctypes private copies
from Python:

- ctypes.set_errno(value) and ctypes.set_last_error(value) store
  'value' in the private copy and returns the previous value.

- ctypes.get_errno() and ctypes.get_last_error() returns the current
  ctypes private copies value.
2008-06-06 08:33:46 +00:00
..
darwin Copy ctypes-0.9.9.4 sources from external into the trunk. 2006-03-08 19:35:11 +00:00
libffi Fix misspelled sys.platform name and misspelled filename. 2008-06-02 18:41:30 +00:00
libffi_arm_wince Copy ctypes-0.9.9.4 sources from external into the trunk. 2006-03-08 19:35:11 +00:00
libffi_msvc On 64-bit Windows, ffi_arg must be 8 bytes long. This fixes the 2007-05-04 08:20:41 +00:00
libffi_osx MacOS X: Enable 4-way universal builds 2008-06-05 12:58:24 +00:00
_ctypes.c Issue #1798: Add ctypes calling convention that allows safe access of errno. 2008-06-06 08:33:46 +00:00
_ctypes_test.c Issue 1872: Changed the struct module typecode from 't' to '?', for 2008-03-05 15:34:29 +00:00
_ctypes_test.h Copy ctypes-0.9.9.4 sources from external into the trunk. 2006-03-08 19:35:11 +00:00
callbacks.c Issue #1798: Add ctypes calling convention that allows safe access of errno. 2008-06-06 08:33:46 +00:00
callproc.c Issue #1798: Add ctypes calling convention that allows safe access of errno. 2008-06-06 08:33:46 +00:00
cfield.c MacOS X: Enable 4-way universal builds 2008-06-05 12:58:24 +00:00
ctypes.h Issue #1798: Add ctypes calling convention that allows safe access of errno. 2008-06-06 08:33:46 +00:00
ctypes_dlfcn.h Add pep-291 compatibility markers. 2006-06-12 20:56:48 +00:00
malloc_closure.c Patch #1722225: Support QNX 6. 2008-05-23 15:06:50 +00:00
stgdict.c Backport from py3k: Implement the new buffer interface from pep3118 2008-06-05 17:51:15 +00:00