[foreign-jextract] Bindings to functions declared in header file
Paul Sandoz
paul.sandoz at oracle.com
Fri Aug 7 17:47:43 UTC 2020
Hi,
The jextract tool generates bindings to functions declared in a header file.
MethodHandle lookup will return null, since the function does not exist in the corresponding shared library.
$ jshell --class-path . --add-modules jdk.incubator.foreign -R-Dforeign.restricted=permit -R-Djava.library.path=.
| Welcome to JShell -- Version 16-internal
| For an introduction type: /help intro
jshell> import a.a_h
jshell> a_h.f_in_source()
jshell> a_h.f_in_header()
| Exception java.lang.AssertionError: java.lang.NullPointerException: Cannot invoke "java.lang.invoke.MethodHandle.invokeExact(Object[])" because the return value of "a.a_h$constants.f_in_header$MH()" is null
| at a_h.f_in_header (a_h.java:30)
| at (#3:1)
| Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.invoke.MethodHandle.invokeExact(Object[])" because the return value of "a.a_h$constants.f_in_header$MH()" is null
| at a_h.f_in_header (a_h.java:28)
| …
More details below.
Paul.
$ more a.h
void f_in_source();
static void f_in_header() {
}
$ more a.c
#include "a.h"
void f_in_source() {
}
$ more a/a_h.java
// Generated by jextract
package a;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
import jdk.incubator.foreign.*;
import jdk.incubator.foreign.MemoryLayout.PathElement;
import static jdk.incubator.foreign.CSupport.SysV.*;
public final class a_h {
private a_h() {}
public static MethodHandle f_in_source$MH() {
return a_h$constants.f_in_source$MH();
}
public static void f_in_source (Object... x0) {
try {
a_h$constants.f_in_source$MH().invokeExact(x0);
} catch (Throwable ex) {
throw new AssertionError(ex);
}
}
public static MethodHandle f_in_header$MH() {
return a_h$constants.f_in_header$MH();
}
public static void f_in_header (Object... x0) {
try {
a_h$constants.f_in_header$MH().invokeExact(x0);
} catch (Throwable ex) {
throw new AssertionError(ex);
}
}
}
More information about the panama-dev
mailing list