New submission from Thomas Heller: This patch adds new calling conventions to ctypes foreign functions by passing 'errno=True' or 'GetLastError=True' to the CDLL or WinDLL constructor.
If CDLL(..., errno=True) or WinDLL(..., errno=True) is used, the function objects available in the CDLL or WinDLL instance will set the C global errno to zero before the actual call, and attach the C global errno value after the call as 'errno' attribute to the function object. This attribute is stored in thread-local storage. Similarly, if CDLL(..., GetLastError=True) or WinDLL(..., GetLastError=True) is used, the win32 api function 'SetLastError(0)' is used to reset the windows last error code before the actual call, and the value returned by 'GetLastError()' is attached as 'LastError' attribute to the function object, in thread local storage. Of course this only occurs on Windows. The LastError and errno attributes are readonly from Python code, accessing them before a foreign function call has occurred in the current thread raises a ValueError. ---------- assignee: theller components: Extension Modules files: ctypes-errno.patch keywords: patch messages: 59748 nosy: theller severity: normal status: open title: Add ctypes calling convention that allows safe access of errno type: rfe versions: Python 2.6 Added file: http://bugs.python.org/file9130/ctypes-errno.patch __________________________________ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1798> __________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com