File tree 2 files changed +46
-4
lines changed
2 files changed +46
-4
lines changed Original file line number Diff line number Diff line change @@ -262,8 +262,6 @@ <h3 id="cgo">Cgo</h3>
262
262
263
263
< p >
264
264
TODO: CL 70890 "permit passing string values directly between Go and C."
265
- < br >
266
- TODO: CL 66332 "special case C ptr types to use uintptr."
267
265
</ p >
268
266
269
267
< p >
@@ -279,6 +277,31 @@ <h3 id="cgo">Cgo</h3>
279
277
variable or else the built-in default.
280
278
</ p >
281
279
280
+ < p >
281
+ Cgo now translates some C types that would normally map to a pointer
282
+ type in Go, to a < code > uintptr</ code > instead. These types include
283
+ the < code > CFTypeRef</ code > hierarchy in Darwin's CoreFoundation
284
+ framework and the < code > jobject</ code > hierarchy in Java's JNI
285
+ interface.
286
+ </ p >
287
+
288
+ < p >
289
+ These types must be < code > uintptr</ code > on the Go side because they
290
+ would otherwise confuse the Go garbage collector; they are sometimes
291
+ not really pointers but data structures encoded in a pointer type.
292
+ </ p >
293
+
294
+ < p >
295
+ Because of this change, values of the affected types need to be
296
+ zero-initialized with the constant < code > 0</ code > instead of the
297
+ constant < code > nil</ code > . Go 1.10 provides < code > gofix</ code >
298
+ modules to help with that rewrite:
299
+ < pre >
300
+ go tool fix -r cftype < pkg >
301
+ go tool fix -r jni < pkg >
302
+ </ pre >
303
+ </ p>
304
+
282
305
< p >
283
306
For more details, see the < a href ="/cmd/cgo/ "> cgo documentation</ a > .
284
307
</ p >
Original file line number Diff line number Diff line change @@ -403,16 +403,35 @@ the CF*Ref types from the CoreFoundation library on Darwin, including:
403
403
CFXMLParserRef
404
404
CFXMLTreeRef
405
405
406
+ Also the object types from Java's JNI interface:
407
+
408
+ jobject
409
+ jclass
410
+ jthrowable
411
+ jstring
412
+ jarray
413
+ jbooleanArray
414
+ jbyteArray
415
+ jcharArray
416
+ jshortArray
417
+ jintArray
418
+ jlongArray
419
+ jfloatArray
420
+ jdoubleArray
421
+ jobjectArray
422
+ jweak
423
+
406
424
These types are uintptr on the Go side because they would otherwise
407
425
confuse the Go garbage collector; they are sometimes not really
408
426
pointers but data structures encoded in a pointer type. All operations
409
427
on these types must happen in C. The proper constant to initialize an
410
428
empty such reference is 0, not nil.
411
429
412
- This special case was introduced in Go 1.10. For auto-updating code
413
- from Go 1.9 and earlier, use the cftype rewrite in the Go fix tool:
430
+ These special cases were introduced in Go 1.10. For auto-updating code
431
+ from Go 1.9 and earlier, use the cftype or jni rewrites in the Go fix tool:
414
432
415
433
go tool fix -r cftype <pkg>
434
+ go tool fix -r jni <pkg>
416
435
417
436
It will replace nil with 0 in the appropriate places.
418
437
You can’t perform that action at this time.
0 commit comments