-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Open
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Description
I was thinking about #975.
My idea is guessing argument types and making specialized wrappers.
For example,
We can convert following code
package main
// #include <stdio.h>
import "C"
func main() {
C.printf(C.CString("hello: %d"), 10)
C.fflush(C.stdout)
}
into
package main
// #include <stdio.h>
// int call_printf_with_int(const char* s, int i) {
// return printf(s, i);
// }
import "C"
func main() {
C.call_printf_with_int(C.CString("hello: %d"), 10)
C.fflush(C.stdout)
}
I'd like to leave these translations to cgo.
To promote this idea, we have to make go/types understand some special cgo semantics.
- all cgo objects are exportable even if the first letter is lower case (e.g.
C.char,C.int, ...) - cgo functions behave like
unsafe.Pointerin the expression context (e.g.var xxx unsafe.Pointer = C.puts) - cgo functions can return the optional
errorargument in the assignment context (e.g_, err := C.puts(C.CString("x"))
Is this acceptable?
FWIW, https://go-review.googlesource.com/c/go/+/83215 is the attempt.
Metadata
Metadata
Assignees
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.