34 35 public class PointerTest { 36 private static final boolean DEBUG = Boolean.getBoolean("PointerTest.DEBUG"); 37 38 private static final Library lib; 39 private static final pointers ptrs; 40 41 private static final String[] VERIFICATION_STRINGS = { 42 "String A", 43 "String B", 44 "String C" 45 }; 46 47 static { 48 lib = Libraries.loadLibrary(MethodHandles.lookup(), "Pointers"); 49 ptrs = Libraries.bind(pointers.class, lib); 50 } 51 52 @NativeHeader 53 static interface pointers { 54 @C(file="dummy", line=47, column=11, USR="c:@F@get_strings") 55 @CallingConvention(value=1) 56 @NativeType(layout="(p:p:p:cp:i)V", ctype="void (const char***, int*)", size=1l) 57 void get_strings(Pointer<Pointer<Pointer<Byte>>> p, Pointer<Integer> pcount); 58 59 @C(file="dummy", line=47, column=11, USR="c:@F@get_strings2") 60 @CallingConvention(value=1) 61 @NativeType(layout="(p:i)p:p:c", ctype="const char **(int *)", size=1l) 62 Pointer<Pointer<Byte>> get_strings2(Pointer<Integer> pcount); 63 64 @C(file="dummy", line=47, column=11, USR="c:@F@get_structs") 65 @CallingConvention(value=1) 66 @NativeType(layout="(p:p:p:[3ip:c]p:i)V", ctype="void (const struct MyStruct ***, int *)", size=1l) 67 void get_structs(Pointer<Pointer<Pointer<MyStruct>>> p, Pointer<Integer> pcount); 68 69 @C(file="dummy", line=47, column=11, USR="c:@F@get_structs2") 70 @CallingConvention(value=1) 71 @NativeType(layout="(p:i)p:p:[3ip:c]", ctype="const struct MyStruct **(int *)", size=1l) 72 Pointer<Pointer<MyStruct>> get_structs2(Pointer<Integer> pcount); 73 74 @NativeType(layout="[3ip:c]", ctype="dummy", size=24, isRecordType=true) 75 @C(file="dummy", line=47, column=11, USR="C:@S@MyStruct") 76 static interface MyStruct extends Struct<MyStruct> { 77 @Offset(offset=0l) 78 @C(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@ia") 79 @Array(elementType="int", elementSize=4l, length=3l) 80 @NativeType(layout="3i", ctype="int []", size=12l) 81 int[] ia$get(); 82 void ia$set(int[] i); 83 84 @Offset(offset=128l) 85 @C(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@str") 86 @NativeType(layout="p:c", ctype="const char*", size=4l) 87 Pointer<Byte> str$get(); 88 void str$set(Pointer<Byte> str); 89 } 90 } 91 92 private static void debug(String str) { 93 if (DEBUG) { 94 System.err.println(str); 95 } 96 } 97 98 private void verifyStrings(Pointer<Pointer<Byte>> values, Pointer<Integer> pi) { 99 debug("values: " + values); 100 debug("nvalues: " + pi.get()); 101 102 assertEquals(VERIFICATION_STRINGS.length, pi.get()); 103 104 for (int i = 0; i < pi.get(); i++) { 105 Pointer<Byte> cstr = values.offset(i).get(); 106 String str = Pointer.toString(cstr); | 34 35 public class PointerTest { 36 private static final boolean DEBUG = Boolean.getBoolean("PointerTest.DEBUG"); 37 38 private static final Library lib; 39 private static final pointers ptrs; 40 41 private static final String[] VERIFICATION_STRINGS = { 42 "String A", 43 "String B", 44 "String C" 45 }; 46 47 static { 48 lib = Libraries.loadLibrary(MethodHandles.lookup(), "Pointers"); 49 ptrs = Libraries.bind(pointers.class, lib); 50 } 51 52 @NativeHeader 53 static interface pointers { 54 @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@get_strings") 55 @NativeType(layout="(p:p:p:cp:i)V", ctype="void (const char***, int*)") 56 void get_strings(Pointer<Pointer<Pointer<Byte>>> p, Pointer<Integer> pcount); 57 58 @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@get_strings2") 59 @NativeType(layout="(p:i)p:p:c", ctype="const char **(int *)") 60 Pointer<Pointer<Byte>> get_strings2(Pointer<Integer> pcount); 61 62 @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@get_structs") 63 @NativeType(layout="(p:p:p:[3ip:c]p:i)V", ctype="void (const struct MyStruct ***, int *)" ) 64 void get_structs(Pointer<Pointer<Pointer<MyStruct>>> p, Pointer<Integer> pcount); 65 66 @NativeLocation(file="dummy", line=47, column=11, USR="c:@F@get_structs2") 67 @NativeType(layout="(p:i)p:p:[3ip:c]", ctype="const struct MyStruct **(int *)") 68 Pointer<Pointer<MyStruct>> get_structs2(Pointer<Integer> pcount); 69 70 @NativeLocation(file="dummy", line=47, column=11, USR="C:@S@MyStruct") 71 @NativeStruct("[3ip:c]") 72 static interface MyStruct extends Struct<MyStruct> { 73 @Offset(offset=0l) 74 @NativeLocation(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@ia") 75 @Array(elementType="int", elementSize=4l, length=3l) 76 @NativeType(layout="3i", ctype="int []") 77 int[] ia$get(); 78 void ia$set(int[] i); 79 80 @Offset(offset=128l) 81 @NativeLocation(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@FI@str") 82 @NativeType(layout="p:c", ctype="const char*") 83 Pointer<Byte> str$get(); 84 void str$set(Pointer<Byte> str); 85 } 86 } 87 88 private static void debug(String str) { 89 if (DEBUG) { 90 System.err.println(str); 91 } 92 } 93 94 private void verifyStrings(Pointer<Pointer<Byte>> values, Pointer<Integer> pi) { 95 debug("values: " + values); 96 debug("nvalues: " + pi.get()); 97 98 assertEquals(VERIFICATION_STRINGS.length, pi.get()); 99 100 for (int i = 0; i < pi.get(); i++) { 101 Pointer<Byte> cstr = values.offset(i).get(); 102 String str = Pointer.toString(cstr); |