From 77dd973815a033895cf6e5ed9056472e830c03a8 Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Fri, 11 Sep 2026 08:14:40 +0200 Subject: [PATCH 1/4] gh-152433: Windows: allow build socketmodule for UWP (#152601) --- ...-09-05-10-14-50.gh-issue-152433._LtjIg.rst | 1 + Modules/clinic/socketmodule.c.h | 14 ++++---- Modules/socketmodule.c | 36 ++++++++++++------- 3 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 Misc/NEWS.d/next/Windows/2026-09-05-10-14-50.gh-issue-152433._LtjIg.rst diff --git a/Misc/NEWS.d/next/Windows/2026-09-05-10-14-50.gh-issue-152433._LtjIg.rst b/Misc/NEWS.d/next/Windows/2026-09-05-10-14-50.gh-issue-152433._LtjIg.rst new file mode 100644 index 00000000000000..e9ab1fe7281239 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-09-05-10-14-50.gh-issue-152433._LtjIg.rst @@ -0,0 +1 @@ +Allow build :mod:`socket` module for Universal Windows Platform. diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h index dd5a906dda1a38..fcccf347a0ae9b 100644 --- a/Modules/clinic/socketmodule.c.h +++ b/Modules/clinic/socketmodule.c.h @@ -2159,7 +2159,7 @@ PyDoc_STRVAR(_socket_setdefaulttimeout__doc__, #define _SOCKET_SETDEFAULTTIMEOUT_METHODDEF \ {"setdefaulttimeout", (PyCFunction)_socket_setdefaulttimeout, METH_O, _socket_setdefaulttimeout__doc__}, -#if (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) +#if (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS_DESKTOP)) PyDoc_STRVAR(_socket_if_nameindex__doc__, "if_nameindex($module, /)\n" @@ -2179,9 +2179,9 @@ _socket_if_nameindex(PyObject *module, PyObject *Py_UNUSED(ignored)) return _socket_if_nameindex_impl(module); } -#endif /* (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) */ +#endif /* (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS_DESKTOP)) */ -#if (defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)) +#if (defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS_DESKTOP)) PyDoc_STRVAR(_socket_if_nametoindex__doc__, "if_nametoindex($module, oname, /)\n" @@ -2213,9 +2213,9 @@ _socket_if_nametoindex(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)) */ +#endif /* (defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS_DESKTOP)) */ -#if (defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)) +#if (defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP)) PyDoc_STRVAR(_socket_if_indextoname__doc__, "if_indextoname($module, if_index, /)\n" @@ -2244,7 +2244,7 @@ _socket_if_indextoname(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)) */ +#endif /* (defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP)) */ #if defined(CMSG_LEN) @@ -2478,4 +2478,4 @@ _socket_CMSG_SPACE(PyObject *module, PyObject *arg) #ifndef _SOCKET_CMSG_SPACE_METHODDEF #define _SOCKET_CMSG_SPACE_METHODDEF #endif /* !defined(_SOCKET_CMSG_SPACE_METHODDEF) */ -/*[clinic end generated code: output=aa9082b592c39fa5 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=dfe0ca7c716c1183 input=a9049054013a1b77]*/ diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index d189c6d478836c..61505c2603f22c 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -290,6 +290,10 @@ shutdown(how) -- shut down traffic in one or both directions\n\ /* Helpers needed for AF_HYPERV */ # include +#ifndef RPC_S_OK +#define RPC_S_OK 0L +#endif + /* Macros based on the IPPROTO enum, see: https://bugs.python.org/issue29515 */ #define IPPROTO_ICMP IPPROTO_ICMP #define IPPROTO_IGMP IPPROTO_IGMP @@ -631,14 +635,14 @@ _PyLong_##NAME##_Converter(PyObject *obj, void *ptr) \ return 1; \ } -#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) +#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP) # ifdef MS_WINDOWS UNSIGNED_INT_CONVERTER(NetIfindex, NET_IFINDEX) # else # define _PyLong_NetIfindex_Converter _PyLong_UnsignedInt_Converter # define NET_IFINDEX unsigned int # endif -#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) +#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP) /*[python input] class NET_IFINDEX_converter(CConverter): @@ -5924,10 +5928,12 @@ _socket_gethostname_impl(PyObject *module) Otherwise, gethostname apparently also returns the DNS name. */ wchar_t buf[MAX_COMPUTERNAME_LENGTH + 1]; DWORD size = Py_ARRAY_LENGTH(buf); - wchar_t *name; - PyObject *result; +#ifdef MS_WINDOWS_DESKTOP if (GetComputerNameExW(ComputerNamePhysicalDnsHostname, buf, &size)) +#else + if (GetComputerNameW(buf, &size)) +#endif return PyUnicode_FromWideChar(buf, size); if (GetLastError() != ERROR_MORE_DATA) @@ -5936,9 +5942,12 @@ _socket_gethostname_impl(PyObject *module) if (size == 0) return Py_GetConstant(Py_CONSTANT_EMPTY_STR); +#ifndef MS_WINDOWS_DESKTOP + return NULL; +#else /* MSDN says ERROR_MORE_DATA may occur because DNS allows longer names */ - name = PyMem_New(wchar_t, size); + wchar_t* name = PyMem_New(wchar_t, size); if (!name) { PyErr_NoMemory(); return NULL; @@ -5952,9 +5961,10 @@ _socket_gethostname_impl(PyObject *module) return NULL; } - result = PyUnicode_FromWideChar(name, size); + PyObject* result = PyUnicode_FromWideChar(name, size); PyMem_Free(name); return result; +#endif #else char buf[1024]; int res; @@ -7321,7 +7331,7 @@ _socket_setdefaulttimeout(PyObject *module, PyObject *arg) } -#if defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) +#if defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS_DESKTOP) /* Python API for getting interface indices and names */ /*[clinic input] @@ -7412,9 +7422,9 @@ _socket_if_nameindex_impl(PyObject *module) #endif } -#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) +#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS_DESKTOP) -#if defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS) +#if defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS_DESKTOP) /*[clinic input] _socket.if_nametoindex @@ -7444,9 +7454,9 @@ _socket_if_nametoindex_impl(PyObject *module, PyObject *oname) return PyLong_FromUnsignedLong(index); } -#endif // defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS) +#endif // defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS_DESKTOP) -#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) +#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP) /*[clinic input] @permit_long_summary @@ -7471,7 +7481,7 @@ _socket_if_indextoname_impl(PyObject *module, NET_IFINDEX index) return PyUnicode_DecodeFSDefault(name); } -#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) +#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP) #ifdef CMSG_LEN @@ -9374,7 +9384,7 @@ socket_exec(PyObject *m) #endif #endif /* _MSTCPIP_ */ -#ifdef MS_WINDOWS +#ifdef MS_WINDOWS_DESKTOP /* remove some flags on older version Windows during run-time */ if (remove_unusable_flags(m) < 0) { goto error; From 1b1b9b30218fc3bf92fd444d65f1a739b6c19bde Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Fri, 11 Sep 2026 12:16:27 +0200 Subject: [PATCH 2/4] gh-152433: Windows: allow build ``ceval.c`` for UWP (#152689) --- .../next/Windows/2026-07-04-20-12-24.gh-issue-152433.NtWEoL.rst | 1 + Python/ceval.c | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Windows/2026-07-04-20-12-24.gh-issue-152433.NtWEoL.rst diff --git a/Misc/NEWS.d/next/Windows/2026-07-04-20-12-24.gh-issue-152433.NtWEoL.rst b/Misc/NEWS.d/next/Windows/2026-07-04-20-12-24.gh-issue-152433.NtWEoL.rst new file mode 100644 index 00000000000000..91c8f3c3949df0 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-07-04-20-12-24.gh-issue-152433.NtWEoL.rst @@ -0,0 +1 @@ +Allow build ``ceval.c`` for Windows UWP. diff --git a/Python/ceval.c b/Python/ceval.c index 3a859c05a03724..8cf02651d9a408 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -131,7 +131,9 @@ hardware_stack_limits(uintptr_t *base, uintptr_t *top, uintptr_t sp) GetCurrentThreadStackLimits(&low, &high); *top = (uintptr_t)high; ULONG guarantee = 0; +#ifdef MS_WINDOWS_DESKTOP SetThreadStackGuarantee(&guarantee); +#endif *base = (uintptr_t)low + guarantee; #elif defined(__APPLE__) pthread_t this_thread = pthread_self(); From ab4ee5513b60ba2c3d1389fcc8c54915809ecfef Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Fri, 11 Sep 2026 12:17:26 +0200 Subject: [PATCH 3/4] gh-152433: Windows: ``_ctypes`` module: improve UWP compatibility (#152792) --- .../Windows/2026-07-01-17-00-52.gh-issue-152433.kSd1bW.rst | 1 + Modules/_ctypes/callproc.c | 5 +++-- 2 files changed, 4 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..1248edfd54aa2b --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-07-01-17-00-52.gh-issue-152433.kSd1bW.rst @@ -0,0 +1 @@ +Allow build :mod:`!_ctypes` for Universal Windows Platform. diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 746034c8004c5c..1f2c49b5878cc7 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) From 07f33ceb3a3bfe0f0bb95a11141d0159bf3c0aec Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Fri, 11 Sep 2026 12:18:43 +0200 Subject: [PATCH 4/4] gh-152433: Windows: ``_winapi`` module: improve UWP compatibility (#152962) --- .../2026-07-03-17-07-40.gh-issue-152433.Lc6HmG.rst | 1 + Modules/_winapi.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 Misc/NEWS.d/next/Windows/2026-07-03-17-07-40.gh-issue-152433.Lc6HmG.rst diff --git a/Misc/NEWS.d/next/Windows/2026-07-03-17-07-40.gh-issue-152433.Lc6HmG.rst b/Misc/NEWS.d/next/Windows/2026-07-03-17-07-40.gh-issue-152433.Lc6HmG.rst new file mode 100644 index 00000000000000..5f944e05b52567 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-07-03-17-07-40.gh-issue-152433.Lc6HmG.rst @@ -0,0 +1 @@ +``_winapi`` module: improve UWP compatibility diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 36eb831044a786..3cee151b997dee 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -1211,6 +1211,7 @@ gethandlelist(PyObject *mapping, const char *name, Py_ssize_t *size) return ret; } +#ifdef MS_WINDOWS_DESKTOP typedef struct { LPPROC_THREAD_ATTRIBUTE_LIST attribute_list; LPHANDLE handle_list; @@ -1322,6 +1323,7 @@ getattributelist(PyObject *obj, const char *name, AttributeList *attribute_list) return ret; } +#endif /*[clinic input] _winapi.CreateProcess @@ -1355,6 +1357,9 @@ _winapi_CreateProcess_impl(PyObject *module, const wchar_t *application_name, PyObject *startup_info) /*[clinic end generated code: output=a25c8e49ea1d6427 input=84e2175279a3f5c2]*/ { +#ifndef MS_WINDOWS_DESKTOP + return NULL; +#else PyObject *ret = NULL; BOOL result; PROCESS_INFORMATION pi; @@ -1436,6 +1441,7 @@ _winapi_CreateProcess_impl(PyObject *module, const wchar_t *application_name, freeattributelist(&attribute_list); return ret; +#endif } /*[clinic input] @@ -2591,7 +2597,9 @@ _winapi_BatchedWaitForMultipleObjects_impl(PyObject *module, while (--thread_count >= 0) { HANDLE t = thread_data[thread_count]->thread; if (t) { +#ifdef MS_WINDOWS_DESKTOP TerminateThread(t, WAIT_ABANDONED_0); +#endif CloseHandle(t); } PyMem_Free((void *)thread_data[thread_count]); @@ -2785,7 +2793,11 @@ static PyObject * _winapi_GetOEMCP_impl(PyObject *module) /*[clinic end generated code: output=4def5b07a8be1b3b input=e8caf4353a28e28e]*/ { +#ifndef MS_WINDOWS_DESKTOP + return NULL; +#else return PyLong_FromUnsignedLong(GetOEMCP()); +#endif } /*[clinic input]