]> uap-core.de Git - rssreader.git/commitdiff
fix UiString.toString()
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 12 Aug 2025 14:15:22 +0000 (16:15 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 12 Aug 2025 14:15:22 +0000 (16:15 +0200)
ui-java/src/main/java/de/unixwork/ui/ToolkitFuncs.java
ui-java/src/main/java/de/unixwork/ui/UiString.java

index b8e2a25b4dccc0bc9c68b23d74731cb4df7b0d1f..66a987569722f18e9a8f7bf2a890226b889772b6 100644 (file)
@@ -68,11 +68,13 @@ public class ToolkitFuncs {
     // 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);
@@ -141,6 +143,7 @@ public class ToolkitFuncs {
 
         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);
 
@@ -204,6 +207,7 @@ public class ToolkitFuncs {
 
         malloc = linker.downcallHandle(malloc_addr, sigm_l);
         free = linker.downcallHandle(free_addr, sigv_m);
+        strlen = linker.downcallHandle(strlen_addr, sigl_m);
     }
 
     static ToolkitFuncs getInstance() {
index 14228e1fd545ce7b5e031fd41cfefa54b3461b89..f9ce0054e3e35235da0e9dfa3be10b33788113de 100644 (file)
@@ -25,6 +25,8 @@ public class UiString {
         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);
             }