-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: C functions that return void incorrectly return Go values #21878
Comments
Change https://golang.org/cl/63830 mentions this issue: |
Change https://golang.org/cl/63831 mentions this issue: |
Some more examples of why this is a problem:
//…
package p
/*
static void return_void() { return; }
static void consume_void(void) { return; }
*/
import "C"
func F() {
impossible := C.return_void() // Today: no error here.
C.consume_void(impossible)
} The error today:
//…
package p
/*
static void return_void() { return; }
static void consume_void_ptr(void* unused) { return; }
*/
import "C"
func F() {
impossible := C.return_void() // Today: no error here.
C.consume_void_ptr(&impossible)
} The error today:
package cgotest
/*
static void* return_void_ptr() { return 0; }
static void consume_void_ptr(void* unused) { return; }
*/
import "C"
func testVoidPtrMustCompile() {
var p *C.void = C.return_void_ptr()
C.consume_void_ptr(p)
} But today it fails to compile:
|
The root of the problem is that we're treating @hirochachacha notes that we could fix that by having the cgo command rewrite |
The only code that I have been able to find to date that actually uses It is a mechanically-generated wrapper, and the erroneously-wrapped (But I will note that searching for |
As another point of reference, the string
|
We previously used bare strings, which made it difficult to see (and to cross-reference) the set of allowed context values. This change is purely cosmetic, but makes it easier for me to understand how to address #21878. updates #21878 Change-Id: I9027d94fd5997a0fe857c0055dea8719e1511f03 Reviewed-on: https://go-review.googlesource.com/63830 Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
Just wondering, but is it wrong to think of |
“The (nonexistent) value of a void expression (an expression that has type (Note, however, that there is no C type corresponding to the Go type In contrast, there is exactly one Go value of type |
(But see also #20275 (comment): having a non-instantiable |
cgo
fails to reject the following program — despite numerous errors involving values of typeC.void
, which ought to be completely uninstantiable. (The word “void” itself means “empty”, so it's nonsensical for the type “void” to contain a value!)I'm not sure to what extent this is fixable, given that the fix for #3729 added a test verifying that Go callers can bind
_, err
to the result of a call to a void-returning function.The text was updated successfully, but these errors were encountered: