detached 57935ff

Revert "purego: fix float returns (#177)"

This reverts commit 2a2fe0f2bfbd84fa932e6af44c559f74eec9b600.

Reason: test failures on Ubuntu:

```
=== RUN   TestRegisterFunc_Floats
    func_test.go:119: strtof failed. got 0.000000 but wanted 2.000000
    func_test.go:131: strtod failed. got 0.000000 but wanted 1.000000
--- FAIL: TestRegisterFunc_Floats (0.00s)
```
commit
57935ffe1d434ff8dad800dc8572773002b49d7a
author
Hajime Hoshi · · 2023-11-18 17:50 UTC
parent
2a2fe0f
signature
unsigned
2 files · +5 -44
M func.go +1 -5
@@ -276,11 +276,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
276276 RegisterFunc(v.Interface(), r1)
277277 case reflect.String:
278278 v.SetString(strings.GoString(r1))
279- case reflect.Float32:
280- // NOTE: r2 is only the floating return value on 64bit platforms.
281- // On 32bit platforms r2 is the upper part of a 64bit return.
282- v.SetFloat(float64(math.Float32frombits(uint32(r2))))
283- case reflect.Float64:
279+ case reflect.Float32, reflect.Float64:
284280 // NOTE: r2 is only the floating return value on 64bit platforms.
285281 // On 32bit platforms r2 is the upper part of a 64bit return.
286282 v.SetFloat(math.Float64frombits(uint64(r2)))
@@ -276,11 +276,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
276 RegisterFunc(v.Interface(), r1)276 RegisterFunc(v.Interface(), r1)
277 case reflect.String:277 case reflect.String:
278 v.SetString(strings.GoString(r1))278 v.SetString(strings.GoString(r1))
279- case reflect.Float32:279+ case reflect.Float32, reflect.Float64:
280- // NOTE: r2 is only the floating return value on 64bit platforms.
281- // On 32bit platforms r2 is the upper part of a 64bit return.
282- v.SetFloat(float64(math.Float32frombits(uint32(r2))))
283- case reflect.Float64:
284 // NOTE: r2 is only the floating return value on 64bit platforms.280 // NOTE: r2 is only the floating return value on 64bit platforms.
285 // On 32bit platforms r2 is the upper part of a 64bit return.281 // On 32bit platforms r2 is the upper part of a 64bit return.
286 v.SetFloat(math.Float64frombits(uint64(r2)))282 v.SetFloat(math.Float64frombits(uint64(r2)))
M func_test.go +4 -39
@@ -35,11 +35,11 @@ func getSystemLibrary() (string, error) {
3535 func TestRegisterFunc(t *testing.T) {
3636 library, err := getSystemLibrary()
3737 if err != nil {
38- t.Fatalf("couldn't get system library: %s", err)
38+ t.Errorf("couldn't get system library: %s", err)
3939 }
4040 libc, err := openLibrary(library)
4141 if err != nil {
42- t.Fatalf("failed to dlopen: %s", err)
42+ t.Errorf("failed to dlopen: %s", err)
4343 }
4444 var puts func(string)
4545 purego.RegisterLibFunc(&puts, libc, "puts")
@@ -76,11 +76,11 @@ func Test_qsort(t *testing.T) {
7676
7777 library, err := getSystemLibrary()
7878 if err != nil {
79- t.Fatalf("couldn't get system library: %s", err)
79+ t.Errorf("couldn't get system library: %s", err)
8080 }
8181 libc, err := openLibrary(library)
8282 if err != nil {
83- t.Fatalf("failed to dlopen: %s", err)
83+ t.Errorf("failed to dlopen: %s", err)
8484 }
8585
8686 data := []int{88, 56, 100, 2, 25}
@@ -97,38 +97,3 @@ func Test_qsort(t *testing.T) {
9797 }
9898 }
9999 }
100-
101-func TestRegisterFunc_Floats(t *testing.T) {
102- library, err := getSystemLibrary()
103- if err != nil {
104- t.Fatalf("couldn't get system library: %s", err)
105- }
106- libc, err := openLibrary(library)
107- if err != nil {
108- t.Fatalf("failed to dlopen: %s", err)
109- }
110- {
111- var strtof func(arg string) float32
112- purego.RegisterLibFunc(&strtof, libc, "strtof")
113- const (
114- arg = "2"
115- )
116- got := strtof(arg)
117- expected := float32(2)
118- if got != expected {
119- t.Errorf("strtof failed. got %f but wanted %f", got, expected)
120- }
121- }
122- {
123- var strtod func(arg string, ptr **byte) float64
124- purego.RegisterLibFunc(&strtod, libc, "strtod")
125- const (
126- arg = "1"
127- )
128- got := strtod(arg, nil)
129- expected := float64(1)
130- if got != expected {
131- t.Errorf("strtod failed. got %f but wanted %f", got, expected)
132- }
133- }
134-}
@@ -35,11 +35,11 @@ func getSystemLibrary() (string, error) {
35 func TestRegisterFunc(t *testing.T) {35 func TestRegisterFunc(t *testing.T) {
36 library, err := getSystemLibrary()36 library, err := getSystemLibrary()
37 if err != nil {37 if err != nil {
38- t.Fatalf("couldn't get system library: %s", err)38+ t.Errorf("couldn't get system library: %s", err)
39 }39 }
40 libc, err := openLibrary(library)40 libc, err := openLibrary(library)
41 if err != nil {41 if err != nil {
42- t.Fatalf("failed to dlopen: %s", err)42+ t.Errorf("failed to dlopen: %s", err)
43 }43 }
44 var puts func(string)44 var puts func(string)
45 purego.RegisterLibFunc(&puts, libc, "puts")45 purego.RegisterLibFunc(&puts, libc, "puts")
@@ -76,11 +76,11 @@ func Test_qsort(t *testing.T) {
76 76
77 library, err := getSystemLibrary()77 library, err := getSystemLibrary()
78 if err != nil {78 if err != nil {
79- t.Fatalf("couldn't get system library: %s", err)79+ t.Errorf("couldn't get system library: %s", err)
80 }80 }
81 libc, err := openLibrary(library)81 libc, err := openLibrary(library)
82 if err != nil {82 if err != nil {
83- t.Fatalf("failed to dlopen: %s", err)83+ t.Errorf("failed to dlopen: %s", err)
84 }84 }
85 85
86 data := []int{88, 56, 100, 2, 25}86 data := []int{88, 56, 100, 2, 25}
@@ -97,38 +97,3 @@ func Test_qsort(t *testing.T) {
97 }97 }
98 }98 }
99 }99 }
100-
101-func TestRegisterFunc_Floats(t *testing.T) {
102- library, err := getSystemLibrary()
103- if err != nil {
104- t.Fatalf("couldn't get system library: %s", err)
105- }
106- libc, err := openLibrary(library)
107- if err != nil {
108- t.Fatalf("failed to dlopen: %s", err)
109- }
110- {
111- var strtof func(arg string) float32
112- purego.RegisterLibFunc(&strtof, libc, "strtof")
113- const (
114- arg = "2"
115- )
116- got := strtof(arg)
117- expected := float32(2)
118- if got != expected {
119- t.Errorf("strtof failed. got %f but wanted %f", got, expected)
120- }
121- }
122- {
123- var strtod func(arg string, ptr **byte) float64
124- purego.RegisterLibFunc(&strtod, libc, "strtod")
125- const (
126- arg = "1"
127- )
128- got := strtod(arg, nil)
129- expected := float64(1)
130- if got != expected {
131- t.Errorf("strtod failed. got %f but wanted %f", got, expected)
132- }
133- }
134-}

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