Skip to content

Commit 03d0add

Browse files
committed
u
1 parent cdec41d commit 03d0add

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

libmimalloc-sys/build.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,47 @@ fn patch_apple_tls_model_for_v3() {
5555
return;
5656
}
5757

58-
const OLD: &str = "#if defined(_WIN32)\n #define MI_TLS_MODEL_DYNAMIC_WIN32 1 \n#elif defined(__APPLE__) && MI_HAS_TLS_SLOT && !defined(__POWERPC__) // macOS on arm64 or x64\n // #define MI_TLS_MODEL_DYNAMIC_PTHREADS 1 // also works but a bit slower\n #define MI_TLS_MODEL_FIXED_SLOT 1\n #define MI_TLS_MODEL_FIXED_SLOT_DEFAULT 108 // seems unused. @apple: it would be great to get 2 official slots for custom allocators :-)\n #define MI_TLS_MODEL_FIXED_SLOT_CACHED 109\n // we used before __PTK_FRAMEWORK_OLDGC_KEY9 (89) but that seems used now.\n // see <https://github.com/rweichler/substrate/blob/master/include/pthread_machdep.h>\n#elif defined(__APPLE__) || defined(__OpenBSD__) || defined(__ANDROID__)\n #define MI_TLS_MODEL_DYNAMIC_PTHREADS 1\n // #define MI_TLS_MODEL_DYNAMIC_PTHREADS_DEFAULT_ENTRY_IS_NULL 1\n#else\n #define MI_TLS_MODEL_THREAD_LOCAL 1\n#endif";
58+
// The block we're looking for in upstream's prim.h (v3.3.2).
59+
// Each line is a separate string literal joined by concat! — preserves
60+
// exact whitespace (including trailing spaces) and is immune to editor
61+
// "trim trailing whitespace" settings.
62+
const OLD: &str = concat!(
63+
"#if defined(_WIN32)\n",
64+
" #define MI_TLS_MODEL_DYNAMIC_WIN32 1 \n",
65+
"#elif defined(__APPLE__) && MI_HAS_TLS_SLOT && !defined(__POWERPC__) // macOS on arm64 or x64\n",
66+
" // #define MI_TLS_MODEL_DYNAMIC_PTHREADS 1 // also works but a bit slower\n",
67+
" #define MI_TLS_MODEL_FIXED_SLOT 1\n",
68+
" #define MI_TLS_MODEL_FIXED_SLOT_DEFAULT 108 // seems unused. @apple: it would be great to get 2 official slots for custom allocators :-)\n",
69+
" #define MI_TLS_MODEL_FIXED_SLOT_CACHED 109\n",
70+
" // we used before __PTK_FRAMEWORK_OLDGC_KEY9 (89) but that seems used now.\n",
71+
" // see <https://github.com/rweichler/substrate/blob/master/include/pthread_machdep.h>\n",
72+
"#elif defined(__APPLE__) || defined(__OpenBSD__) || defined(__ANDROID__)\n",
73+
" #define MI_TLS_MODEL_DYNAMIC_PTHREADS 1\n",
74+
" // #define MI_TLS_MODEL_DYNAMIC_PTHREADS_DEFAULT_ENTRY_IS_NULL 1\n",
75+
"#else\n",
76+
" #define MI_TLS_MODEL_THREAD_LOCAL 1\n",
77+
"#endif",
78+
);
5979

60-
const NEW: &str = "#if defined(_WIN32)\n #define MI_TLS_MODEL_DYNAMIC_WIN32 1\n// --- mimalloc-safe vendor patch: Apple uses THREAD_LOCAL + RECURSE_GUARD ---\n// See libmimalloc-sys/build.rs::patch_apple_tls_model_for_v3 for rationale.\n#elif defined(__APPLE__) && !defined(__POWERPC__) // macOS on arm64 or x64\n #define MI_TLS_MODEL_THREAD_LOCAL 1\n #ifndef MI_TLS_RECURSE_GUARD\n #define MI_TLS_RECURSE_GUARD 1\n #endif\n// --- end mimalloc-safe vendor patch ---\n#elif defined(__OpenBSD__) || defined(__ANDROID__)\n #define MI_TLS_MODEL_DYNAMIC_PTHREADS 1\n // #define MI_TLS_MODEL_DYNAMIC_PTHREADS_DEFAULT_ENTRY_IS_NULL 1\n#else\n #define MI_TLS_MODEL_THREAD_LOCAL 1\n#endif";
80+
// Replacement: route Apple to THREAD_LOCAL + RECURSE_GUARD.
81+
const NEW: &str = concat!(
82+
"#if defined(_WIN32)\n",
83+
" #define MI_TLS_MODEL_DYNAMIC_WIN32 1\n",
84+
"// --- mimalloc-safe vendor patch: Apple uses THREAD_LOCAL + RECURSE_GUARD ---\n",
85+
"// See libmimalloc-sys/build.rs::patch_apple_tls_model_for_v3 for rationale.\n",
86+
"#elif defined(__APPLE__) && !defined(__POWERPC__) // macOS on arm64 or x64\n",
87+
" #define MI_TLS_MODEL_THREAD_LOCAL 1\n",
88+
" #ifndef MI_TLS_RECURSE_GUARD\n",
89+
" #define MI_TLS_RECURSE_GUARD 1\n",
90+
" #endif\n",
91+
"// --- end mimalloc-safe vendor patch ---\n",
92+
"#elif defined(__OpenBSD__) || defined(__ANDROID__)\n",
93+
" #define MI_TLS_MODEL_DYNAMIC_PTHREADS 1\n",
94+
" // #define MI_TLS_MODEL_DYNAMIC_PTHREADS_DEFAULT_ENTRY_IS_NULL 1\n",
95+
"#else\n",
96+
" #define MI_TLS_MODEL_THREAD_LOCAL 1\n",
97+
"#endif",
98+
);
6199

62100
assert!(
63101
content.contains(OLD),

0 commit comments

Comments
 (0)