Skip to content

Commit 76a2508

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 76a2508

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

syscall_bench_test.go

Lines changed: 9 additions & 4 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,23 +44,27 @@ 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 {
5459
testCases[i].fnPtr = purego.NewCallback(testCases[i].fn)
5560

56-
cFn, err := purego.Dlsym(libHandle, testCases[i].cFnName)
61+
cFn, err := load.OpenSymbol(libHandle, testCases[i].cFnName)
5762
if err != nil {
5863
b.Fatalf("Failed to load C function %s: %v", testCases[i].cFnName, err)
5964
}
6065
testCases[i].cFnPtr = cFn
6166

62-
cCallbackFn, err := purego.Dlsym(libHandle, testCases[i].cCallbackName)
67+
cCallbackFn, err := load.OpenSymbol(libHandle, testCases[i].cCallbackName)
6368
if err != nil {
6469
b.Fatalf("Failed to load C callback wrapper %s: %v", testCases[i].cCallbackName, err)
6570
}

0 commit comments

Comments
 (0)