From 0da9a0ce608e5b009b2fa7991bd9d77db0734e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Fri, 21 Feb 2025 19:24:41 +0100 Subject: [PATCH 1/3] gh-128627: Skip wasm-gc on iOS Safari where it's broken As of iOS 18.3.1, enabling wasm-gc is making the interpreter fail to load. Downstream pyodide issue: pyodide/pyodide#5428. macOS Safari 18.3 does not surface the issue. Confirmed on device that disabling this restores interpreter function. --- Python/emscripten_trampoline.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Python/emscripten_trampoline.c b/Python/emscripten_trampoline.c index 0293c7ea0f37ad..76b01223586e13 100644 --- a/Python/emscripten_trampoline.c +++ b/Python/emscripten_trampoline.c @@ -78,6 +78,10 @@ EM_JS(CountArgsFunc, _PyEM_GetCountArgsPtr, (), { // ) // ) addOnPreRun(() => { + let isIOS = /iPad|iPhone|iPod/.test(navigator.platform); + if (isIOS) { + return; + } // Try to initialize countArgsFunc const code = new Uint8Array([ 0x00, 0x61, 0x73, 0x6d, // \0asm magic number From 0c2b94ea875599698d5a172fafb7cc24a80a6301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Sun, 23 Feb 2025 16:05:57 +0100 Subject: [PATCH 2/3] Don't skip count-args-pointer generation --- Python/emscripten_trampoline.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Python/emscripten_trampoline.c b/Python/emscripten_trampoline.c index 76b01223586e13..10bb7b3aedc83b 100644 --- a/Python/emscripten_trampoline.c +++ b/Python/emscripten_trampoline.c @@ -77,11 +77,13 @@ EM_JS(CountArgsFunc, _PyEM_GetCountArgsPtr, (), { // i32.const -1 // ) // ) -addOnPreRun(() => { + +function getPyEMCountArgsPtr() { let isIOS = /iPad|iPhone|iPod/.test(navigator.platform); if (isIOS) { - return; + return 0; } + // Try to initialize countArgsFunc const code = new Uint8Array([ 0x00, 0x61, 0x73, 0x6d, // \0asm magic number @@ -153,15 +155,19 @@ addOnPreRun(() => { 0x41, 0x7f, // i32.const -1 0x0b // end function ]); - let ptr = 0; try { const mod = new WebAssembly.Module(code); const inst = new WebAssembly.Instance(mod, { e: { t: wasmTable } }); - ptr = addFunction(inst.exports.f); + return addFunction(inst.exports.f); } catch (e) { // If something goes wrong, we'll null out _PyEM_CountFuncParams and fall // back to the JS trampoline. + return 0; } +} + +addOnPreRun(() => { + const ptr = getPyEMCountArgsPtr(); Module._PyEM_CountArgsPtr = ptr; const offset = HEAP32[__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET / 4]; HEAP32[(__PyRuntime + offset) / 4] = ptr; From 2d706e62e07e4b67e98c1d7fefdd629888db2783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Sun, 23 Feb 2025 16:10:46 +0100 Subject: [PATCH 3/3] Don't use navigator if it doesn't exist (hi, Node) Co-authored-by: Hood Chatham --- Python/emscripten_trampoline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/emscripten_trampoline.c b/Python/emscripten_trampoline.c index 10bb7b3aedc83b..a7bb685bf3dc6d 100644 --- a/Python/emscripten_trampoline.c +++ b/Python/emscripten_trampoline.c @@ -79,7 +79,7 @@ EM_JS(CountArgsFunc, _PyEM_GetCountArgsPtr, (), { // ) function getPyEMCountArgsPtr() { - let isIOS = /iPad|iPhone|iPod/.test(navigator.platform); + let isIOS = globalThis.navigator && /iPad|iPhone|iPod/.test(navigator.platform); if (isIOS) { return 0; }