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

Fix template substitution with const #677

Merged
merged 5 commits into from May 16, 2023

Conversation

HGuillemet
Copy link
Contributor

template <typename T>
class X {
 public:
    X(const T*) {}
};

If you instantiate this template with int *, then the resulting type should be int * const * and not const int **.
But the parser produces this, with a new Info("X<int *>").pointerTypes("XI"):

    public XI(@Cast("const int**") PointerPointer arg0) { super((Pointer)null); allocate(arg0); }
    private native void allocate(@Cast("const int**") PointerPointer arg0);

Leading to JNI compile error since the constructor expects a int * const*.
This PR tries to fix this. It seems to do the trick. The parser now emits:

    public XI(@Cast("int**") PointerPointer arg0) { super((Pointer)null); allocate(arg0); }
    private native void allocate(@Cast("int**") PointerPointer arg0);

The const doesn't appear in the cast at all, but at least we have a better chance to compile the JNI.
I'm not sure it generalizes well. Can we do something better ?

@saudet
Copy link
Member

saudet commented May 14, 2023

Info.constPointer currently gets ignored in this case, yes. It's complicated, but if this fix works for that template that's fine for now. We can do something about Info.constPointer later, I think that's OK, yes. Did you make sure it doesn't break anything in the presets though?

@HGuillemet
Copy link
Contributor Author

Just finished to reparse (almost) all presets. Only changes are for pytorch where const is removed from @Cast in the following declarations:

In BlockArrayRef.java:

public native @Cast("torch::jit::Block**") PointerPointer data();

In ValueArrayRef.java

public native @Cast("torch::jit::Value**") PointerPointer data();

JNI still compiles.

@saudet saudet merged commit 78b9450 into bytedeco:master May 16, 2023
16 checks passed
@HGuillemet HGuillemet deleted the fix_const_template branch May 16, 2023 12:58
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

Successfully merging this pull request may close these issues.

None yet

2 participants