Skip to content

Commit a2f31c7

Browse files
committed
purego: refactor benchmark test to use internal load API
Replace direct purego.Dlopen/Dlclose calls with load.OpenLibrary/CloseLibrary from the internal load package for consistency with other test code. Includes proper error handling in the defer cleanup function.
1 parent 165b8d2 commit a2f31c7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

syscall_bench_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111

1212
"github.com/ebitengine/purego"
13+
"github.com/ebitengine/purego/internal/load"
1314
)
1415

1516
// BenchmarkCallingMethods compares RegisterFunc, SyscallN, and Callback methods
@@ -43,11 +44,15 @@ func BenchmarkCallingMethods(b *testing.B) {
4344
os.Remove(libFileName)
4445
})
4546

46-
libHandle, err := purego.Dlopen(libFileName, purego.RTLD_NOW|purego.RTLD_GLOBAL)
47+
libHandle, err := load.OpenLibrary(libFileName)
4748
if err != nil {
4849
b.Fatalf("Failed to load C library: %v", err)
4950
}
50-
defer purego.Dlclose(libHandle)
51+
defer func() {
52+
if err := load.CloseLibrary(libHandle); err != nil {
53+
b.Fatalf("Failed to close library: %s", err)
54+
}
55+
}()
5156

5257
// Create callbacks and load C functions
5358
for i := range testCases {

0 commit comments

Comments
 (0)