detached 192c5e8

purego: change how bool return values are converted (#181)

Closes #183
commit
192c5e846faa64025fb8a6a94532c7a77fbd8dce
author
JupiterRider · · 2023-11-22 02:48 UTC
committer
GitHub · · 2023-11-22 02:48 UTC
parent
7e00a08
signature
GPG Unverified4AEE18F83AFDEB23 The key is unknown
refs
tag: v0.6.0-alpha.2
2 files · +15 -1
M func.go +1 -1
@@ -259,7 +259,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
259259 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
260260 v.SetInt(int64(r1))
261261 case reflect.Bool:
262- v.SetBool(r1 != 0)
262+ v.SetBool(byte(r1) != 0)
263263 case reflect.UnsafePointer:
264264 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer
265265 v.SetPointer(*(*unsafe.Pointer)(unsafe.Pointer(&r1)))
@@ -259,7 +259,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
259 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:259 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
260 v.SetInt(int64(r1))260 v.SetInt(int64(r1))
261 case reflect.Bool:261 case reflect.Bool:
262- v.SetBool(r1 != 0)262+ v.SetBool(byte(r1) != 0)
263 case reflect.UnsafePointer:263 case reflect.UnsafePointer:
264 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer264 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer
265 v.SetPointer(*(*unsafe.Pointer)(unsafe.Pointer(&r1)))265 v.SetPointer(*(*unsafe.Pointer)(unsafe.Pointer(&r1)))
M func_test.go +14 -0
@@ -121,3 +121,17 @@ func TestRegisterFunc_Floats(t *testing.T) {
121121 }
122122 }
123123 }
124+
125+func TestRegisterLibFunc_Bool(t *testing.T) {
126+ // this callback recreates the state where the return register
127+ // contains other information but the least significant byte is false
128+ cbFalse := purego.NewCallback(func() uintptr {
129+ return 0x7F5948AE9A00
130+ })
131+ var runFalse func() bool
132+ purego.RegisterFunc(&runFalse, cbFalse)
133+ expected := false
134+ if got := runFalse(); got != expected {
135+ t.Errorf("runFalse failed. got %t but wanted %t", got, expected)
136+ }
137+}
@@ -121,3 +121,17 @@ func TestRegisterFunc_Floats(t *testing.T) {
121 }121 }
122 }122 }
123 }123 }
124+
125+func TestRegisterLibFunc_Bool(t *testing.T) {
126+ // this callback recreates the state where the return register
127+ // contains other information but the least significant byte is false
128+ cbFalse := purego.NewCallback(func() uintptr {
129+ return 0x7F5948AE9A00
130+ })
131+ var runFalse func() bool
132+ purego.RegisterFunc(&runFalse, cbFalse)
133+ expected := false
134+ if got := runFalse(); got != expected {
135+ t.Errorf("runFalse failed. got %t but wanted %t", got, expected)
136+ }
137+}

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