From 491b2ae597c6abac4a983c0ca263a835e413440d Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Wed, 1 Jul 2026 17:01:05 +0200 Subject: [PATCH] gh-152433: Windows: ``_ctypes`` module: improve UWP compatibility --- .../2026-07-01-17-00-52.gh-issue-152433.kSd1bW.rst | 1 + Modules/_ctypes/callproc.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Windows/2026-07-01-17-00-52.gh-issue-152433.kSd1bW.rst diff --git a/Misc/NEWS.d/next/Windows/2026-07-01-17-00-52.gh-issue-152433.kSd1bW.rst b/Misc/NEWS.d/next/Windows/2026-07-01-17-00-52.gh-issue-152433.kSd1bW.rst new file mode 100644 index 00000000000000..e8109360a4b692 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-07-01-17-00-52.gh-issue-152433.kSd1bW.rst @@ -0,0 +1 @@ +``_ctypes`` module: improve UWP compatibility. diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index ccc57e347b07ac..8456f5db589c70 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1082,8 +1082,7 @@ void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...) } -#ifdef MS_WIN32 - +#ifdef MS_WINDOWS_DESKTOP static PyObject * GetComError(ctypes_state *st, HRESULT errcode, GUID *riid, IUnknown *pIunk) { @@ -1337,9 +1336,11 @@ PyObject *_ctypes_callproc(ctypes_state *st, #ifdef MS_WIN32 if (iid && pIunk) { +#ifdef MS_WINDOWS_DESKTOP if (*(int *)resbuf & 0x80000000) retval = GetComError(st, *(HRESULT *)resbuf, iid, pIunk); else +#endif retval = PyLong_FromLong(*(int *)resbuf); } else if (flags & FUNCFLAG_HRESULT) { if (*(int *)resbuf & 0x80000000) @@ -1417,10 +1418,14 @@ static PyObject *load_library(PyObject *self, PyObject *args) return NULL; Py_BEGIN_ALLOW_THREADS +#ifndef MS_WINDOWS_DESKTOP + hMod = LoadPackagedLibrary(name, 0); +#else /* bpo-36085: Limit DLL search directories to avoid pre-loading * attacks and enable use of the AddDllDirectory function. */ hMod = LoadLibraryExW(name, NULL, (DWORD)load_flags); +#endif err = hMod ? 0 : GetLastError(); Py_END_ALLOW_THREADS