Skip to content
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

Failures after #338 #400

Closed
dannys4 opened this issue Jan 12, 2024 · 3 comments
Closed

Failures after #338 #400

dannys4 opened this issue Jan 12, 2024 · 3 comments

Comments

@dannys4
Copy link

dannys4 commented Jan 12, 2024

Hi! I'm generally a happy user of this package, and really appreciate the hard work put into it. I maintain a library depending on CxxWrap that generally interfaces with its objects via shared_ptrs. As such, a large swath of the library relied on the automatic conversion from smart pointers to references that was removed in #338 (I realized there were issues with upgrading from 0.12 to 0.13 awhile ago, but haven't had the chance to fix them until I've been forced to with 1.10 issues).

Is there any suggested way of having a type signature foo(bar::CxxWrap.StdLib.SharedPtr{T}, args...) and resolving that in C++ as bar->foo(args...) where bar is of type shared_ptr<T>? A significant amount of my library relies on this and, while I believe I could make a Julia macro to generate this code, it would either be overly simplistic or take a huge amount of time to make.

Any thoughts and advice are appreciated!

@barche
Copy link
Collaborator

barche commented Jan 16, 2024

It's true that it would be good to have an easy option to re-enable this behavior. If I understand correctly you want something like this:

struct World
{
  World(const std::string& message = "default hello") : msg(message){}
  const std::string& greet() const { return msg; }
};

JLCXX_MODULE define_julia_module(jlcxx::Module& types)
{
  types.add_type<World>("World")
    .constructor<const std::string&>()
    .method("greet", &World::greet);
}

Where it should be possible to call greet from Julia on both World and std::shard_ptr<World>?

@dannys4
Copy link
Author

dannys4 commented Jan 16, 2024

Yes, that's roughly the case. In the original PR, the author describes the fixes as "easy enough", but I can't figure out a design pattern that doesn't require me to just wrap this function a second time.

@dannys4
Copy link
Author

dannys4 commented Jan 29, 2024

Luckily, my design pattern will always have the shared pointer as the first argument (to kinda go along with Julia syntax), so a quick-and-dirty fix here is

for op = (:foo1, :foo2, :foo3, :foo4)
    eval(quote
        $op(obj::CxxWrap.StdLib.SharedPtr, args...) = $op(obj[], args...)
    end)
end

where foo1 etc. are functions belonging to some class Bar defined as

mod.add_type<Bar>("Bar").method("foo1", [](Bar &obj, float arg1, char arg2){ ... } ) ...;

Beware all ye who enter: this could easily cause issues with ambiguous function definitions.

@dannys4 dannys4 closed this as completed Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants