]> Cypherpunks repositories - gostls13.git/commit
cmd/cgo: check function argument/return types for bad C pointer types
authorKeith Randall <khr@golang.org>
Sat, 7 Jul 2018 04:38:31 +0000 (21:38 -0700)
committerKeith Randall <khr@golang.org>
Mon, 9 Jul 2018 22:19:21 +0000 (22:19 +0000)
commit94076feef53c41c0c558a8686d6f2650b1614414
treecaa2ff73f5a25ccffec03f2d542db48197c23a78
parent0ebfc99e9af761ecf40a3b6fbc7f9abaf1b3ae63
cmd/cgo: check function argument/return types for bad C pointer types

We need to determine whether arguments to and return values from C
functions are "bad" typedef'd pointer types which need to be uintptr
on the Go side.

The type of those arguments are not specified explicitly. As a result,
we never look through the C declarations for the GetTypeID functions
associated with that type, and never realize that they are bad.
However, in another function in the same package there might be an
explicit reference. Then we end up with the declaration being uintptr
in one file and *struct{...} in another file. Badness ensues.

Fix this by doing a 2-pass algorithm. In the first pass, we run as
normal, but record all the argument and result types we see. In the
second pass, we include those argument types also when reading the C
types.

Fixes #24161

Change-Id: I8d727e73a2fbc88cb9d9899f8719ae405f59f753
Reviewed-on: https://go-review.googlesource.com/122575
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/test/issue24161_darwin_test.go [new file with mode: 0644]
misc/cgo/test/issue24161arg/def.go [new file with mode: 0644]
misc/cgo/test/issue24161arg/use.go [new file with mode: 0644]
misc/cgo/test/issue24161res/restype.go [new file with mode: 0644]
src/cmd/cgo/gcc.go
src/cmd/cgo/main.go