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

std::unique_ptr fields #717

Closed
HGuillemet opened this issue Oct 13, 2023 · 4 comments
Closed

std::unique_ptr fields #717

HGuillemet opened this issue Oct 13, 2023 · 4 comments
Labels

Comments

@HGuillemet
Copy link
Contributor

#include <memory>

struct S {
  std::unique_ptr<int> p;
};

parses to this getter and setter:

  public native @UniquePtr IntPointer p(); public native S p(IntPointer setter);

Compiling the JNI triggers:

error: ambiguous overload for 'operator=' (operand types are 'std::unique_ptr<int>' and 'UniquePtrAdapter<int>')
 1178 |     ptr->p = adapter0;

= for unique_ptr has 2 overloads : one taking a std::unique_ptr && and another taking a const std::unique_ptr &. And the adapter has cast overloads for both.

What's the best way to handle this ?

(case seen in Pytorch 2.1)

@saudet
Copy link
Member

saudet commented Oct 13, 2023

I guess either one work, but give it a try with a @Cast like there already are for SharedPtrAdapter.

@HGuillemet
Copy link
Contributor Author

i don't think @Cast works on fields setter.

@saudet
Copy link
Member

saudet commented Oct 13, 2023

I'm sure it does, try with the third element.

@HGuillemet
Copy link
Contributor Author

Ok, it seems to work with this info:

new Info("S::p").annotations("@UniquePtr", "@Cast({\"\", \"\", \"std::unique_ptr<int>&&\"})")

The @Cast is put on the getter only, but it affects the generation of the setter JNI, somehow.

Thanks, closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants