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

Comments

@duzy
Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Apr 28, 2018

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

@AlexRouSg

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Apr 28, 2018

@odeke-em

This comment has been minimized.

Copy link
Member

commented Apr 30, 2018

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

This comment has been minimized.

Copy link
Member

commented Apr 30, 2018

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

This comment has been minimized.

Copy link

commented Apr 30, 2018

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

@odeke-em odeke-em added NeedsFix and removed WaitingForInfo labels Apr 30, 2018

@odeke-em odeke-em added this to the Go1.11 milestone Apr 30, 2018

@duzy

This comment has been minimized.

Copy link
Author

commented Apr 30, 2018

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

@gopherbot gopherbot closed this in a4aa2e0 May 1, 2018

@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.
Projects
None yet
6 participants
You can’t perform that action at this time.