// some libc stuff
public MethodHandle malloc;
public MethodHandle free;
+ public MethodHandle strlen;
private ToolkitFuncs(Linker linker, SymbolLookup lib) {
FunctionDescriptor sigm = FunctionDescriptor.of(ValueLayout.ADDRESS);
FunctionDescriptor sigm_m = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
FunctionDescriptor sigi_m = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS);
+ FunctionDescriptor sigl_m = FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS);
FunctionDescriptor sigm_mm = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
FunctionDescriptor sigv_mm = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
FunctionDescriptor sigm_ml = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_LONG);
MemorySegment malloc_addr = lib.find("malloc").orElseThrow();
MemorySegment free_addr = lib.find("free").orElseThrow();
+ MemorySegment strlen_addr = lib.find("strlen").orElseThrow();
object_get_context = linker.downcallHandle(object_get_context_addr, sigm_m);
malloc = linker.downcallHandle(malloc_addr, sigm_l);
free = linker.downcallHandle(free_addr, sigv_m);
+ strlen = linker.downcallHandle(strlen_addr, sigl_m);
}
static ToolkitFuncs getInstance() {
ToolkitFuncs ui = ToolkitFuncs.getInstance();
try {
MemorySegment cstr = (MemorySegment) ui.string_get.invoke(valuePtr);
+ long length = (long)ui.strlen.invoke(cstr);
+ cstr = cstr.reinterpret(length+1);
if (cstr != null && cstr.address() != 0) {
return cstr.getString(0);
}