nativelibs4java / BridJ

BridJ: blazing fast Java / C / C++ interop
https://code.google.com/archive/p/bridj/
Other
299 stars 77 forks source link

Passing structures "by value" #46

Open ochafik opened 9 years ago

ochafik commented 9 years ago

From @ivangfr on January 19, 2015 14:41

Hi,

I have a function with this signature:

int DeleteElement(FOO*, BAR, char, char);

However, when I execute it, I get a RuntimeException error: "Failed to get low-level struct representation !"

I implemented a second version of the function, now the second parameter is a pointer:

int DeleteElement2(FOO*, BAR*, char, char);

Now it works.

Googling about it, I found this (https://groups.google.com/forum/#!topic/nativelibs4java/Xj4Y-yTB8DI) when you said that

"Unfortunately passing and returning structures "by value" (as opposed to "by reference" or "by pointer") is not supported by BridJ yet (the underlying dyncall library doesn't support them). It's currently my top priority for BridJ". (1/9/13)

So, I would like to confirm if it's not implemented in the version 0.6.2? Do you plan to implement it in the next versions?

Congratulations! It's a great project!

Regards

Copied from original issue: ochafik/nativelibs4java#554

phr00t commented 9 years ago

I'm having trouble using BridJ to implement OpenVR support for a Java engine, jMonkeyEngine. I get the error "Invalid return value type !" when this function is run:

https://github.com/phr00t/jmonkeyengine-virtual-reality/blob/master/src/openvr_api/IVRSystem.java#L84

I think it is related to this "issue", right? Any possible workaround or solution here? I don't have access to the OpenVR source code. I'd love to continue to use BridJ. What are my options?

mpsijm commented 3 years ago

I'm also experiencing this issue with TreeSitter, where many structs are passed by value (notably TSNode): https://github.com/tree-sitter/tree-sitter/blob/master/lib/include/tree_sitter/api.h

I can call the parser from Java (which returns a TSTree *), but I can't inspect the tree from Java as that requires passing TSNodes by value. This is quite a big limitation of the Maven plugin for TreeSitter: https://github.com/mpsijm/java-tree-sitter#limitations