-
Notifications
You must be signed in to change notification settings - Fork 66
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
How to avoid deep type piracy? #458
Comments
This can be avoided by using a small lambda function instead of the member-function pointer, i.e.: type.method("+", [](const Hist& h, double f) { return h+f; });
type.method("+", [](const Hist& h, const Hist& f) { return h+f; }); Then the generated functions will be more strict regarding the arguments (and only allow What happens in the original code is the following:For a member function libcxxwrap-julia generates two methods, one for the /// Define a member function, const version
template<typename R, typename CT, typename... ArgsT, typename... Extra>
TypeWrapper<T>& method(const std::string& name, R(CT::*f)(ArgsT...) const, Extra... extra)
{
m_module.method(name, [f](const T& obj, ArgsT... args) -> R { return (obj.*f)(args...); }, extra... );
m_module.method(name, [f](const T* obj, ArgsT... args) -> R { return ((*obj).*f)(args...); }, extra... );
return *this;
} Which results in these CppFuntionInfo: CxxWrap.CxxWrapCore.CppFunctionInfo(:+, Any[ConstCxxRef{Main.Types.Hist}, Float64], Any, Main.Types.HistAllocated, Ptr{Nothing} @0x00007f6393220600, Ptr{Nothing} @0x000000002585c150, Base, "", Any[], Any[], 0)
CxxWrap.CxxWrapCore.CppFunctionInfo(:+, Any[ConstCxxPtr{Main.Types.Hist}, Float64], Any, Main.Types.HistAllocated, Ptr{Nothing} @0x00007f639321c520, Ptr{Nothing} @0x0000000027d36930, Base, "", Any[], Any[], 0) But CxxWrap will allow Line 575 in ad11b16
producing this signature: :((Base).:+(arg1::Union{Ptr{Nothing}, ConstCxxPtr{<:Main.Types.Hist}, CxxPtr{<:Main.Types.Hist}}, arg2::Union{Float64, Int64, Irrational}; )::Main.Types.HistAllocated |
Thanks very much for the explanation and way out. I have tested and indeed with lambdas I get the signature:
The problem I have now is that the wrapper code is genererated by WrapIt.jl and I need to find out why is using |
Lambda function are now systemtically used in Module::module() calls.
While wrapping a C++ type that provides operator+ breaks the REPL in a very unexpected manner. For example using the
?
to get the help of a entity, the wrapped operator is selected by the multiple-dispatch when trying to call the function+(arg1::Ptr{Nothing}, arg2::Int64)
. Here is the error:I am attaching a reproducer.
and the Julia code to trigger the error:
The text was updated successfully, but these errors were encountered: