1- #ifndef Py_EMSCRIPTEN_TRAMPOLINE_H
2- #define Py_EMSCRIPTEN_TRAMPOLINE_H
1+ #ifndef Py_WASM_TRAMPOLINE_H
2+ #define Py_WASM_TRAMPOLINE_H
33
4- #include "pycore_typedefs .h" // _PyRuntimeState
4+ #include "Python .h"
55
66/**
77 * C function call trampolines to mitigate bad function pointer casts.
1818 * with 0/NULL in function pointer cast. Compilers do not show warnings when a
1919 * function pointer is explicitly casted to an incompatible type.
2020 *
21- * Bad fpcasts are an issue in WebAssembly. WASM 's indirect_call has strict
21+ * Bad fpcasts are an issue in WebAssembly. Wasm 's indirect_call has strict
2222 * function signature checks. Argument count, types, and return type must match.
2323 *
2424 * Third party code unintentionally rely on problematic fpcasts. The call
25- * trampoline mitigates common occurrences of bad fpcasts on Emscripten .
25+ * trampoline mitigates common occurrences of bad fpcasts on Wasm targets .
2626 */
2727
28- #if defined(__EMSCRIPTEN__ ) && defined(PY_CALL_TRAMPOLINE )
28+ #if defined(__wasm__ ) && defined(PY_CALL_TRAMPOLINE )
2929
3030PyObject *
31- _PyEM_TrampolineCall (PyCFunctionWithKeywords func ,
32- PyObject * self ,
33- PyObject * args ,
34- PyObject * kw );
31+ _PyWasm_TrampolineCall (PyCFunctionWithKeywords func ,
32+ PyObject * self ,
33+ PyObject * args ,
34+ PyObject * kw );
35+
36+ int
37+ _PyWasm_TrampolineCallSetter (setter func ,
38+ PyObject * self ,
39+ PyObject * val ,
40+ void * closure );
3541
3642#define _PyCFunction_TrampolineCall (meth , self , args ) \
37- _PyEM_TrampolineCall (*_PyCFunctionWithKeywords_CAST(meth), (self), (args), NULL)
43+ _PyWasm_TrampolineCall (*_PyCFunctionWithKeywords_CAST(meth), (self), (args), NULL)
3844
3945#define _PyCFunctionWithKeywords_TrampolineCall (meth , self , args , kw ) \
40- _PyEM_TrampolineCall ((meth), (self), (args), (kw))
46+ _PyWasm_TrampolineCall ((meth), (self), (args), (kw))
4147
4248#define descr_set_trampoline_call (set , obj , value , closure ) \
43- ((int)_PyEM_TrampolineCall(_PyCFunctionWithKeywords_CAST(set), (obj), \
44- (value), (PyObject*)(closure)))
49+ _PyWasm_TrampolineCallSetter((set), (obj), (value), (closure))
4550
4651#define descr_get_trampoline_call (get , obj , closure ) \
47- _PyEM_TrampolineCall(_PyCFunctionWithKeywords_CAST(get), (obj), \
48- (PyObject*)(closure), NULL)
52+ _PyWasm_TrampolineCall(_PyCFunctionWithKeywords_CAST(get), (obj), \
53+ (PyObject*)(closure), NULL)
54+
4955
56+ #else // defined(__wasm__) && defined(PY_CALL_TRAMPOLINE)
5057
51- #else // defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE)
58+ // Disable trampolines by directly calling the method.
5259
5360#define _PyCFunction_TrampolineCall (meth , self , args ) \
5461 (meth)((self), (args))
@@ -62,6 +69,6 @@ _PyEM_TrampolineCall(PyCFunctionWithKeywords func,
6269#define descr_get_trampoline_call (get , obj , closure ) \
6370 (get)((obj), (closure))
6471
65- #endif // defined(__EMSCRIPTEN__ ) && defined(PY_CALL_TRAMPOLINE)
72+ #endif // defined(__wasm__ ) && defined(PY_CALL_TRAMPOLINE)
6673
67- #endif // ndef Py_EMSCRIPTEN_SIGNAL_H
74+ #endif // ndef Py_WASM_TRAMPOLINE_H
0 commit comments