aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-04-13 21:34:43 +0200
committerRon Evans <[email protected]>2022-09-16 14:05:17 +0200
commit5551ec7a1ed9d59764cfdf5a73b23dc40365a6f8 (patch)
tree0fcff842574327f6615ed0909ed57efaf726dba5 /testdata
parent91104b2f276348e251a25e9e58e7faafe781358f (diff)
downloadtinygo-5551ec7a1ed9d59764cfdf5a73b23dc40365a6f8.tar.gz
tinygo-5551ec7a1ed9d59764cfdf5a73b23dc40365a6f8.zip
cgo: implement support for static functions
Diffstat (limited to 'testdata')
-rw-r--r--testdata/cgo/extra.go14
-rw-r--r--testdata/cgo/main.go3
-rw-r--r--testdata/cgo/out.txt3
3 files changed, 20 insertions, 0 deletions
diff --git a/testdata/cgo/extra.go b/testdata/cgo/extra.go
index 8c2c2691b..f8ce946db 100644
--- a/testdata/cgo/extra.go
+++ b/testdata/cgo/extra.go
@@ -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)
+}
diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go
index e8438919f..417b43a95 100644
--- a/testdata/cgo/main.go
+++ b/testdata/cgo/main.go
@@ -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
diff --git a/testdata/cgo/out.txt b/testdata/cgo/out.txt
index 375ad1f6f..48e29a167 100644
--- a/testdata/cgo/out.txt
+++ b/testdata/cgo/out.txt
@@ -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