detached a91fd92

add test for mix of floats and int arguments in callback (#171)

This test makes sure that int and float arguments take different registers
commit
a91fd92eea51594b980f162268aa3c22874e24a0
author
TotallyGamerJet · · 2023-10-03 11:57 UTC
committer
GitHub · · 2023-10-03 11:57 UTC
parent
5b7ae97
signature
GPG Unverified4AEE18F83AFDEB23 The key is unknown
2 files · +23 -4
M callback_test.go +22 -3
@@ -58,7 +58,8 @@ func TestNewCallbackFloat64(t *testing.T) {
5858 var cbTotal int
5959 var cbTotalF float64
6060 imp := purego.NewCallback(func(a1, a2, a3, a4, a5, a6, a7, a8, a9 int,
61- f1, f2, f3, f4, f5, f6, f7, f8 float64) {
61+ f1, f2, f3, f4, f5, f6, f7, f8 float64,
62+ ) {
6263 cbTotal = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9
6364 cbTotalF = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8
6465 })
@@ -76,6 +77,24 @@ func TestNewCallbackFloat64(t *testing.T) {
7677 }
7778 }
7879
80+func TestNewCallbackFloat64AndIntMix(t *testing.T) {
81+ // This tests interleaving float and integer arguments to NewCallback
82+ const (
83+ expectCbTotal = 54.75
84+ )
85+ var cbTotal float64
86+ imp := purego.NewCallback(func(a1, a2 float64, a3, a4, a5 int, a6, a7, a8 float64, a9 int) {
87+ cbTotal = a1 + a2 + float64(a3) + float64(a4) + float64(a5) + a6 + a7 + a8 + float64(a9)
88+ })
89+ var fn func(a1, a2 float64, a3, a4, a5 int, a6, a7, a8 float64, a9 int)
90+ purego.RegisterFunc(&fn, imp)
91+ fn(1.25, 3.25, 4, 5, 6, 7.5, 8.25, 9.5, 10)
92+
93+ if cbTotal != expectCbTotal {
94+ t.Errorf("cbTotal not correct got %f but wanted %f", cbTotal, expectCbTotal)
95+ }
96+}
97+
7998 func TestNewCallbackFloat32(t *testing.T) {
8099 // This tests the maximum number of float32 arguments a function to NewCallback can take
81100 const (
@@ -85,7 +104,8 @@ func TestNewCallbackFloat32(t *testing.T) {
85104 var cbTotal int
86105 var cbTotalF float32
87106 imp := purego.NewCallback(func(a1, a2, a3, a4, a5, a6, a7, a8 int,
88- f1, f2, f3, f4, f5, f6, f7, f8, f9 float32) {
107+ f1, f2, f3, f4, f5, f6, f7, f8, f9 float32,
108+ ) {
89109 cbTotal = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
90110 cbTotalF = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9
91111 })
@@ -114,7 +134,6 @@ func TestNewCallbackFloat32AndFloat64(t *testing.T) {
114134 imp := purego.NewCallback(func(f1, f2, f3 float32, f4, f5, f6 float64, f7, f8, f9 float32) {
115135 cbTotalF32 = f1 + f2 + f3 + f7 + f8 + f9
116136 cbTotalF64 = f4 + f5 + f6
117-
118137 })
119138 var fn func(f1, f2, f3 float32, f4, f5, f6 float64, f7, f8, f9 float32)
120139 purego.RegisterFunc(&fn, imp)
@@ -58,7 +58,8 @@ func TestNewCallbackFloat64(t *testing.T) {
58 var cbTotal int58 var cbTotal int
59 var cbTotalF float6459 var cbTotalF float64
60 imp := purego.NewCallback(func(a1, a2, a3, a4, a5, a6, a7, a8, a9 int,60 imp := purego.NewCallback(func(a1, a2, a3, a4, a5, a6, a7, a8, a9 int,
61- f1, f2, f3, f4, f5, f6, f7, f8 float64) {61+ f1, f2, f3, f4, f5, f6, f7, f8 float64,
62+ ) {
62 cbTotal = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a963 cbTotal = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9
63 cbTotalF = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f864 cbTotalF = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8
64 })65 })
@@ -76,6 +77,24 @@ func TestNewCallbackFloat64(t *testing.T) {
76 }77 }
77 }78 }
78 79
80+func TestNewCallbackFloat64AndIntMix(t *testing.T) {
81+ // This tests interleaving float and integer arguments to NewCallback
82+ const (
83+ expectCbTotal = 54.75
84+ )
85+ var cbTotal float64
86+ imp := purego.NewCallback(func(a1, a2 float64, a3, a4, a5 int, a6, a7, a8 float64, a9 int) {
87+ cbTotal = a1 + a2 + float64(a3) + float64(a4) + float64(a5) + a6 + a7 + a8 + float64(a9)
88+ })
89+ var fn func(a1, a2 float64, a3, a4, a5 int, a6, a7, a8 float64, a9 int)
90+ purego.RegisterFunc(&fn, imp)
91+ fn(1.25, 3.25, 4, 5, 6, 7.5, 8.25, 9.5, 10)
92+
93+ if cbTotal != expectCbTotal {
94+ t.Errorf("cbTotal not correct got %f but wanted %f", cbTotal, expectCbTotal)
95+ }
96+}
97+
79 func TestNewCallbackFloat32(t *testing.T) {98 func TestNewCallbackFloat32(t *testing.T) {
80 // This tests the maximum number of float32 arguments a function to NewCallback can take99 // This tests the maximum number of float32 arguments a function to NewCallback can take
81 const (100 const (
@@ -85,7 +104,8 @@ func TestNewCallbackFloat32(t *testing.T) {
85 var cbTotal int104 var cbTotal int
86 var cbTotalF float32105 var cbTotalF float32
87 imp := purego.NewCallback(func(a1, a2, a3, a4, a5, a6, a7, a8 int,106 imp := purego.NewCallback(func(a1, a2, a3, a4, a5, a6, a7, a8 int,
88- f1, f2, f3, f4, f5, f6, f7, f8, f9 float32) {107+ f1, f2, f3, f4, f5, f6, f7, f8, f9 float32,
108+ ) {
89 cbTotal = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8109 cbTotal = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
90 cbTotalF = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9110 cbTotalF = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9
91 })111 })
@@ -114,7 +134,6 @@ func TestNewCallbackFloat32AndFloat64(t *testing.T) {
114 imp := purego.NewCallback(func(f1, f2, f3 float32, f4, f5, f6 float64, f7, f8, f9 float32) {134 imp := purego.NewCallback(func(f1, f2, f3 float32, f4, f5, f6 float64, f7, f8, f9 float32) {
115 cbTotalF32 = f1 + f2 + f3 + f7 + f8 + f9135 cbTotalF32 = f1 + f2 + f3 + f7 + f8 + f9
116 cbTotalF64 = f4 + f5 + f6136 cbTotalF64 = f4 + f5 + f6
117-
118 })137 })
119 var fn func(f1, f2, f3 float32, f4, f5, f6 float64, f7, f8, f9 float32)138 var fn func(f1, f2, f3 float32, f4, f5, f6 float64, f7, f8, f9 float32)
120 purego.RegisterFunc(&fn, imp)139 purego.RegisterFunc(&fn, imp)
M func.go +1 -1
@@ -245,7 +245,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
245245 runtime_cgocall(syscall9XABI0, unsafe.Pointer(&syscall))
246246 r1, r2 = syscall.r1, syscall.r2
247247 } else {
248- // This is a fallback for amd64, 386, and arm. Note this may not support floats
248+ // This is a fallback for Windows amd64, 386, and arm. Note this may not support floats
249249 r1, r2, _ = syscall_syscall9X(cfn, sysargs[0], sysargs[1], sysargs[2], sysargs[3], sysargs[4], sysargs[5], sysargs[6], sysargs[7], sysargs[8])
250250 }
251251 if ty.NumOut() == 0 {
@@ -245,7 +245,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
245 runtime_cgocall(syscall9XABI0, unsafe.Pointer(&syscall))245 runtime_cgocall(syscall9XABI0, unsafe.Pointer(&syscall))
246 r1, r2 = syscall.r1, syscall.r2246 r1, r2 = syscall.r1, syscall.r2
247 } else {247 } else {
248- // This is a fallback for amd64, 386, and arm. Note this may not support floats248+ // This is a fallback for Windows amd64, 386, and arm. Note this may not support floats
249 r1, r2, _ = syscall_syscall9X(cfn, sysargs[0], sysargs[1], sysargs[2], sysargs[3], sysargs[4], sysargs[5], sysargs[6], sysargs[7], sysargs[8])249 r1, r2, _ = syscall_syscall9X(cfn, sysargs[0], sysargs[1], sysargs[2], sysargs[3], sysargs[4], sysargs[5], sysargs[6], sysargs[7], sysargs[8])
250 }250 }
251 if ty.NumOut() == 0 {251 if ty.NumOut() == 0 {

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close