detached 39f180a

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

Closes #183
commit
39f180a6cfccb18fdae1af6a7999064f3bd4d0fd
author
JupiterRider · · 2023-11-22 02:48 UTC
committer
Hajime Hoshi · · 2023-11-22 02:48 UTC
parent
c9a29b2
signature
unsigned
2 files · +15 -1
M func.go +1 -1
@@ -263,7 +263,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
263263 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
264264 v.SetInt(int64(r1))
265265 case reflect.Bool:
266- v.SetBool(r1 != 0)
266+ v.SetBool(byte(r1) != 0)
267267 case reflect.UnsafePointer:
268268 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer
269269 v.SetPointer(*(*unsafe.Pointer)(unsafe.Pointer(&r1)))
@@ -263,7 +263,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
263 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:263 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
264 v.SetInt(int64(r1))264 v.SetInt(int64(r1))
265 case reflect.Bool:265 case reflect.Bool:
266- v.SetBool(r1 != 0)266+ v.SetBool(byte(r1) != 0)
267 case reflect.UnsafePointer:267 case reflect.UnsafePointer:
268 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer268 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer
269 v.SetPointer(*(*unsafe.Pointer)(unsafe.Pointer(&r1)))269 v.SetPointer(*(*unsafe.Pointer)(unsafe.Pointer(&r1)))
M func_test.go +14 -0
@@ -137,3 +137,17 @@ func TestRegisterFunc_Floats(t *testing.T) {
137137 }
138138 }
139139 }
140+
141+func TestRegisterLibFunc_Bool(t *testing.T) {
142+ // this callback recreates the state where the return register
143+ // contains other information but the least significant byte is false
144+ cbFalse := purego.NewCallback(func() uintptr {
145+ return 0x7F5948AE9A00
146+ })
147+ var runFalse func() bool
148+ purego.RegisterFunc(&runFalse, cbFalse)
149+ expected := false
150+ if got := runFalse(); got != expected {
151+ t.Errorf("runFalse failed. got %t but wanted %t", got, expected)
152+ }
153+}
@@ -137,3 +137,17 @@ func TestRegisterFunc_Floats(t *testing.T) {
137 }137 }
138 }138 }
139 }139 }
140+
141+func TestRegisterLibFunc_Bool(t *testing.T) {
142+ // this callback recreates the state where the return register
143+ // contains other information but the least significant byte is false
144+ cbFalse := purego.NewCallback(func() uintptr {
145+ return 0x7F5948AE9A00
146+ })
147+ var runFalse func() bool
148+ purego.RegisterFunc(&runFalse, cbFalse)
149+ expected := false
150+ if got := runFalse(); got != expected {
151+ t.Errorf("runFalse failed. got %t but wanted %t", got, expected)
152+ }
153+}

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