detached 05b0c8f

Allow uintptr in struct on amd64 (#317)

commit
05b0c8f6678f4003e390daf3ea24bd99606d6e35
author
TotallyGamerJet · · 2025-05-13 17:54 UTC
committer
GitHub · · 2025-05-13 17:54 UTC
parent
5047c08
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
refs
tag: v0.9.0-alpha.5
3 files · +15 -2
M struct_amd64.go +2 -2
@@ -200,7 +200,7 @@ func tryPlaceRegister(v reflect.Value, addFloat func(uintptr), addInt func(uintp
200200 val |= f.Uint() << shift
201201 shift += 32
202202 class |= _INTEGER
203- case reflect.Uint64, reflect.Uint:
203+ case reflect.Uint64, reflect.Uint, reflect.Uintptr:
204204 val = f.Uint()
205205 shift = 64
206206 class = _INTEGER
@@ -245,7 +245,7 @@ func placeStack(v reflect.Value, addStack func(uintptr)) {
245245 addStack(f.Pointer())
246246 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
247247 addStack(uintptr(f.Int()))
248- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
248+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
249249 addStack(uintptr(f.Uint()))
250250 case reflect.Float32:
251251 addStack(uintptr(math.Float32bits(float32(f.Float()))))
@@ -200,7 +200,7 @@ func tryPlaceRegister(v reflect.Value, addFloat func(uintptr), addInt func(uintp
200 val |= f.Uint() << shift200 val |= f.Uint() << shift
201 shift += 32201 shift += 32
202 class |= _INTEGER202 class |= _INTEGER
203- case reflect.Uint64, reflect.Uint:203+ case reflect.Uint64, reflect.Uint, reflect.Uintptr:
204 val = f.Uint()204 val = f.Uint()
205 shift = 64205 shift = 64
206 class = _INTEGER206 class = _INTEGER
@@ -245,7 +245,7 @@ func placeStack(v reflect.Value, addStack func(uintptr)) {
245 addStack(f.Pointer())245 addStack(f.Pointer())
246 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:246 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
247 addStack(uintptr(f.Int()))247 addStack(uintptr(f.Int()))
248- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:248+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
249 addStack(uintptr(f.Uint()))249 addStack(uintptr(f.Uint()))
250 case reflect.Float32:250 case reflect.Float32:
251 addStack(uintptr(math.Float32bits(float32(f.Float()))))251 addStack(uintptr(math.Float32bits(float32(f.Float()))))
M struct_test.go +9 -0
@@ -463,6 +463,15 @@ func TestRegisterFunc_structArgs(t *testing.T) {
463463 t.Fatalf("GoUint4Fn returned %d wanted %#x", ret, expected)
464464 }
465465 }
466+ {
467+ type OneLong struct{ a uintptr }
468+ var TakeGoUintAndReturn func(a OneLong) uint64
469+ purego.RegisterLibFunc(&TakeGoUintAndReturn, lib, "TakeGoUintAndReturn")
470+ expected := uint64(7)
471+ if ret := TakeGoUintAndReturn(OneLong{7}); ret != expected {
472+ t.Fatalf("TakeGoUintAndReturn returned %+v wanted %+v", ret, expected)
473+ }
474+ }
466475 }
467476
468477 func TestRegisterFunc_structReturns(t *testing.T) {
@@ -463,6 +463,15 @@ func TestRegisterFunc_structArgs(t *testing.T) {
463 t.Fatalf("GoUint4Fn returned %d wanted %#x", ret, expected)463 t.Fatalf("GoUint4Fn returned %d wanted %#x", ret, expected)
464 }464 }
465 }465 }
466+ {
467+ type OneLong struct{ a uintptr }
468+ var TakeGoUintAndReturn func(a OneLong) uint64
469+ purego.RegisterLibFunc(&TakeGoUintAndReturn, lib, "TakeGoUintAndReturn")
470+ expected := uint64(7)
471+ if ret := TakeGoUintAndReturn(OneLong{7}); ret != expected {
472+ t.Fatalf("TakeGoUintAndReturn returned %+v wanted %+v", ret, expected)
473+ }
474+ }
466 }475 }
467 476
468 func TestRegisterFunc_structReturns(t *testing.T) {477 func TestRegisterFunc_structReturns(t *testing.T) {
M testdata/structtest/struct_test.c +4 -0
@@ -348,3 +348,7 @@ struct GoUint4 {
348348 GoUint GoUint4(struct GoUint4 g) {
349349 return g.a + g.b + g.c + g.d;
350350 }
351+
352+GoUint TakeGoUintAndReturn(GoUint a) {
353+ return a;
354+}
@@ -348,3 +348,7 @@ struct GoUint4 {
348 GoUint GoUint4(struct GoUint4 g) {348 GoUint GoUint4(struct GoUint4 g) {
349 return g.a + g.b + g.c + g.d;349 return g.a + g.b + g.c + g.d;
350 }350 }
351+
352+GoUint TakeGoUintAndReturn(GoUint a) {
353+ return a;
354+}

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