-
-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wasm32-wasi] About function pointer casting in build/static_src #3012
Comments
I am OK with these functions getting modified to specify an unused argument instead. But ideally we also it it in a way, where the cast to |
Something like? #if __wasi__
static PyObject *Nuitka_Function_get_name(PyObject *self, void *data) {
#else
static PyObject *Nuitka_Function_get_name(PyObject *self,) {
#endif
struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)self;
// ... |
Yes, but without the need for the define, just follow the signature of getter and setter:
Trailing commas wouldn't work btw. |
Highly likely there are more (not-strictly-compatible)function pointer casting in build/static_src. P.S. |
You have made excellent progress already. The ones I saw in the loader right now seem standard and PyCFunction looks like it's just more of the same. |
I notice there is a widely coding pattern in build/static_src/CompiledXType.c. It will cause a trap during execution(Step 18.) when using as a wasm32-wasi target.
Take CompiledFunctionType.c as an example.
Nuitka_Function_get_name
asstatic PyObject *Nuitka_Function_get_name(struct Nuitka_FunctionObject *function)
. With one argument.static PyGetSetDef Nuitka_Function_getset[]
, cast it togetter
(from Include/descrobject.h). It means castPyObject*(struct Nuitka_FunctionObject*)
->PyObject *(PyObject *, void *)
.Nuitka_Function_get_name
in a form likesget(obj, closure)
(getset_get()
in Objects/descrobject.c).From caller side, callee is a function with two arguments. On the other side, callee is a function with one argument. It works well in C. But it confuses wasm.
A call with function pointers will be transferred into
call_indirect
in Wasm, and pack the callee type together. During execution, there is a type check between expected function type(likePyObject*(void*,void*)
) and actually function type(PyObject*(void*)
) (all pointers are same types). Eventually, the checker will hit a trap because of different amount of arguments.P.S.
I am thinking about using a different function signature for wasm32-wasi target like:
The text was updated successfully, but these errors were encountered: