diff options
author | Hood Chatham <roberthoodchatham@gmail.com> | 2023-09-15 22:04:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-15 22:04:21 (GMT) |
commit | 6b179adb8c05801bf069121b360531d135ee3f44 (patch) | |
tree | 0ef8079fe12fed536e09162574dd759cf59b3cb1 /Objects | |
parent | 59073c9ab8eb8db9304f16c46086ccc525e82570 (diff) | |
download | cpython-6b179adb8c05801bf069121b360531d135ee3f44.zip cpython-6b179adb8c05801bf069121b360531d135ee3f44.tar.gz cpython-6b179adb8c05801bf069121b360531d135ee3f44.tar.bz2 |
gh-106213: Make Emscripten trampolines work with JSPI (GH-106219)
There is a WIP proposal to enable webassembly stack switching which have been
implemented in v8:
https://github.com/WebAssembly/js-promise-integration
It is not possible to switch stacks that contain JS frames so the Emscripten JS
trampolines that allow calling functions with the wrong number of arguments
don't work in this case. However, the js-promise-integration proposal requires
the [type reflection for Wasm/JS API](https://github.com/WebAssembly/js-types)
proposal, which allows us to actually count the number of arguments a function
expects.
For better compatibility with stack switching, this PR checks if type reflection
is available, and if so we use a switch block to decide the appropriate
signature. If type reflection is unavailable, we should use the current EMJS
trampoline.
We cache the function argument counts since when I didn't cache them performance
was negatively affected.
Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: Brett Cannon <brett@python.org>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/descrobject.c | 20 | ||||
-rw-r--r-- | Objects/methodobject.c | 7 |
2 files changed, 1 insertions, 26 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c index a744c3d..56ce34f 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -4,6 +4,7 @@ #include "pycore_abstract.h" // _PyObject_RealIsSubclass() #include "pycore_call.h" // _PyStack_AsDict() #include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate() +#include "pycore_emscripten_trampoline.h" // descr_set_trampoline_call(), descr_get_trampoline_call() #include "pycore_descrobject.h" // _PyMethodWrapper_Type #include "pycore_object.h" // _PyObject_GC_UNTRACK() #include "pycore_pystate.h" // _PyThreadState_GET() @@ -16,25 +17,6 @@ class property "propertyobject *" "&PyProperty_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=556352653fd4c02e]*/ -// see pycore_object.h -#if defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE) -#include <emscripten.h> -EM_JS(int, descr_set_trampoline_call, (setter set, PyObject *obj, PyObject *value, void *closure), { - return wasmTable.get(set)(obj, value, closure); -}); - -EM_JS(PyObject*, descr_get_trampoline_call, (getter get, PyObject *obj, void *closure), { - return wasmTable.get(get)(obj, closure); -}); -#else -#define descr_set_trampoline_call(set, obj, value, closure) \ - (set)((obj), (value), (closure)) - -#define descr_get_trampoline_call(get, obj, closure) \ - (get)((obj), (closure)) - -#endif // __EMSCRIPTEN__ && PY_CALL_TRAMPOLINE - static void descr_dealloc(PyDescrObject *descr) { diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 521c905..b40b282 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -553,10 +553,3 @@ cfunction_call(PyObject *func, PyObject *args, PyObject *kwargs) return _Py_CheckFunctionResult(tstate, func, result, NULL); } -#if defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE) -#include <emscripten.h> - -EM_JS(PyObject*, _PyCFunctionWithKeywords_TrampolineCall, (PyCFunctionWithKeywords func, PyObject *self, PyObject *args, PyObject *kw), { - return wasmTable.get(func)(self, args, kw); -}); -#endif |