| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 465b3b8 commit fe2b470
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,19 @@ typedef PyObject* (*TrampolineFunc)(int* success, | |||
| 47 | 47 | PyObject* args, | |
| 48 | 48 | PyObject* kw); | |
| 49 | 49 | ||
| 50 | + // Lets JS reach _PyRuntime without it being in -sEXPORTED_FUNCTIONS. | ||
| 51 | + EMSCRIPTEN_KEEPALIVE _PyRuntimeState *const _PyEM_runtime = &_PyRuntime; | ||
| 52 | + | ||
| 53 | + // Its table slot is taken over by the wasm-gc trampoline, so the table | ||
| 54 | + // never grows. | ||
| 55 | + static PyObject* | ||
| 56 | + trampoline_placeholder(int* success, PyCFunctionWithKeywords func, | ||
| 57 | + PyObject* self, PyObject* args, PyObject* kw) | ||
| 58 | + { | ||
| 59 | + Py_FatalError("Emscripten trampoline slot was not set up"); | ||
| 60 | + } | ||
| 61 | + EMSCRIPTEN_KEEPALIVE const TrampolineFunc _PyEM_trampoline_slot = trampoline_placeholder; | ||
| 62 | + | ||
| 50 | 63 | /** | |
| 51 | 64 | * Backwards compatible trampoline works with all JS runtimes | |
| 52 | 65 | */ | |
@@ -79,7 +92,9 @@ function getPyEMTrampolinePtr() { | |||
| 79 | 92 | const trampolineInstance = new WebAssembly.Instance(trampolineModule, { | |
| 80 | 93 | env: { __indirect_function_table: wasmTable, memory: wasmMemory }, | |
| 81 | 94 | }); | |
| 82 | - return addFunction(trampolineInstance.exports.trampoline_call); | ||
| 95 | + const slot = HEAPU32[__PyEM_trampoline_slot / 4]; | ||
| 96 | + wasmTable.set(slot, trampolineInstance.exports.trampoline_call); | ||
| 97 | + return slot; | ||
| 83 | 98 | } | |
| 84 | 99 | // We have to be careful to work correctly with memory snapshots -- the value of | |
| 85 | 100 | // _PyRuntimeState.emscripten_trampoline needs to reflect whether wasm-gc is | |
@@ -90,12 +105,12 @@ function getPyEMTrampolinePtr() { | |||
| 90 | 105 | addOnPreRun(function setEmscriptenTrampoline() { | |
| 91 | 106 | const ptr = getPyEMTrampolinePtr(); | |
| 92 | 107 | const offset = HEAP32[__PyEM_EMSCRIPTEN_TRAMPOLINE_OFFSET / 4]; | |
| 93 | - HEAP32[(__PyRuntime + offset) / 4] = ptr; | ||
| 108 | + HEAP32[(HEAPU32[__PyEM_runtime / 4] + offset) / 4] = ptr; | ||
| 94 | 109 | }); | |
| 95 | 110 | ); | |
| 96 | 111 | ||
| 97 | 112 | EM_JS_DEPS(_PyEM_TrampolineCall, | |
| 98 | - "$wasmTable,$wasmMemory,$addFunction,$addOnPreRun"); | ||
| 113 | + "$wasmTable,$wasmMemory,$addOnPreRun"); | ||
| 99 | 114 | ||
| 100 | 115 | PyObject* | |
| 101 | 116 | _PyEM_TrampolineCall(PyCFunctionWithKeywords func, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2440,7 +2440,7 @@ AS_CASE([$ac_sys_system], | |||
| 2440 | 2440 | dnl Include file system support | |
| 2441 | 2441 | AS_VAR_APPEND([LINKFORSHARED], [" -sFORCE_FILESYSTEM -lidbfs.js -lnodefs.js -lproxyfs.js -lworkerfs.js"]) | |
| 2442 | 2442 | AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_RUNTIME_METHODS=FS,callMain,ENV,HEAPU32,TTY,ERRNO_CODES"]) | |
| 2443 | - AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,_PyGILState_GetThisThreadState,__PyEM_EMSCRIPTEN_TRAMPOLINE_OFFSET"]) | ||
| 2443 | + AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,_PyGILState_GetThisThreadState,__PyEM_EMSCRIPTEN_TRAMPOLINE_OFFSET"]) | ||
| 2444 | 2444 | AS_VAR_APPEND([LINKFORSHARED], [" -sSTACK_SIZE=5MB"]) | |
| 2445 | 2445 | dnl Avoid bugs in JS fallback string decoding path | |
| 2446 | 2446 | AS_VAR_APPEND([LINKFORSHARED], [" -sTEXTDECODER=2"]) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments