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: cannot call functions with variable-argument lists. #975

Open
gopherbot opened this issue Jul 29, 2010 · 10 comments
Open

cmd/cgo: cannot call functions with variable-argument lists. #975

gopherbot opened this issue Jul 29, 2010 · 10 comments
Assignees
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 29, 2010

by akidan:

A package such as the following will not compile with cgo. 
(printf is a contrived example, but this would be useful for bridging objective c
through id objc_msgSend(id self, SEL op, ...);)

--- (file foo.go)
package foo

// #include <stdio.h>
import "C"

func PrintStuff() {
    C.printf(C.CString("Hello"))
}

---

$ cgo foo.go

What is the expected output?
Program compiles and is able to call function with variable-argument list.

What do you see instead?
unexpected type: ...

What is your $GOOS?  $GOARCH?
darwin amd64

Which revision are you using?  (hg identify)
43fd9bb529f0+ tip
@rsc
Copy link
Contributor

@rsc rsc commented Jul 29, 2010

Comment 1:

I'm not sure this will ever work.  It's very hard to type check and do correctly.

Labels changed: added priority-low, removed priority-medium.

Owner changed to r...@golang.org.

Status changed to LongTerm.

@gopherbot
Copy link
Author

@gopherbot gopherbot commented Jul 30, 2010

Comment 2 by akidan:

Thank you for the update all the same - transparency is appreciated!
@rsc
Copy link
Contributor

@rsc rsc commented Dec 9, 2011

Comment 3:

Labels changed: added priority-someday.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 5:

Labels changed: added repo-main.

@rsc
Copy link
Contributor

@rsc rsc commented Mar 3, 2014

Comment 6:

Adding Release=None to all Priority=Someday bugs.

Labels changed: added release-none.

@LionNatsu
Copy link
Contributor

@LionNatsu LionNatsu commented Jan 24, 2018

I think this should be documented as it is a long-term issue.

While wiki says:

... That is, if you want to call the C function printf() from Go code, you write C.printf(). Since variable argument methods like printf aren't supported yet (issue 975), we will wrap it in the C method "myprint":...

The documentation of cgo should be more explicit for the issue, but now it not even mention this.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jan 24, 2018

@LionNatsu, please file a new bug just for documenting that. It's true that I see nothing at https://golang.org/cmd/cgo/ about variadic args.

@gopherbot
Copy link
Author

@gopherbot gopherbot commented Jan 28, 2018

Change https://golang.org/cl/90415 mentions this issue: cgo: Update documentation on calling C variadic functions

gopherbot pushed a commit that referenced this issue Jun 13, 2018
The current implementation does not support calling C variadic
functions (as discussed in #975). Document that.

Fixes #23537

Change-Id: If4c684a3d135f3c2782a720374dc4c07ea66dcbb
Reviewed-on: https://go-review.googlesource.com/90415
Reviewed-by: Ian Lance Taylor <iant@golang.org>
dna2github added a commit to dna2fork/go that referenced this issue Jun 14, 2018
The current implementation does not support calling C variadic
functions (as discussed in golang#975). Document that.

Fixes golang#23537

Change-Id: If4c684a3d135f3c2782a720374dc4c07ea66dcbb
Reviewed-on: https://go-review.googlesource.com/90415
Reviewed-by: Ian Lance Taylor <iant@golang.org>
alpicoid pushed a commit to alpicoid/gotk3 that referenced this issue May 4, 2019
…) that supports only one tag

as cgo does not support functions with variable-argument lists (see golang/go#975)
@golang golang deleted a comment Nov 1, 2020
@golang golang deleted a comment Nov 1, 2020
@golang golang deleted a comment Nov 1, 2020
@golang golang deleted a comment Nov 1, 2020
@golang golang deleted a comment Nov 1, 2020
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Feb 2, 2021

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 7, 2021

n order to implement this, we need to be able to rewrite

C.printf(C.CString("%d %s"), 1, C.CString("2"))

into a call to a generated Go function

GoWrapper(C.CString("%d %s"), 1, C.CString("2"))

which means that we need to generate

func GoWrapper(p1 *C.char,  p2 int, p3 *C.char)

and similarly for a C wrapper function.

That is all fine, but in order to write these functions we need to know the types of the Go arguments. Normally we can simply use the types of the C function parameters, which we can get from the C debug info. But of course for a C variadic function we have no type information for the variadic arguments. That means that we need to use the types of the Go arguments. But currently cgo does not know those types.

So I think this has to wait for #16623.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants