[Python-Dev] Py_END_ALLOW_THREADS and GetLastError()

Kristján Valur Jónsson kristjan at ccpgames.com
Sat Jan 10 12:29:47 CET 2009

Currently on Windows, Py_END_ALLOW_THREADS can have the side effect of resetting the windows error code returned by GetLastError().
There is a number of cases, particularly in posixmodule, with a pattern like:
            result = FindNextFile(hFindFile, &FileData);
            /* FindNextFile sets error to ERROR_NO_MORE_FILES if
               it got to the end of the directory. */
            if (!result && GetLastError() != ERROR_NO_MORE_FILES) {

That doesn´t work.  (This particular site is where I noticed the problem, running the testsuite in a debug build).
Now, the thread swith macro does take care to preserve "errno", but not the windows system error.  This is easy to add, but it requires that windows.h be included by ceval.c and pystate.c
The alternative fix is to find all these cases and manually preserve the error state, or query it right after the function call if needed.
Any preferences?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090110/7e294515/attachment.htm>

More information about the Python-Dev mailing list