1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:34:51 -07:00
go/misc/cgo/errors
Ian Lance Taylor a16954b8a7 cmd/cgo: always use a function literal for pointer checking
The pointer checking code needs to know the exact type of the parameter
expected by the C function, so that it can use a type assertion to
convert the empty interface returned by cgoCheckPointer to the correct
type. Previously this was done by using a type conversion, but that
meant that the code accepted arguments that were convertible to the
parameter type, rather than arguments that were assignable as in a
normal function call. In other words, some code that should not have
passed type checking was accepted.

This CL changes cgo to always use a function literal for pointer
checking. Now the argument is passed to the function literal, which has
the correct argument type, so type checking is performed just as for a
function call as it should be.

Since we now always use a function literal, simplify the checking code
to run as a statement by itself. It now no longer needs to return a
value, and we no longer need a type assertion.

This does have the cost of introducing another function call into any
call to a C function that requires pointer checking, but the cost of the
additional call should be minimal compared to the cost of pointer
checking.

Fixes #16591.

Change-Id: I220165564cf69db9fd5f746532d7f977a5b2c989
Reviewed-on: https://go-review.googlesource.com/31233
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-10-19 21:20:50 +00:00
..
err1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
err2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
err3.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
issue7757.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
issue8442.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
issue11097a.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
issue11097b.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
issue13129.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
issue13423.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
issue13635.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
issue13830.go cmd/cgo: use function arg type for _cgoCheckPointerN function 2016-06-09 16:02:03 +00:00
issue14669.go cmd/cgo: remove -O options when generating compiler errors 2016-05-27 01:40:30 +00:00
issue16116.go cmd/cgo: error, not panic, if not enough arguments to function 2016-06-21 04:32:04 +00:00
issue16591.go cmd/cgo: always use a function literal for pointer checking 2016-10-19 21:20:50 +00:00
ptr.go cmd/cgo: check pointers for deferred C calls at the right time 2016-06-03 20:51:39 +00:00
test.bash cmd/cgo: always use a function literal for pointer checking 2016-10-19 21:20:50 +00:00