Cgo add cbytes implementation (rebased version of #3318) (#4470)

cgo: added CBytes implementation
This commit is contained in:
leongross
2024-09-17 07:12:57 -07:00
committed by GitHub
parent d4729f92bd
commit a9bf981d92
10 changed files with 61 additions and 1 deletions
+2
View File
@@ -165,6 +165,8 @@ func main() {
println("C.GoString(nil):", C.GoString(nil))
println("len(C.GoStringN(nil, 0)):", len(C.GoStringN(nil, 0)))
println("len(C.GoBytes(nil, 0)):", len(C.GoBytes(nil, 0)))
println("len(C.GoBytes(C.CBytes(nil),0)):", len(C.GoBytes(C.CBytes(nil), 0)))
println(`rountrip CBytes:`, C.GoString((*C.char)(C.CBytes([]byte("hello\000")))))
// libc: test whether C functions work at all.
buf1 := []byte("foobar\x00")
+2
View File
@@ -73,6 +73,8 @@ C.CStringN: 4 2 0 4 8
C.GoString(nil):
len(C.GoStringN(nil, 0)): 0
len(C.GoBytes(nil, 0)): 0
len(C.GoBytes(C.CBytes(nil),0)): 0
rountrip CBytes: hello
copied string: foobar
CGo sqrt(3): +1.732051e+000
C sqrt(3): +1.732051e+000