detached 4f3e551

purego: enumerate types that can be returned from callbacks (#58)

explicitly enumerates which types can be returned from a callback. It also adds support for returning reflect.Pointer and reflect.UnsafePointer
commit
4f3e551a671be4b5946962a5ecd87f9cbb655cf9
author
TotallyGamerJet · · 2022-11-01 17:25 UTC
committer
GitHub · · 2022-11-01 17:25 UTC
parent
fbeb60f
signature
GPG Unverified4AEE18F83AFDEB23 The key is unknown
1 file · +16 -2
M syscall_darwin.go +16 -2
@@ -75,8 +75,18 @@ func compileCallback(fn interface{}) uintptr {
7575 panic("purego: unsupported argument type: " + in.Kind().String())
7676 }
7777 }
78- if ty.NumOut() > 1 || ty.NumOut() == 1 && ty.Out(0).Size() != ptrSize {
79- panic("purego: callbacks can only have one pointer-sized return")
78+output:
79+ switch {
80+ case ty.NumOut() == 1:
81+ switch ty.Out(0).Kind() {
82+ case reflect.Pointer, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
83+ reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
84+ reflect.Bool, reflect.UnsafePointer:
85+ break output
86+ }
87+ panic("purego: unsupported return type: " + ty.String())
88+ case ty.NumOut() > 1:
89+ panic("purego: callbacks can only have one return")
8090 }
8191 cbs.lock.Lock()
8292 defer cbs.lock.Unlock()
@@ -121,6 +131,10 @@ func callbackWrap(a *callbackArgs) {
121131 } else {
122132 a.result = 0
123133 }
134+ case reflect.Pointer:
135+ a.result = ret[0].Pointer()
136+ case reflect.UnsafePointer:
137+ a.result = ret[0].Pointer()
124138 default:
125139 panic("purego: unsupported kind: " + k.String())
126140 }
@@ -75,8 +75,18 @@ func compileCallback(fn interface{}) uintptr {
75 panic("purego: unsupported argument type: " + in.Kind().String())75 panic("purego: unsupported argument type: " + in.Kind().String())
76 }76 }
77 }77 }
78- if ty.NumOut() > 1 || ty.NumOut() == 1 && ty.Out(0).Size() != ptrSize {78+output:
79- panic("purego: callbacks can only have one pointer-sized return")79+ switch {
80+ case ty.NumOut() == 1:
81+ switch ty.Out(0).Kind() {
82+ case reflect.Pointer, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
83+ reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
84+ reflect.Bool, reflect.UnsafePointer:
85+ break output
86+ }
87+ panic("purego: unsupported return type: " + ty.String())
88+ case ty.NumOut() > 1:
89+ panic("purego: callbacks can only have one return")
80 }90 }
81 cbs.lock.Lock()91 cbs.lock.Lock()
82 defer cbs.lock.Unlock()92 defer cbs.lock.Unlock()
@@ -121,6 +131,10 @@ func callbackWrap(a *callbackArgs) {
121 } else {131 } else {
122 a.result = 0132 a.result = 0
123 }133 }
134+ case reflect.Pointer:
135+ a.result = ret[0].Pointer()
136+ case reflect.UnsafePointer:
137+ a.result = ret[0].Pointer()
124 default:138 default:
125 panic("purego: unsupported kind: " + k.String())139 panic("purego: unsupported kind: " + k.String())
126 }140 }

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