Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
Closed
Description
Bug report
Bug description:
Everywherectypes.GetLastError() is used, even thoughuse_last_error is specified
cpython/Lib/_pyrepl/windows_console.py
Line 617 ine1c09ff
| _KERNEL32=WinDLL("kernel32",use_last_error=True) |
This will always return the "swapped" error, as can be seen here
cpython/Modules/_ctypes/callbacks.c
Lines 201 to 222 ine1c09ff
| #ifdefMS_WIN32 | |
| if (flags&FUNCFLAG_USE_LASTERROR) { | |
| inttemp=space[1]; | |
| space[1]=GetLastError(); | |
| SetLastError(temp); | |
| } | |
| #endif | |
| } | |
| result=PyObject_Vectorcall(callable,args,nargs,NULL); | |
| if (result==NULL) { | |
| PyErr_FormatUnraisable("Exception ignored while " | |
| "calling ctypes callback function %R", | |
| callable); | |
| } | |
| #ifdefMS_WIN32 | |
| if (flags&FUNCFLAG_USE_LASTERROR) { | |
| inttemp=space[1]; | |
| space[1]=GetLastError(); | |
| SetLastError(temp); | |
| } |
or carefully reading the docs (the code was easier to read for me :)
The rule is easy:use_last_error=True implies usingctypes.get_last_error(), which@eryksun has for example explained here:https://discuss.python.org/t/a-ctypes-function-to-list-all-loaded-shared-libraries/36370/10
CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows