[issue33030] GetLastError() may be overwritten by Py_END_ALLOW_THREADS

2021-03-18 Thread Eryk Sun
Change by Eryk Sun : -- versions: +Python 3.10, Python 3.9 -Python 3.6, Python 3.7 ___ Python tracker ___ ___ Python-bugs-list

[issue33030] GetLastError() may be overwritten by Py_END_ALLOW_THREADS

2018-03-08 Thread Alexey Izbyshev
Alexey Izbyshev added the comment: @eryksun Very interesting! BTW, I looked at CreateFile docs, and the fact that it may set the last error to zero is even documented there. @steve.dower > maybe we don't have to preserve errno on Windows? There are still places where

[issue33030] GetLastError() may be overwritten by Py_END_ALLOW_THREADS

2018-03-08 Thread Eryk Sun
Eryk Sun added the comment: FYI, here's a sampling of successful calls that modify the last error value. Most Create- functions intentionally set the last error to 0 on success, such as CreateFile, CreateFileMapping, CreateSymbolicLink, CreateJobObject, CreateEvent,

[issue33030] GetLastError() may be overwritten by Py_END_ALLOW_THREADS

2018-03-08 Thread Steve Dower
Steve Dower added the comment: > Before take_gil() knows whether it has to do any work I thought we had a check for when the GIL was not even initialized, but that doesn't seem to exist in master any more. Preserving GetLastError() at the same place we do errno is

[issue33030] GetLastError() may be overwritten by Py_END_ALLOW_THREADS

2018-03-08 Thread Alexey Izbyshev
Alexey Izbyshev added the comment: > Ideally, if we don't have to do any work to reacquire the GIL, we shouldn't > do any work to preserve the error code either. Before take_gil() knows whether it has to do any work, it calls MUTEX_LOCK(_PyRuntime.ceval.gil.mutex), which

[issue33030] GetLastError() may be overwritten by Py_END_ALLOW_THREADS

2018-03-08 Thread Steve Dower
Steve Dower added the comment: > GetLastError() docs officially scare us I believe this is a case where the docs were updated from intended/correct behavior to actual behavior, which happens from time to time and is never clearly marked. As I say, they are _supposed_

[issue33030] GetLastError() may be overwritten by Py_END_ALLOW_THREADS

2018-03-08 Thread Alexey Izbyshev
Alexey Izbyshev added the comment: FWIW, GetLastError() docs[1] officially scare us: Most functions that set the thread's last-error code set it when they fail. However, some functions also set the last-error code when they succeed. If the function is not documented to

[issue33030] GetLastError() may be overwritten by Py_END_ALLOW_THREADS

2018-03-08 Thread Steve Dower
New submission from Steve Dower : Most Win32 API calls are made within Py_BEGIN_ALLOW_THREADS blocks, as they do not access Python objects and so we can release the GIL. However, in general, error handling occurs after the Py_END_ALLOW_THREADS line. Due to the design