Skip to content
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: variadic parameters not working with C.char #25143

Closed
duzy opened this issue Apr 28, 2018 · 8 comments
Closed

cmd/cgo: variadic parameters not working with C.char #25143

duzy opened this issue Apr 28, 2018 · 8 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@duzy
Copy link

duzy commented Apr 28, 2018

What version of Go are you using (go version)?

$ go version
go version go1.10.1 linux/amd64

Does this issue reproduce with the latest release?

I think so.

What operating system and processor architecture are you using (go env)?

I'm working with alpine 3.7.

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"

What did you do?

Working with this segment:

func cfree(cs... *C.char) {
    for _, s := range cs {
        C.free(unsafe.Pointer(s))
    }
}

What did you expect to see?

Nothing as all good.

What did you see instead?

Compilation error as "undefined: C in C.char".

@duzy duzy changed the title Ellipsis (variadic) parameters not working with C.char cgo: Ellipsis (variadic) parameters not working with C.char Apr 28, 2018
@cznic
Copy link
Contributor

cznic commented Apr 28, 2018

Missing import "C"? Please show a complete program.

@davecheney davecheney added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 28, 2018
@AlexRouSg
Copy link
Contributor

AlexRouSg commented Apr 28, 2018

@cznic I can repo with the following and any c type as the variadic arg.

package main

import "C"

func free(...*C.char) {
}

func main() {}

@cznic
Copy link
Contributor

cznic commented Apr 28, 2018

I can reproduce the issue with the above code in Go1.10. I don't know why it fails. I seem to recall, that Go cannot call C variadic functions but I cannot find that mentioned in the CGO docs at https://golang.org/cmd/cgo/.

However, in this case free is not a C function and I don't see why it should not compile.

@AlexRouSg
Copy link
Contributor

cc @ianlancetaylor

@odeke-em
Copy link
Member

I seem to recall, that Go cannot call C variadic functions but I cannot find that mentioned in the CGO docs at

@cznic is this the issue that you are looking for #975?
#23537 was filed to document this but the CL https://go-review.googlesource.com/#/c/90415/ hasn't yet been reviewed.

@odeke-em odeke-em changed the title cgo: Ellipsis (variadic) parameters not working with C.char cmd/cgo: variadic parameters not working with C.char Apr 30, 2018
@odeke-em
Copy link
Member

Although perhaps this is an entirely different issue. #975 is about calling variadic C functions in Go, while this is one is entirely failing when a Go function has a variadic C. signature.

/cc @hirochachacha too

@gopherbot
Copy link

Change https://golang.org/cl/110159 mentions this issue: cmd/cgo: parse cgo type inside ellipsis node

@odeke-em odeke-em added NeedsFix The path to resolution is known, but the work has not been done. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Apr 30, 2018
@odeke-em odeke-em added this to the Go1.11 milestone Apr 30, 2018
@duzy
Copy link
Author

duzy commented Apr 30, 2018

Thank you all guys for addressing this issue. Looking forward to using Go1.11 instead. Cheers!

@golang golang locked and limited conversation to collaborators May 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants