detached 21128fa

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 UnverifiedB5690EEEBB952194 The 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 (
1414 "runtime"
1515 "strings"
1616 "testing"
17+ "unsafe"
1718
1819 "github.com/ebitengine/purego"
1920 )
@@ -81,3 +82,15 @@ func buildSharedLib(compilerEnv, libFile string, sources ...string) error {
8182
8283 return nil
8384 }
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 nil83 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) {
296296 sysargs[6], sysargs[7], sysargs[8], sysargs[9], sysargs[10], sysargs[11],
297297 sysargs[12], sysargs[13], sysargs[14],
298298 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,
300300 }
301301 runtime_cgocall(syscall15XABI0, unsafe.Pointer(&syscall))
302302 } 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
1717 type syscall15Args struct {
1818 fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr
1919 f1, f2, f3, f4, f5, f6, f7, f8 uintptr
20- r1, r2, err uintptr
2120 arm64_r8 uintptr
2221 }
2322
@@ -26,10 +25,10 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
2625 args := syscall15Args{
2726 fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15,
2827 a1, a2, a3, a4, a5, a6, a7, a8,
29- r1, r2, err, 0,
28+ 0,
3029 }
3130 runtime_cgocall(syscall15XABI0, unsafe.Pointer(&args))
32- return args.r1, args.r2, args.err
31+ return args.a1, args.a2, 0
3332 }
3433
3534 // 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 uintptr18 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 uintptr19 f1, f2, f3, f4, f5, f6, f7, f8 uintptr
20- r1, r2, err uintptr
21 arm64_r8 uintptr20 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.err31+ 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
1515 type syscall15Args struct {
1616 fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr
1717 f1, f2, f3, f4, f5, f6, f7, f8 uintptr
18- r1, r2, err uintptr
1918 arm64_r8 uintptr
2019 }
2120
@@ -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 uintptr16 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 uintptr17 f1, f2, f3, f4, f5, f6, f7, f8 uintptr
18- r1, r2, err uintptr
19 arm64_r8 uintptr18 arm64_r8 uintptr
20 }19 }
21 20

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