-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgo.go
63 lines (49 loc) · 920 Bytes
/
cgo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cgo
/*
void empty_function() {}
int function(int a) {
return a;
}
void fastcgo_function(void *args, void *result) {
struct Arguments {
int a;
};
struct Result {
int value;
};
((struct Result*)result)->value = ((struct Arguments*)args)->a;
}
*/
import "C"
import (
"golang.conf/fastcgo"
"unsafe"
)
func CGoEmptyFunctionCall() {
C.empty_function()
}
func CGoFunctionCall() {
C.function(5)
}
func FastCGoEmptyFunctionCall() {
fastcgo.SimpleCall0(C.empty_function)
}
func FastCGoEmptyFunctionCallOnSystemStack() {
fastcgo.Call0(C.empty_function)
}
func FastCGoFunctionCallOnSystemStack() {
var args = struct {
a int32
}{1}
var result = struct {
value int32
}{}
fastcgo.Call2(C.fastcgo_function, uintptr(unsafe.Pointer(&args)), uintptr(unsafe.Pointer(&result)))
}
//go:noinline
func GoEmptyFunctionCall() {
}
//go:noinline
func GoFunctionCall(a int) int {
return a
}