From c0c7adf28d1e454b393b860407b632263911e179 Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Sat, 25 Jul 2026 19:46:26 +0200 Subject: [PATCH] gh-152433: Windows: fix ``ctypes`` MemoryError in UWP build UWP does not allow allocating memory with code execution permissions. --- Modules/_ctypes/malloc_closure.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index 62c7aa5d6affbf..967a7612298f65 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -68,10 +68,17 @@ static void more_core(void) /* allocate a memory block */ #ifdef MS_WIN32 +#ifdef MS_WINDOWS_DESKTOP item = (ITEM *)VirtualAlloc(NULL, count * sizeof(ITEM), MEM_COMMIT, PAGE_EXECUTE_READWRITE); +#else + item = (ITEM*)VirtualAllocFromApp(NULL, + count * sizeof(ITEM), + MEM_COMMIT | MEM_RESERVE, + PAGE_READWRITE); +#endif if (item == NULL) return; #else