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

Wrong function pointer definition #162

Closed
Arcnor opened this issue Feb 7, 2017 · 8 comments
Closed

Wrong function pointer definition #162

Arcnor opened this issue Feb 7, 2017 · 8 comments
Labels

Comments

@Arcnor
Copy link

Arcnor commented Feb 7, 2017

The following C++ definition:

const char* (*GetClipboardTextFn)();

...creates the following Java definition:

public static class @Cast("const char *") GetClipboardTextFn extends FunctionPointer {
    static { Loader.load(); }
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public @Cast("const char *") GetClipboardTextFn(Pointer p) { super(p); }
    protected @Cast("const char *") GetClipboardTextFn() { allocate(); }
    private native void allocate();
    public native @Cast("const char*") BytePointer call();
}

Both the @Cast on the class and the ones on the constructors make this impossible to compile.

I've fixed this in my InfoMap in the meantime by doing infoMap.put(new Info("char* (*)()").pointerTypes("GetClipboardTextFn")), which might also be a bug? (There is no way of referencing this that I can see other than char* (*)(), but that can obviously match with multiple functions)

@saudet
Copy link
Member

saudet commented Feb 7, 2017

How did you generate that? When I try this typedef:

typedef const char* (*GetClipboardTextFn)();

The output is as follows and compiles fine:

public static class GetClipboardTextFn extends FunctionPointer {
    static { Loader.load(); }
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public    GetClipboardTextFn(Pointer p) { super(p); }
    protected GetClipboardTextFn() { allocate(); }
    private native void allocate();
    public native @Cast("const char*") BytePointer call();
}

@Arcnor
Copy link
Author

Arcnor commented Feb 7, 2017

I've checked the code, and typedef has special code, so you won't get the @Cast.

This comes from here: https://github.com/ocornut/imgui/blob/master/imgui.h#L761

I've also discovered my workaround is not perfect. The getter/setter for the function pointer will not be created...

@saudet
Copy link
Member

saudet commented Feb 7, 2017

Still doesn't happen here. I get this:

public static class GetClipboardTextFn_Pointer extends FunctionPointer {
    static { Loader.load(); }
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public    GetClipboardTextFn_Pointer(Pointer p) { super(p); }
    protected GetClipboardTextFn_Pointer() { allocate(); }
    private native void allocate();
    public native @Cast("const char*") BytePointer call(Pointer user_data);
}
@MemberGetter public native GetClipboardTextFn_Pointer GetClipboardTextFn();

@Arcnor
Copy link
Author

Arcnor commented Feb 7, 2017

Ok, my original report seems wrong. What I'm really getting in Java is:

    public static class @Cast("const char*") BytePointer_GetClipboardTextFn extends FunctionPointer {
        static { Loader.load(); }
        /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
        public    @Cast("const char*") BytePointer_GetClipboardTextFn(Pointer p) { super(p); }
        protected @Cast("const char*") BytePointer_GetClipboardTextFn() { allocate(); }
        private native void allocate();
        public native @Cast("const char*") BytePointer call();
    }
    @MemberGetter public native @Cast("const char*") BytePointer_GetClipboardTextFn GetClipboardTextFn();

... so BytePointer_ is being appended. Since you're not getting it, I can upload the project I'm using for the generation (the mappings for imgui), it will probably be easier to see it there.

@Arcnor
Copy link
Author

Arcnor commented Feb 7, 2017

https://expirebox.com/download/efce5caa04c94eb8c9c481b7a1016a56.html contains the bindings, hopefully you should be able to just do "mvn clean package" and the error will show.

@saudet
Copy link
Member

saudet commented Feb 7, 2017

Ah, wait a minute, I had tried the one with the void* argument. Ok, without the void* argument, then it outputs weird, I see.

@saudet saudet added the bug label Feb 7, 2017
@saudet
Copy link
Member

saudet commented Feb 12, 2017

I've fixed this in the commit above. Thanks for reporting!

@saudet
Copy link
Member

saudet commented Mar 12, 2017

And now part of JavaCPP as of version 1.3.2. Thanks again for the feedback!

@saudet saudet closed this as completed Mar 12, 2017
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