mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 10:37:46 +00:00
b7a3fd8d2f
Here is the proposal: https://github.com/golang/go/issues/56378 They are documented here: https://pkg.go.dev/cmd/cgo@master#hdr-Optimizing_calls_of_C_code This would have been very useful to fix https://github.com/tinygo-org/bluetooth/issues/176 in a nice way. That bug is now fixed in a different way using a wrapper function, but once this new noescape pragma gets included in TinyGo we could remove the workaround and use `#cgo noescape` instead.
31 lines
478 B
Go
31 lines
478 B
Go
package main
|
|
|
|
/*
|
|
// Function signatures.
|
|
int foo(int a, int b);
|
|
void variadic0();
|
|
void variadic2(int x, int y, ...);
|
|
static void staticfunc(int x);
|
|
|
|
// Global variable signatures.
|
|
extern int someValue;
|
|
|
|
void notEscapingFunction(int *a);
|
|
|
|
#cgo noescape notEscapingFunction
|
|
*/
|
|
import "C"
|
|
|
|
// Test function signatures.
|
|
func accessFunctions() {
|
|
C.foo(3, 4)
|
|
C.variadic0()
|
|
C.variadic2(3, 5)
|
|
C.staticfunc(3)
|
|
C.notEscapingFunction(nil)
|
|
}
|
|
|
|
func accessGlobals() {
|
|
_ = C.someValue
|
|
}
|