-
Notifications
You must be signed in to change notification settings - Fork 67
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
Get SafeCfunction by @safe_cfunction on c++ side not working correctly #466
Comments
Obviously if i change ptr inside macro safe_cfunction(f, rt, args)
return esc(:($(@__MODULE__).SafeCFunction(@cfunction($f, $rt, $args), $rt, [$(args.args...)])))
end Only So i add my version of macro as follows macro safe_cfunction_cpp(f, rt, args)
return esc(:($(@__MODULE__).CxxWrap.CxxWrapCore._SafeCFunction(@cfunction($f, $rt, $args), $rt, [$(args.args...)])))
end Dont get about cconverter which should do exactly what i need, yet. |
I managed to get it to work by modifying the C++ code like this: jl_value_t *ret = jl_eval_string(R"(
summy(x,y) = x+y
@safe_cfunction(summy, Cint, (Cint, Cint))
)");
jlcxx::SafeCFunction cFunc = jlcxx::unbox<jlcxx::SafeCFunction>(ret);
cFunc.fptr = jlcxx::unbox<void*>((jl_value_t*)cFunc.fptr); // no idea why the pointer itself is also boxed here
auto fptr = jlcxx::make_function_pointer<int(int, int)>(cFunc);
return fptr(a, b); It seems the pointer that comes back out is still boxed. I think the reason for that is that |
Hi.
I discovered amazing functionality with
SafeCfunction
which i previously try to write on my own.Its perfectly worked trough the julia, but not with c++.
What i'm trying to do is to get
SafeCfunction
and cast.Signature checked correctly
( with swapped types in message:
for exmaple with wrong signature, for above code, as follows
int(double, int)
i got the following (types should be swapped):Incorrect argument type for cfunction at position 1, expected: Float64, obtained: Int32
)But void pointer stored inside
SafeCfunction
is broken and function call crash.Is there some trick to build SafeCfunction from c++? (i could bind function to add SafeCfunction into some container which i access from c++, but why it isnt working directly )
Thanks
The text was updated successfully, but these errors were encountered: