Skip to content

Commit 571a56b

Browse files
authored
Remove purego fallbacks (#325)
Having go-cmp panic when using the purego build tag makes it hard to use go-cmp for testing packages that themselves have purego fallbacks. Since go-cmp can't implement its functionality without unsafe (the "fallback" panics) and since environments that prohibit unsafe are much less common these days anyway, simply remove purego code entirely. Fixes #283.
1 parent a97318b commit 571a56b

File tree

6 files changed

+1
-62
lines changed

6 files changed

+1
-62
lines changed

cmp/export_unsafe.go renamed to cmp/export.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !purego
6-
// +build !purego
7-
85
package cmp
96

107
import (
118
"reflect"
129
"unsafe"
1310
)
1411

15-
const supportExporters = true
16-
1712
// retrieveUnexportedField uses unsafe to forcibly retrieve any field from
1813
// a struct such that the value has read-write permissions.
1914
//

cmp/export_panic.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

cmp/internal/value/pointer_unsafe.go renamed to cmp/internal/value/pointer.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !purego
6-
// +build !purego
7-
85
package value
96

107
import (

cmp/internal/value/pointer_purego.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

cmp/options.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,6 @@ func (cm comparer) String() string {
403403
// In other cases, the cmpopts.IgnoreUnexported option can be used to ignore
404404
// all unexported fields on specified struct types.
405405
func Exporter(f func(reflect.Type) bool) Option {
406-
if !supportExporters {
407-
panic("Exporter is not supported on purego builds")
408-
}
409406
return exporter(f)
410407
}
411408

cmp/report_reflect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (opts formatOptions) FormatValue(v reflect.Value, parentKind reflect.Kind,
199199
break
200200
}
201201
sf := t.Field(i)
202-
if supportExporters && !isExported(sf.Name) {
202+
if !isExported(sf.Name) {
203203
vv = retrieveUnexportedField(v, sf, true)
204204
}
205205
s := opts.WithTypeMode(autoType).FormatValue(vv, t.Kind(), ptrs)

0 commit comments

Comments
 (0)