Skip to content

Commit 1330862

Browse files
ambvhoodmane
authored andcommitted
Skip wasm-gc on iOS Safari where it's borked (pyodide#5445)
As of iOS 18.3.1, enabling wasm-gc is making the interpreter fail to load. Upstream pull request: python/cpython#130418. macOS Safari 18.3 does not surface the issue. Confirmed on device that disabling this restores interpreter function. Resolves pyodide#5428.
1 parent 6ff0877 commit 1330862

10 files changed

+87
-24
lines changed

cpython/patches/0001-Public-pymain_run_python.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From c37e3894a271ee8b406ffc41a0ce6f5c248914ee Mon Sep 17 00:00:00 2001
1+
From f8a9e2d38252a032bdb617db396a047154f1bb6e Mon Sep 17 00:00:00 2001
22
From: Hood Chatham <[email protected]>
33
Date: Sun, 17 Jul 2022 14:40:39 +0100
4-
Subject: [PATCH 1/8] Public pymain_run_python
4+
Subject: [PATCH 1/9] Public pymain_run_python
55

66
Discussion here:
77
https://discuss.python.org/t/unstable-api-for-pymain-run-python-run-python-cli-but-dont-finalize-interpreter/44675
@@ -23,5 +23,5 @@ index b602272b78b..d06d3c926b9 100644
2323
{
2424
PyObject *main_importer_path = NULL;
2525
--
26-
2.34.1
26+
2.48.1
2727

cpython/patches/0002-Add-emscripten-platform-support-to-ctypes.util.find_.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 83ce578076b86b0231739b81ed9231bf8d9ca800 Mon Sep 17 00:00:00 2001
1+
From 74f68027172f2b646b8ab9a8d73380b12f864cb7 Mon Sep 17 00:00:00 2001
22
From: ryanking13 <[email protected]>
33
Date: Fri, 2 Dec 2022 11:36:44 +0000
4-
Subject: [PATCH 2/8] Add emscripten platform support to
4+
Subject: [PATCH 2/9] Add emscripten platform support to
55
ctypes.util.find_library
66

77
---
@@ -44,5 +44,5 @@ index c550883e7c7..c25c8f63e77 100644
4444
# AIX has two styles of storing shared libraries
4545
# GNU auto_tools refer to these as svr4 and aix
4646
--
47-
2.34.1
47+
2.48.1
4848

cpython/patches/0003-Allow-multiprocessing.connection-top-level-import.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From da79a0ddc090407c1ea1d8e25da67931d1863642 Mon Sep 17 00:00:00 2001
1+
From 32155f0ed7043dde694b7910db46f4c97f2e41d9 Mon Sep 17 00:00:00 2001
22
From: Hood Chatham <[email protected]>
33
Date: Mon, 19 Dec 2022 09:09:14 -0800
4-
Subject: [PATCH 3/8] Allow multiprocessing.connection top level import
4+
Subject: [PATCH 3/9] Allow multiprocessing.connection top level import
55

66
Upstream PR:
77
https://github.com/python/cpython/pull/114808
@@ -26,5 +26,5 @@ index d0582e3cd54..b96b2454d3d 100644
2626
from . import util
2727

2828
--
29-
2.34.1
29+
2.48.1
3030

cpython/patches/0004-Make-Emscripten-trampolines-work-with-JSPI.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From b86ebf295ad48ade5810032e83f98edb0e642abf Mon Sep 17 00:00:00 2001
1+
From a761e476e8abab81106ed4f8b4422732404b65d2 Mon Sep 17 00:00:00 2001
22
From: Hood Chatham <[email protected]>
33
Date: Wed, 28 Jun 2023 10:46:19 -0700
4-
Subject: [PATCH 4/8] Make Emscripten trampolines work with JSPI
4+
Subject: [PATCH 4/9] Make Emscripten trampolines work with JSPI
55

66
There is a WIP proposal to enable webassembly stack switching which have been
77
implemented in v8:
@@ -382,5 +382,5 @@ index d0d54050286..85c6d2f71ae 100644
382382
)
383383
AC_SUBST([PLATFORM_HEADERS])
384384
--
385-
2.34.1
385+
2.48.1
386386

cpython/patches/0005-Use-wasm-gc-based-call-adaptor-if-available.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 2d2732b55d57008545e818fc1b5ef4dca5625b9e Mon Sep 17 00:00:00 2001
1+
From 13370805f9652e70bc19447381443afde82c9b93 Mon Sep 17 00:00:00 2001
22
From: Hood Chatham <[email protected]>
33
Date: Tue, 22 Oct 2024 15:16:03 +0200
4-
Subject: [PATCH 5/8] Use wasm-gc based call adaptor if available
4+
Subject: [PATCH 5/9] Use wasm-gc based call adaptor if available
55

66
Part of the ongoing quest to support JSPI. The JSPI spec removed its dependence on
77
JS type reflection, and now the plan is for runtimes to ship JSPI while keeping
@@ -408,5 +408,5 @@ index a7981bc4877..ab03729266c 100644
408408

409409
PyStatus
410410
--
411-
2.34.1
411+
2.48.1
412412

cpython/patches/0006-Fix-LONG_BIT-constant-to-be-always-32bit.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From d9e6867695c02c07420d8a15d4ae1b96ea41f553 Mon Sep 17 00:00:00 2001
1+
From 6f2d305e8eba14fd3c49f54790f13c19fa41860b Mon Sep 17 00:00:00 2001
22
From: ryanking13 <[email protected]>
33
Date: Fri, 12 Jan 2024 00:52:57 +0900
4-
Subject: [PATCH 6/8] Fix LONG_BIT constant to be always 32bit
4+
Subject: [PATCH 6/9] Fix LONG_BIT constant to be always 32bit
55

