detached 90cebfb

test: harden abi helper coverage

commit
90cebfbd3ff850bfc390973db0ed14be0697e56b
author
brice · · 2026-04-13 09:50 UTC
parent
2cdd607
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +36 -2
M struct_abi_helpers.go +5 -2
@@ -1,3 +1,6 @@
1+// SPDX-License-Identifier: Apache-2.0
2+// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
3+
14 package purego
25
36 import (
@@ -7,11 +10,11 @@ import (
710 )
811
912 func packFloat32Pair(low, high uintptr) uintptr {
10- return high<<32 | (low & math.MaxUint32)
13+ return uintptr((uint64(high) << 32) | (uint64(low) & math.MaxUint32))
1114 }
1215
1316 func highFloat32Bits(word uintptr) uint32 {
14- return uint32(word >> 32)
17+ return uint32(uint64(word) >> 32)
1518 }
1619
1720 func flushPackedWord(val *uint64, shift *byte, flushed *bool, isFloat bool, addFloat, addInt func(uintptr)) {
@@ -1,3 +1,6 @@
1+// SPDX-License-Identifier: Apache-2.0
2+// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
3+
1 package purego4 package purego
2 5
3 import (6 import (
@@ -7,11 +10,11 @@ import (
7 )10 )
8 11
9 func packFloat32Pair(low, high uintptr) uintptr {12 func packFloat32Pair(low, high uintptr) uintptr {
10- return high<<32 | (low & math.MaxUint32)13+ return uintptr((uint64(high) << 32) | (uint64(low) & math.MaxUint32))
11 }14 }
12 15
13 func highFloat32Bits(word uintptr) uint32 {16 func highFloat32Bits(word uintptr) uint32 {
14- return uint32(word >> 32)17+ return uint32(uint64(word) >> 32)
15 }18 }
16 19
17 func flushPackedWord(val *uint64, shift *byte, flushed *bool, isFloat bool, addFloat, addInt func(uintptr)) {20 func flushPackedWord(val *uint64, shift *byte, flushed *bool, isFloat bool, addFloat, addInt func(uintptr)) {
M struct_abi_helpers_test.go +31 -0
@@ -1,3 +1,6 @@
1+// SPDX-License-Identifier: Apache-2.0
2+// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
3+
14 package purego
25
36 import (
@@ -38,6 +41,22 @@ func TestFlushPackedWordResetsState(t *testing.T) {
3841 }
3942 }
4043
44+func TestFlushPackedWordResetsStateForIntegerBranch(t *testing.T) {
45+ var val uint64 = 0x55667788
46+ shift := byte(16)
47+ flushed := false
48+ var gotInt uintptr
49+ flushPackedWord(&val, &shift, &flushed, false, func(uintptr) {
50+ t.Fatal("unexpected float flush")
51+ }, func(v uintptr) { gotInt = v })
52+ if !flushed || val != 0 || shift != 0 {
53+ t.Fatalf("flushPackedWord() left state dirty: flushed=%v val=%#x shift=%d", flushed, val, shift)
54+ }
55+ if gotInt != 0x55667788 {
56+ t.Fatalf("flushPackedWord() flushed %#x, want %#x", gotInt, uintptr(0x55667788))
57+ }
58+}
59+
4160 func TestStableValuePointerCopiesUnaddressableValue(t *testing.T) {
4261 type sample struct{ X uint32 }
4362 ptr, keepAlive := stableValuePointer(reflect.ValueOf(sample{X: 7}))
@@ -49,6 +68,18 @@ func TestStableValuePointerCopiesUnaddressableValue(t *testing.T) {
4968 }
5069 }
5170
71+func TestStableValuePointerUsesAddressableValue(t *testing.T) {
72+ type sample struct{ X uint32 }
73+ value := sample{X: 9}
74+ ptr, keepAlive := stableValuePointer(reflect.ValueOf(&value).Elem())
75+ if keepAlive != nil {
76+ t.Fatal("expected nil keepAlive for addressable value")
77+ }
78+ if got := *(*uint32)(ptr); got != 9 {
79+ t.Fatalf("stableValuePointer() pointed to %#x, want %#x", got, uint32(9))
80+ }
81+}
82+
5283 func TestIsAllSameFloatRejectsNestedMixedStruct(t *testing.T) {
5384 type inner struct{ X, Y float32 }
5485 type mixed struct {
@@ -1,3 +1,6 @@
1+// SPDX-License-Identifier: Apache-2.0
2+// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
3+
1 package purego4 package purego
2 5
3 import (6 import (
@@ -38,6 +41,22 @@ func TestFlushPackedWordResetsState(t *testing.T) {
38 }41 }
39 }42 }
40 43
44+func TestFlushPackedWordResetsStateForIntegerBranch(t *testing.T) {
45+ var val uint64 = 0x55667788
46+ shift := byte(16)
47+ flushed := false
48+ var gotInt uintptr
49+ flushPackedWord(&val, &shift, &flushed, false, func(uintptr) {
50+ t.Fatal("unexpected float flush")
51+ }, func(v uintptr) { gotInt = v })
52+ if !flushed || val != 0 || shift != 0 {
53+ t.Fatalf("flushPackedWord() left state dirty: flushed=%v val=%#x shift=%d", flushed, val, shift)
54+ }
55+ if gotInt != 0x55667788 {
56+ t.Fatalf("flushPackedWord() flushed %#x, want %#x", gotInt, uintptr(0x55667788))
57+ }
58+}
59+
41 func TestStableValuePointerCopiesUnaddressableValue(t *testing.T) {60 func TestStableValuePointerCopiesUnaddressableValue(t *testing.T) {
42 type sample struct{ X uint32 }61 type sample struct{ X uint32 }
43 ptr, keepAlive := stableValuePointer(reflect.ValueOf(sample{X: 7}))62 ptr, keepAlive := stableValuePointer(reflect.ValueOf(sample{X: 7}))
@@ -49,6 +68,18 @@ func TestStableValuePointerCopiesUnaddressableValue(t *testing.T) {
49 }68 }
50 }69 }
51 70
71+func TestStableValuePointerUsesAddressableValue(t *testing.T) {
72+ type sample struct{ X uint32 }
73+ value := sample{X: 9}
74+ ptr, keepAlive := stableValuePointer(reflect.ValueOf(&value).Elem())
75+ if keepAlive != nil {
76+ t.Fatal("expected nil keepAlive for addressable value")
77+ }
78+ if got := *(*uint32)(ptr); got != 9 {
79+ t.Fatalf("stableValuePointer() pointed to %#x, want %#x", got, uint32(9))
80+ }
81+}
82+
52 func TestIsAllSameFloatRejectsNestedMixedStruct(t *testing.T) {83 func TestIsAllSameFloatRejectsNestedMixedStruct(t *testing.T) {
53 type inner struct{ X, Y float32 }84 type inner struct{ X, Y float32 }
54 type mixed struct {85 type mixed struct {

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