FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-156780: Emscripten: drop the trampoline's dependence on exports by clementperon · Pull Request #157238 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ac  (1) .c  (1) No extension  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
21 changes: 18 additions & 3 deletions Python/emscripten_trampoline.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ typedef PyObject* (*TrampolineFunc)(int* success,
PyObject* args,
PyObject* kw);

// Lets JS reach _PyRuntime without it being in -sEXPORTED_FUNCTIONS.
EMSCRIPTEN_KEEPALIVE _PyRuntimeState *const _PyEM_runtime = &_PyRuntime;
Comment thread
clementperon marked this conversation as resolved.

// Its table slot is taken over by the wasm-gc trampoline, so the table
// never grows.
static PyObject*
trampoline_placeholder(int* success, PyCFunctionWithKeywords func,
PyObject* self, PyObject* args, PyObject* kw)
{
Py_FatalError("Emscripten trampoline slot was not set up");
}
EMSCRIPTEN_KEEPALIVE const TrampolineFunc _PyEM_trampoline_slot = trampoline_placeholder;

/**
* Backwards compatible trampoline works with all JS runtimes
*/
Expand Down Expand Up @@ -79,7 +92,9 @@ function getPyEMTrampolinePtr() {
const trampolineInstance = new WebAssembly.Instance(trampolineModule, {
env: { __indirect_function_table: wasmTable, memory: wasmMemory },
});
return addFunction(trampolineInstance.exports.trampoline_call);
const slot = HEAPU32[__PyEM_trampoline_slot / 4];
wasmTable.set(slot, trampolineInstance.exports.trampoline_call);
return slot;
}
// We have to be careful to work correctly with memory snapshots -- the value of
// _PyRuntimeState.emscripten_trampoline needs to reflect whether wasm-gc is
Expand All @@ -90,12 +105,12 @@ function getPyEMTrampolinePtr() {
addOnPreRun(function setEmscriptenTrampoline() {
const ptr = getPyEMTrampolinePtr();
const offset = HEAP32[__PyEM_EMSCRIPTEN_TRAMPOLINE_OFFSET / 4];
HEAP32[(__PyRuntime + offset) / 4] = ptr;
HEAP32[(HEAPU32[__PyEM_runtime / 4] + offset) / 4] = ptr;
});
);

EM_JS_DEPS(_PyEM_TrampolineCall,
"$wasmTable,$wasmMemory,$addFunction,$addOnPreRun");
"$wasmTable,$wasmMemory,$addOnPreRun");

PyObject*
_PyEM_TrampolineCall(PyCFunctionWithKeywords func,
Expand Down
2 changes: 1 addition & 1 deletion configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configure.ac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,7 @@ AS_CASE([$ac_sys_system],
dnl Include file system support
AS_VAR_APPEND([LINKFORSHARED], [" -sFORCE_FILESYSTEM -lidbfs.js -lnodefs.js -lproxyfs.js -lworkerfs.js"])
AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_RUNTIME_METHODS=FS,callMain,ENV,HEAPU32,TTY,ERRNO_CODES"])
AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,_PyGILState_GetThisThreadState,__PyEM_EMSCRIPTEN_TRAMPOLINE_OFFSET"])
AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,_PyGILState_GetThisThreadState,__PyEM_EMSCRIPTEN_TRAMPOLINE_OFFSET"])
AS_VAR_APPEND([LINKFORSHARED], [" -sSTACK_SIZE=5MB"])
dnl Avoid bugs in JS fallback string decoding path
AS_VAR_APPEND([LINKFORSHARED], [" -sTEXTDECODER=2"])
Expand Down
Loading

Back | FazBrowse Home | New Git URL