Hello, I'm trying to figure out how to return a two dimensional string in Go (cgo) and be able to access this result in python and java jni.
I followed the following <https://stackoverflow.com/questions/14833531/how-to-convert-from-byte-to-char-in-go> to make the unsafe pointers. The code works in python with ctypes. However, the java code does not work and is returning null or zero. The relevant go code //export Java_com_test_TestJni_Gen > func Java_com_test_TestJni_Gen(env *C.JNIEnv, clazz C.jclass, x int) > **C.char { > gostrings:=make([]string, x) > for i:=0;i<x;i++ { > gostrings[i]="test" > } > > //https://stackoverflow.com/questions/14833531/how-to-convert-from-byte-to-char-in-go?rq=1 > var b *C.char > ptrSize := unsafe.Sizeof(b) > // Allocate the char** list. > ptr := C.malloc(C.size_t(x) * C.size_t(ptrSize)) > //defer C.free(ptr) > // Assign each byte slice to its appropriate offset. > for p := 0;p<int(x);p++ { > element := (**C.char)(unsafe.Pointer(uintptr(ptr) + > uintptr(p)*ptrSize)) > //*element = (*C.char)(unsafe.Pointer(&list[i][0])) > *element = C.CString(string(gostrings[p])) > } > return((**C.char)(ptr)) > } The relevant java code public static native byte[][] Gen(int x); > public static void main(String argv[]) { > TestJni api=new TestJni(); > byte[][] result=Gen(3); > for(int x=0;x<3;x++) { > System.out.println(result[x]); > } > } I've also made the full project with go code, python, and java code here https://github.com/jbarca/cgojni Thanks in advance -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.