diff options
author | Christian Heimes <christian@python.org> | 2022-03-30 19:28:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-30 19:28:33 (GMT) |
commit | 581c4434de62d9d36392f10e65866c081fb18d71 (patch) | |
tree | 8c7f01b8826e7f11bbe9a344612bb0187e2e4e8e /Objects/methodobject.c | |
parent | 795c00b91cbc208969302e9e16a269c2049af3e9 (diff) | |
download | cpython-581c4434de62d9d36392f10e65866c081fb18d71.zip cpython-581c4434de62d9d36392f10e65866c081fb18d71.tar.gz cpython-581c4434de62d9d36392f10e65866c081fb18d71.tar.bz2 |
bpo-47162: Add call trampoline to mitigate bad fpcasts on Emscripten (GH-32189)
Diffstat (limited to 'Objects/methodobject.c')
-rw-r--r-- | Objects/methodobject.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 93fac22..8bcb1e0 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -483,7 +483,8 @@ cfunction_vectorcall_NOARGS( if (meth == NULL) { return NULL; } - PyObject *result = meth(PyCFunction_GET_SELF(func), NULL); + PyObject *result = _PyCFunction_TrampolineCall( + meth, PyCFunction_GET_SELF(func), NULL); _Py_LeaveRecursiveCall(tstate); return result; } @@ -510,7 +511,8 @@ cfunction_vectorcall_O( if (meth == NULL) { return NULL; } - PyObject *result = meth(PyCFunction_GET_SELF(func), args[0]); + PyObject *result = _PyCFunction_TrampolineCall( + meth, PyCFunction_GET_SELF(func), args[0]); _Py_LeaveRecursiveCall(tstate); return result; } @@ -537,7 +539,9 @@ cfunction_call(PyObject *func, PyObject *args, PyObject *kwargs) PyObject *result; if (flags & METH_KEYWORDS) { - result = (*(PyCFunctionWithKeywords)(void(*)(void))meth)(self, args, kwargs); + result = _PyCFunctionWithKeywords_TrampolineCall( + (*(PyCFunctionWithKeywords)(void(*)(void))meth), + self, args, kwargs); } else { if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) { @@ -546,7 +550,15 @@ cfunction_call(PyObject *func, PyObject *args, PyObject *kwargs) ((PyCFunctionObject*)func)->m_ml->ml_name); return NULL; } - result = meth(self, args); + result = _PyCFunction_TrampolineCall(meth, self, args); } 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 |