purego: remove r1, r2, err fields as they are no longer used (#218)
When struct returns were added I stopped using r1, and r2 for return values. In doing so I did not update purego.SyscallN which ebitengine uses for Metal and OpenGL. This PR fully removes those fields and fixes purego.SyscallN to return the proper values. Closes #217
- commit
- 21128fad3408ea554637d1a2dfc1b9032e7a39a2
- author
- TotallyGamerJet · · 2024-02-29 17:57 UTC
- committer
- GitHub · · 2024-02-29 17:57 UTC
- parent
- 9ef47a2
- signature
- GPG Unverified
B5690EEEBB952194The key is unknown - refs
- tag: v0.7.0-alpha.3
4 files · +16 -5
M dlfcn_test.go +13 -0
| @@ -14,6 +14,7 @@ import ( | |||
| 14 | 14 | "runtime" | |
| 15 | 15 | "strings" | |
| 16 | 16 | "testing" | |
| 17 | + | "unsafe" | |
| 17 | 18 | ||
| 18 | 19 | "github.com/ebitengine/purego" | |
| 19 | 20 | ) | |
| @@ -81,3 +82,15 @@ func buildSharedLib(compilerEnv, libFile string, sources ...string) error { | |||
| 81 | 82 | ||
| 82 | 83 | return nil | |
| 83 | 84 | } | |
| 85 | + | ||
| 86 | + | func TestSyscallN(t *testing.T) { | |
| 87 | + | var dlsym uintptr | |
| 88 | + | var err error | |
| 89 | + | if dlsym, err = purego.Dlsym(purego.RTLD_DEFAULT, "dlsym"); err != nil { | |
| 90 | + | t.Errorf("Dlsym with RTLD_DEFAULT failed: %v", err) | |
| 91 | + | } | |
| 92 | + | r1, _, err2 := purego.SyscallN(dlsym, purego.RTLD_DEFAULT, uintptr(unsafe.Pointer(&[]byte("dlsym\x00")[0]))) | |
| 93 | + | if dlsym != r1 { | |
| 94 | + | t.Fatalf("SyscallN didn't return the same result as purego.Dlsym: %d", err2) | |
| 95 | + | } | |
| 96 | + | } | |
| @@ -14,6 +14,7 @@ import ( | |||||
| 14 | "runtime" | 14 | "runtime" | ||
| 15 | "strings" | 15 | "strings" | ||
| 16 | "testing" | 16 | "testing" | ||
| 17 | + | "unsafe" | |||
| 17 | 18 | ||||
| 18 | "github.com/ebitengine/purego" | 19 | "github.com/ebitengine/purego" | ||
| 19 | ) | 20 | ) | ||
| @@ -81,3 +82,15 @@ func buildSharedLib(compilerEnv, libFile string, sources ...string) error { | |||||
| 81 | 82 | ||||
| 82 | return nil | 83 | return nil | ||
| 83 | } | 84 | } | ||
| 85 | + | ||||
| 86 | + | func TestSyscallN(t *testing.T) { | |||
| 87 | + | var dlsym uintptr | |||
| 88 | + | var err error | |||
| 89 | + | if dlsym, err = purego.Dlsym(purego.RTLD_DEFAULT, "dlsym"); err != nil { | |||
| 90 | + | t.Errorf("Dlsym with RTLD_DEFAULT failed: %v", err) | |||
| 91 | + | } | |||
| 92 | + | r1, _, err2 := purego.SyscallN(dlsym, purego.RTLD_DEFAULT, uintptr(unsafe.Pointer(&[]byte("dlsym\x00")[0]))) | |||
| 93 | + | if dlsym != r1 { | |||
| 94 | + | t.Fatalf("SyscallN didn't return the same result as purego.Dlsym: %d", err2) | |||
| 95 | + | } | |||
| 96 | + | } | |||
M func.go +1 -1
| @@ -296,7 +296,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) { | |||
| 296 | 296 | sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11], | |
| 297 | 297 | sysargs[12], sysargs[13], sysargs[14], | |
| 298 | 298 | floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6], floats[7], | |
| 299 | - | 0, 0, 0, syscall.arm64_r8, | |
| 299 | + | syscall.arm64_r8, | |
| 300 | 300 | } | |
| 301 | 301 | runtime_cgocall(syscall15XABI0, unsafe.Pointer(&syscall)) | |
| 302 | 302 | } else { | |
| @@ -296,7 +296,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) { | |||||
| 296 | sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11], | 296 | sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11], | ||
| 297 | sysargs[12], sysargs[13], sysargs[14], | 297 | sysargs[12], sysargs[13], sysargs[14], | ||
| 298 | floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6], floats[7], | 298 | floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6], floats[7], | ||
| 299 | - | 0, 0, 0, syscall.arm64_r8, | 299 | + | syscall.arm64_r8, |
| 300 | } | 300 | } | ||
| 301 | runtime_cgocall(syscall15XABI0, unsafe.Pointer(&syscall)) | 301 | runtime_cgocall(syscall15XABI0, unsafe.Pointer(&syscall)) | ||
| 302 | } else { | 302 | } else { | ||
M syscall_sysv.go +2 -3
| @@ -17,7 +17,6 @@ var syscall15XABI0 uintptr | |||
| 17 | 17 | type syscall15Args struct { | |
| 18 | 18 | fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr | |
| 19 | 19 | f1, f2, f3, f4, f5, f6, f7, f8 uintptr | |
| 20 | - | r1, r2, err uintptr | |
| 21 | 20 | arm64_r8 uintptr | |
| 22 | 21 | } | |
| 23 | 22 | ||
| @@ -26,10 +25,10 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a | |||
| 26 | 25 | args := syscall15Args{ | |
| 27 | 26 | fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, | |
| 28 | 27 | a1, a2, a3, a4, a5, a6, a7, a8, | |
| 29 | - | r1, r2, err, 0, | |
| 28 | + | 0, | |
| 30 | 29 | } | |
| 31 | 30 | runtime_cgocall(syscall15XABI0, unsafe.Pointer(&args)) | |
| 32 | - | return args.r1, args.r2, args.err | |
| 31 | + | return args.a1, args.a2, 0 | |
| 33 | 32 | } | |
| 34 | 33 | ||
| 35 | 34 | // NewCallback converts a Go function to a function pointer conforming to the C calling convention. | |
| @@ -17,7 +17,6 @@ var syscall15XABI0 uintptr | |||||
| 17 | type syscall15Args struct { | 17 | type syscall15Args struct { | ||
| 18 | fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr | 18 | fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr | ||
| 19 | f1, f2, f3, f4, f5, f6, f7, f8 uintptr | 19 | f1, f2, f3, f4, f5, f6, f7, f8 uintptr | ||
| 20 | - | r1, r2, err uintptr | |||
| 21 | arm64_r8 uintptr | 20 | arm64_r8 uintptr | ||
| 22 | } | 21 | } | ||
| 23 | 22 | ||||
| @@ -26,10 +25,10 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a | |||||
| 26 | args := syscall15Args{ | 25 | args := syscall15Args{ | ||
| 27 | fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, | 26 | fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, | ||
| 28 | a1, a2, a3, a4, a5, a6, a7, a8, | 27 | a1, a2, a3, a4, a5, a6, a7, a8, | ||
| 29 | - | r1, r2, err, 0, | 28 | + | 0, |
| 30 | } | 29 | } | ||
| 31 | runtime_cgocall(syscall15XABI0, unsafe.Pointer(&args)) | 30 | runtime_cgocall(syscall15XABI0, unsafe.Pointer(&args)) | ||
| 32 | - | return args.r1, args.r2, args.err | 31 | + | return args.a1, args.a2, 0 |
| 33 | } | 32 | } | ||
| 34 | 33 | ||||
| 35 | // NewCallback converts a Go function to a function pointer conforming to the C calling convention. | 34 | // NewCallback converts a Go function to a function pointer conforming to the C calling convention. | ||
M syscall_windows.go +0 -1
| @@ -15,7 +15,6 @@ var syscall15XABI0 uintptr | |||
| 15 | 15 | type syscall15Args struct { | |
| 16 | 16 | fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr | |
| 17 | 17 | f1, f2, f3, f4, f5, f6, f7, f8 uintptr | |
| 18 | - | r1, r2, err uintptr | |
| 19 | 18 | arm64_r8 uintptr | |
| 20 | 19 | } | |
| 21 | 20 | ||
| @@ -15,7 +15,6 @@ var syscall15XABI0 uintptr | |||||
| 15 | type syscall15Args struct { | 15 | type syscall15Args struct { | ||
| 16 | fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr | 16 | fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr | ||
| 17 | f1, f2, f3, f4, f5, f6, f7, f8 uintptr | 17 | f1, f2, f3, f4, f5, f6, f7, f8 uintptr | ||
| 18 | - | r1, r2, err uintptr | |||
| 19 | arm64_r8 uintptr | 18 | arm64_r8 uintptr | ||
| 20 | } | 19 | } | ||
| 21 | 20 | ||||