66
Starting from Emscripten 3.1.50, there is an issue where LONG_BIT is
77
calculated to 64 for some reason. This is very strange because LONG_MAX
@@ -29,5 +29,5 @@ index e2bac3bf504..ae1c1a40260 100644
2929
#define LONG_BIT (8 * SIZEOF_LONG)
3030
#endif
3131
--
32-
2.34.1
32+
2.48.1
3333

cpython/patches/0007-Warn-if-ZoneInfo-is-imported-without-tzdata.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From a35c57ed8c7f2657a7a82d900184ebe649dedfdf Mon Sep 17 00:00:00 2001
1+
From 566d1c20df2370c4a47f21561086fb7e5f51299c Mon Sep 17 00:00:00 2001
22
From: Hood Chatham <[email protected]>
33
Date: Thu, 25 Jul 2024 14:28:57 +0200
4-
Subject: [PATCH 7/8] Warn if ZoneInfo is imported without tzdata
4+
Subject: [PATCH 7/9] Warn if ZoneInfo is imported without tzdata
55

66
---
77
Lib/zoneinfo/_common.py | 6 ++++++
@@ -25,5 +25,5 @@ index 98cdfe37ca6..35d19eae9f0 100644
2525
# to "we cannot find this key":
2626
#
2727
--
28-
2.34.1
28+
2.48.1
2929

cpython/patches/0008-Add-call-to-JsProxy_GetMethod-to-help-remove-tempora.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From ff4534318481437542f2e49348033a00354a069d Mon Sep 17 00:00:00 2001
1+
From f09bfe83d146697b936799d97d8fe0110c61b86d Mon Sep 17 00:00:00 2001
22
From: Hood Chatham <[email protected]>
33
Date: Thu, 25 Jul 2024 14:41:37 +0200
4-
Subject: [PATCH 8/8] Add call to `JsProxy_GetMethod` to help remove temporary
4+
Subject: [PATCH 8/9] Add call to `JsProxy_GetMethod` to help remove temporary
55

66
`_PyObject_GetMethod` is a special attribute lookup function that won't call the
77
`__get__` descriptor on a method to avoid creating a temporary PyMethodObject.
@@ -56,5 +56,5 @@ index 6b2e0aeaab9..9240b33b08a 100644
5656
*method = PyObject_GetAttr(obj, name);
5757
return 0;
5858
--
59-
2.34.1
59+
2.48.1
6060

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
From c627686651a46118b2a653fa61673dfc158442d4 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?=C5=81ukasz=20Langa?= <[email protected]>
3+
Date: Fri, 21 Feb 2025 19:24:41 +0100
4+
Subject: [PATCH 9/9] Skip wasm-gc on iOS Safari where it's broken
5+
6+
As of iOS 18.3.1, enabling wasm-gc is making the interpreter fail to load.
7+
Downstream pyodide issue: pyodide/pyodide#5428.
8+
9+
macOS Safari 18.3 does not surface the issue.
10+
11+
Confirmed on device that disabling this restores interpreter function.
12+
---
13+
Python/emscripten_trampoline.c | 16 +++++++++++++---
14+
1 file changed, 13 insertions(+), 3 deletions(-)
15+
16+
diff --git a/Python/emscripten_trampoline.c b/Python/emscripten_trampoline.c
17+
index e78a94e5e99..ff57f9e91d8 100644
18+
--- a/Python/emscripten_trampoline.c
19+
+++ b/Python/emscripten_trampoline.c
20+
@@ -79,7 +79,13 @@ EM_JS(CountArgsFunc, _PyEM_GetCountArgsPtr, (), {
21+
// i32.const -1
22+
// )
23+
// )
24+
-addOnPreRun(() => {
25+
+
26+
+function getPyEMCountArgsPtr() {
27+
+ let isIOS = globalThis.navigator && /iPad|iPhone|iPod/.test(navigator.platform);
28+
+ if (isIOS) {
29+
+ return 0;
30+
+ }
31+
+
32+
// Try to initialize countArgsFunc
33+
const code = new Uint8Array([
34+
0x00, 0x61, 0x73, 0x6d, // \0asm magic number
35+
@@ -151,15 +157,19 @@ addOnPreRun(() => {
36+
0x41, 0x7f, // i32.const -1
37+
0x0b // end function
38+
]);
39+
- let ptr = 0;
40+
try {
41+
const mod = new WebAssembly.Module(code);
42+
const inst = new WebAssembly.Instance(mod, { e: { t: wasmTable } });
43+
- ptr = addFunction(inst.exports.f);
44+
+ return addFunction(inst.exports.f);
45+
} catch (e) {
46+
// If something goes wrong, we'll null out _PyEM_CountFuncParams and fall
47+
// back to the JS trampoline.
48+
+ return 0;
49+
}
50+
+}
51+
+
52+
+addOnPreRun(() => {
53+
+ const ptr = getPyEMCountArgsPtr();
54+
Module._PyEM_CountArgsPtr = ptr;
55+
const offset = HEAP32[__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET / 4];
56+
HEAP32[(__PyRuntime + offset) / 4] = ptr;
57+
--
58+
2.48.1
59+

docs/project/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ _Insert Date Here_
2020

2121
- Added the `context` parameter to `WebLoop.create_task()` {pr}`5431`
2222
- {{ Fix }} `mountNativeFS` API now correctly propagates the error. {pr}`5434`
23+
- {{ Fix }} Since 0.27.1, Pyodide has been broken in iOS because iOS ships
24+
broken wasm-gc support. Pyodide feature detects whether the runtime supports
25+
wasm-gc and uses it if it is present. Unfortunately, iOS passes the feature
26+
detection but wasm-gc doesn't work as expected. {pr}`5445`
2327

2428
### Packages
2529

0 commit comments

Comments
 (0)