bytedeco/javacpp

Passing data between languages with no leaks

Open

#351 opened on Oct 16, 2019

View on GitHub
 (12 comments) (0 reactions) (0 assignees)Java (4,279 stars) (620 forks)batch import
enhancementhelp wanted

Description

Hi everyone. The issue is the following. I have to transfer ownership of an allocated data (an array) from C++ to Java. How would I do that?

As a side note: I've tried to work something out with @ArrayAllocator annotation but haven't quite understood the idea of how it works. I got a couple of NullPointerExceptions during my experiments that look like this:

javac -cp javacpp.jar:/home/vasniktel/javacpp-test test/Lib.java 
Generating /home/vasniktel/javacpp-test/jnijavacpp.cpp
Generating /home/vasniktel/javacpp-test/test/jniLib.cpp
Warning: Method "public static native void test.Lib.allocateArray(int)" cannot behave like a "ArrayAllocator". No code will be generated.
Exception in thread "main" java.lang.NullPointerException
        at org.bytedeco.javacpp.tools.Generator.methods(Generator.java:1748)
        at org.bytedeco.javacpp.tools.Generator.classes(Generator.java:1645)
        at org.bytedeco.javacpp.tools.Generator.generate(Generator.java:206)
        at org.bytedeco.javacpp.tools.Builder.generateAndCompile(Builder.java:604)
        at org.bytedeco.javacpp.tools.Builder.build(Builder.java:1107)
        at org.bytedeco.javacpp.tools.Builder.main(Builder.java:1341)

The question is how those annotations work and whether this exception is an intended behaviour?

Contributor guide