From 581c4434de62d9d36392f10e65866c081fb18d71 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 30 Mar 2022 22:28:33 +0300 Subject: bpo-47162: Add call trampoline to mitigate bad fpcasts on Emscripten (GH-32189) --- Python/import.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Python/import.c') diff --git a/Python/import.c b/Python/import.c index 982ec8cfe63..4b6d6d16821 100644 --- a/Python/import.c +++ b/Python/import.c @@ -527,7 +527,7 @@ import_find_extension(PyThreadState *tstate, PyObject *name, else { if (def->m_base.m_init == NULL) return NULL; - mod = def->m_base.m_init(); + mod = _PyImport_InitFunc_TrampolineCall(def->m_base.m_init); if (mod == NULL) return NULL; if (PyObject_SetItem(modules, name, mod) == -1) { @@ -958,6 +958,13 @@ PyImport_GetImporter(PyObject *path) return get_path_importer(tstate, path_importer_cache, path_hooks, path); } +#if defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE) +#include +EM_JS(PyObject*, _PyImport_InitFunc_TrampolineCall, (PyModInitFunction func), { + return wasmTable.get(func)(); +}); +#endif // __EMSCRIPTEN__ && PY_CALL_TRAMPOLINE + static PyObject* create_builtin(PyThreadState *tstate, PyObject *name, PyObject *spec) { @@ -973,8 +980,7 @@ create_builtin(PyThreadState *tstate, PyObject *name, PyObject *spec) /* Cannot re-init internal module ("sys" or "builtins") */ return PyImport_AddModuleObject(name); } - - mod = (*p->initfunc)(); + mod = _PyImport_InitFunc_TrampolineCall(*p->initfunc); if (mod == NULL) { return NULL; } -- cgit v1.2.3