Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Wrong use of ctypes.GetLastError() in windows_console.py #132888

Copy link
Copy link
Open
@chris-eibl

Description

@chris-eibl
Issue body actions

Bug report

Bug description:

Everywhere ctypes.GetLastError() is used, even though use_last_error is specified

_KERNEL32 = WinDLL("kernel32", use_last_error=True)

This will always return the "swapped" error, as can be seen here

#ifdef MS_WIN32
if (flags & FUNCFLAG_USE_LASTERROR) {
int temp = 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);
}
#ifdef MS_WIN32
if (flags & FUNCFLAG_USE_LASTERROR) {
int temp = 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 using ctypes.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsstdlibPython modules in the Lib dirPython modules in the Lib dirtopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.