From e247bd925e2e97659a80c7fcbad1cf0f002e5276 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 21 Oct 2026 22:35:50 -0700 Subject: [PATCH 1/3] gh-159111: Mark remaining CPython-specific changes in vendored mimalloc with a comment --- Include/internal/mimalloc/mimalloc/internal.h | 2 ++ Objects/mimalloc/os.c | 1 + Objects/mimalloc/prim/unix/prim.c | 2 +- Objects/mimalloc/random.c | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Include/internal/mimalloc/mimalloc/internal.h b/Include/internal/mimalloc/mimalloc/internal.h index eb4b8c2d5dc1f02..83bf6348a5561c3 100644 --- a/Include/internal/mimalloc/mimalloc/internal.h +++ b/Include/internal/mimalloc/mimalloc/internal.h @@ -102,6 +102,8 @@ terms of the MIT license. A copy of the license can be found in the file #define mi_decl_externc #endif +// CPython: upstream defines __wasi__ on Emscripten here. It is removed so that +// CPython code can distinguish the two platforms (gh-158628). // -------------------------------------------------------------------------- // Internal functions diff --git a/Objects/mimalloc/os.c b/Objects/mimalloc/os.c index 9c9683ce594f345..ab1813a74724417 100644 --- a/Objects/mimalloc/os.c +++ b/Objects/mimalloc/os.c @@ -276,6 +276,7 @@ static void* mi_os_prim_alloc_aligned(size_t size, size_t alignment, bool commit else { // if not aligned, free it, overallocate, and unmap around it #if !MI_TRACK_ASAN + // CPython: downgraded from _mi_warning_message, the warning is noisy in the test suite (gh-112027) _mi_verbose_message("unable to allocate aligned OS memory directly, fall back to over-allocation (size: 0x%zx bytes, address: %p, alignment: 0x%zx, commit: %d)\n", size, p, alignment, commit); #endif if (p != NULL) { mi_os_prim_free(p, size, (commit ? size : 0)); } diff --git a/Objects/mimalloc/prim/unix/prim.c b/Objects/mimalloc/prim/unix/prim.c index 87b3c96ea6045c8..bb619569a1bdb12 100644 --- a/Objects/mimalloc/prim/unix/prim.c +++ b/Objects/mimalloc/prim/unix/prim.c @@ -124,7 +124,7 @@ static bool unix_detect_overcommit(void) { #if defined(__linux__) int fd = mi_prim_open("/proc/sys/vm/overcommit_memory", O_RDONLY); if (fd >= 0) { - char buf[32] = {0}; + char buf[32] = {0}; // CPython: zero-initialize to avoid an MSAN report ssize_t nread = mi_prim_read(fd, &buf, sizeof(buf)); mi_prim_close(fd); // diff --git a/Objects/mimalloc/random.c b/Objects/mimalloc/random.c index b216c4c3505568c..f19520d930cb995 100644 --- a/Objects/mimalloc/random.c +++ b/Objects/mimalloc/random.c @@ -178,7 +178,7 @@ uintptr_t _mi_os_random_weak(uintptr_t extra_seed) { } static void mi_random_init_ex(mi_random_ctx_t* ctx, bool use_weak) { - uint8_t key[32] = {0}; + uint8_t key[32] = {0}; // CPython: zero-initialize to avoid an MSAN report if (use_weak || !_mi_prim_random_buf(key, sizeof(key))) { // if we fail to get random data from the OS, we fall back to a // weak random source based on the current time From 3f5299b1222abc80551e55a8691f37dd26bc58b4 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 21 Oct 2026 22:46:52 -0700 Subject: [PATCH 2/3] gh-159111: Restore arc4random_buf() usage on Cygwin in vendored mimalloc The CPython-specific change from gh-148461 was dropped when mimalloc was updated to v2.5.2. --- Objects/mimalloc/prim/unix/prim.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Objects/mimalloc/prim/unix/prim.c b/Objects/mimalloc/prim/unix/prim.c index bb619569a1bdb12..c66198464e72a21 100644 --- a/Objects/mimalloc/prim/unix/prim.c +++ b/Objects/mimalloc/prim/unix/prim.c @@ -871,6 +871,7 @@ bool _mi_prim_random_buf(void* buf, size_t buf_len) { #elif defined(__ANDROID__) || defined(__DragonFly__) || \ defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__sun) || \ + defined(__CYGWIN__) /* CPython: gh-148461 */ || \ (defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7)) bool _mi_prim_random_buf(void* buf, size_t buf_len) { From 130a1a1351b89c7cb690023570d6198568389e9e Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 21 Oct 2026 22:47:23 -0700 Subject: [PATCH 3/3] gh-159111: Remove the mimalloc update entry from What's New in 3.16 --- Doc/whatsnew/3.16.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 09477b22d95413f..925f425aba58693 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -1295,11 +1295,6 @@ Build changes (Contributed by Stan Ulbrych, Florian Mayer and AnnaAr321 in :gh:`156049`.) -* Update the bundled `mimalloc library`_ from version 2.1.2 to 2.5.2. - (Contributed by Donghee Na in :gh:`159111`.) - - .. _mimalloc library: https://github.com/microsoft/mimalloc/ - C API changes =============