detached 91aa177

fix: revert scalar return optimization that breaks named types

reflect.ValueOf(uintptr(x)) creates a value of type uintptr, not the
declared return type (e.g., types.GType). reflect.MakeFunc requires
exact type match. Revert to reflect.New(outType).Elem() + Set* which
preserves named type semantics.
commit
91aa177a27043b8d15daac3cb32849fd9916104e
author
brice · · 2026-03-23 09:59 UTC
parent
a02394b
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +6 -27
M func.go +6 -27
@@ -392,35 +392,14 @@ func callAndReturn(ty reflect.Type, is32bit bool, cfn uintptr, sysargs *[maxArgs
392392 return nil
393393 }
394394 outType := ty.Out(0)
395- // Task 5: For simple scalar return types, construct the reflect.Value directly
396- // instead of allocating via reflect.New(outType).Elem().
397- // reflect.ValueOf for scalar types avoids the heap allocation that reflect.New incurs.
398- var v reflect.Value
395+ v := reflect.New(outType).Elem()
399396 switch outType.Kind() {
400- case reflect.Uintptr:
401- v = reflect.ValueOf(uintptr(syscall.a1))
402- case reflect.Uint:
403- v = reflect.ValueOf(uint(syscall.a1))
404- case reflect.Uint8:
405- v = reflect.ValueOf(uint8(syscall.a1))
406- case reflect.Uint16:
407- v = reflect.ValueOf(uint16(syscall.a1))
408- case reflect.Uint32:
409- v = reflect.ValueOf(uint32(syscall.a1))
410- case reflect.Uint64:
411- v = reflect.ValueOf(uint64(syscall.a1))
412- case reflect.Int:
413- v = reflect.ValueOf(int(syscall.a1))
414- case reflect.Int8:
415- v = reflect.ValueOf(int8(syscall.a1))
416- case reflect.Int16:
417- v = reflect.ValueOf(int16(syscall.a1))
418- case reflect.Int32:
419- v = reflect.ValueOf(int32(syscall.a1))
420- case reflect.Int64:
421- v = reflect.ValueOf(int64(syscall.a1))
397+ case reflect.Uintptr, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
398+ v.SetUint(uint64(syscall.a1))
399+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
400+ v.SetInt(int64(syscall.a1))
422401 case reflect.Bool:
423- v = reflect.ValueOf(byte(syscall.a1) != 0)
402+ v.SetBool(byte(syscall.a1) != 0)
424403 case reflect.UnsafePointer:
425404 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer
426405 v = reflect.New(outType).Elem()
@@ -392,35 +392,14 @@ func callAndReturn(ty reflect.Type, is32bit bool, cfn uintptr, sysargs *[maxArgs
392 return nil392 return nil
393 }393 }
394 outType := ty.Out(0)394 outType := ty.Out(0)
395- // Task 5: For simple scalar return types, construct the reflect.Value directly395+ v := reflect.New(outType).Elem()
396- // instead of allocating via reflect.New(outType).Elem().
397- // reflect.ValueOf for scalar types avoids the heap allocation that reflect.New incurs.
398- var v reflect.Value
399 switch outType.Kind() {396 switch outType.Kind() {
400- case reflect.Uintptr:397+ case reflect.Uintptr, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
401- v = reflect.ValueOf(uintptr(syscall.a1))398+ v.SetUint(uint64(syscall.a1))
402- case reflect.Uint:399+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
403- v = reflect.ValueOf(uint(syscall.a1))400+ v.SetInt(int64(syscall.a1))
404- case reflect.Uint8:
405- v = reflect.ValueOf(uint8(syscall.a1))
406- case reflect.Uint16:
407- v = reflect.ValueOf(uint16(syscall.a1))
408- case reflect.Uint32:
409- v = reflect.ValueOf(uint32(syscall.a1))
410- case reflect.Uint64:
411- v = reflect.ValueOf(uint64(syscall.a1))
412- case reflect.Int:
413- v = reflect.ValueOf(int(syscall.a1))
414- case reflect.Int8:
415- v = reflect.ValueOf(int8(syscall.a1))
416- case reflect.Int16:
417- v = reflect.ValueOf(int16(syscall.a1))
418- case reflect.Int32:
419- v = reflect.ValueOf(int32(syscall.a1))
420- case reflect.Int64:
421- v = reflect.ValueOf(int64(syscall.a1))
422 case reflect.Bool:401 case reflect.Bool:
423- v = reflect.ValueOf(byte(syscall.a1) != 0)402+ v.SetBool(byte(syscall.a1) != 0)
424 case reflect.UnsafePointer:403 case reflect.UnsafePointer:
425 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer404 // We take the address and then dereference it to trick go vet from creating a possible miss-use of unsafe.Pointer
426 v = reflect.New(outType).Elem()405 v = reflect.New(outType).Elem()

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