mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
cgo: implement support for static functions
This commit is contained in:
committed by
Ron Evans
parent
91104b2f27
commit
5551ec7a1e
Vendored
+14
@@ -3,4 +3,18 @@ package main
|
||||
// Make sure CGo supports multiple files.
|
||||
|
||||
// int fortytwo(void);
|
||||
// static float headerfunc_static(float a) { return a - 1; }
|
||||
// static void headerfunc_void(int a, int *ptr) { *ptr = a; }
|
||||
import "C"
|
||||
|
||||
func headerfunc_2() {
|
||||
// Call headerfunc_static that is different from the headerfunc_static in
|
||||
// the main.go file.
|
||||
// The upstream CGo implementation does not handle this case correctly.
|
||||
println("static headerfunc 2:", C.headerfunc_static(5))
|
||||
|
||||
// Test function without return value.
|
||||
var n C.int
|
||||
C.headerfunc_void(3, &n)
|
||||
println("static headerfunc void:", n)
|
||||
}
|
||||
|
||||
Vendored
+3
@@ -12,6 +12,7 @@ int mul(int, int);
|
||||
import "C"
|
||||
|
||||
// int headerfunc(int a) { return a + 1; }
|
||||
// static int headerfunc_static(int a) { return a - 1; }
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
@@ -47,6 +48,8 @@ func main() {
|
||||
|
||||
// functions in the header C snippet
|
||||
println("headerfunc:", C.headerfunc(5))
|
||||
println("static headerfunc:", C.headerfunc_static(5))
|
||||
headerfunc_2()
|
||||
|
||||
// equivalent types
|
||||
var goInt8 int8 = 5
|
||||
|
||||
Vendored
+3
@@ -16,6 +16,9 @@ callback 2: 600
|
||||
variadic0: 1
|
||||
variadic2: 15
|
||||
headerfunc: 6
|
||||
static headerfunc: 4
|
||||
static headerfunc 2: +4.000000e+000
|
||||
static headerfunc void: 3
|
||||
bool: true true
|
||||
float: +3.100000e+000
|
||||
double: +3.200000e+000
|
||||
|
||||
Reference in New Issue
Block a user