From 25363de2266a3b53204065637eb509a8cc4d72c3 Mon Sep 17 00:00:00 2001
From: Keith Randall
TODO: CL 70890 "permit passing string values directly between Go and C."
-
@@ -279,6 +277,31 @@ Later
+Cgo now translates some C types that would normally map to a pointer
+type in Go, to a
+These types must be
+Because of this change, values of the affected types need to be
+zero-initialized with the constant
-TODO: CL 66332 "special case C ptr types to use uintptr."
go
build
commands refer to the CC
e
variable or else the built-in default.
uintptr
instead. These types include
+the CFTypeRef
hierarchy in Darwin's CoreFoundation
+framework and the jobject
hierarchy in Java's JNI
+interface.
+uintptr
on the Go side because they
+would otherwise confuse the Go garbage collector; they are sometimes
+not really pointers but data structures encoded in a pointer type.
+0
instead of the
+constant nil
. Go 1.10 provides gofix
+modules to help with that rewrite:
+
+ go tool fix -r cftype
+
For more details, see the cgo documentation.
diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index c1bdf0659f..0b64b31d46 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -403,16 +403,35 @@ the CF*Ref types from the CoreFoundation library on Darwin, including: CFXMLParserRef CFXMLTreeRef +Also the object types from Java's JNI interface: + + jobject + jclass + jthrowable + jstring + jarray + jbooleanArray + jbyteArray + jcharArray + jshortArray + jintArray + jlongArray + jfloatArray + jdoubleArray + jobjectArray + jweak + These types are uintptr on the Go side because they would otherwise confuse the Go garbage collector; they are sometimes not really pointers but data structures encoded in a pointer type. All operations on these types must happen in C. The proper constant to initialize an empty such reference is 0, not nil. -This special case was introduced in Go 1.10. For auto-updating code -from Go 1.9 and earlier, use the cftype rewrite in the Go fix tool: +These special cases were introduced in Go 1.10. For auto-updating code +from Go 1.9 and earlier, use the cftype or jni rewrites in the Go fix tool: go tool fix -r cftype