summaryrefslogtreecommitdiff
path: root/spew/internalunsafe_test.go
diff options
context:
space:
mode:
authorRoger Peppe <[email protected]>2018-01-29 09:57:49 +0000
committerDave Collins <[email protected]>2018-02-03 01:28:59 -0600
commit87df7c60d5820d0f8ae11afede5aa52325c09717 (patch)
treecb1baccb5f0358afe3a3b92dd476e917e233f44c /spew/internalunsafe_test.go
parentdb69d09d2c587e9b9677f991dfcab1fc24d9086e (diff)
simpler, more robust bypass
We make the bypass implementation a little simpler by inferring the flag field position from available reflect information and more robust by checking that the flags that are set actually match the semantics we expect. We can restrict the use of unsafe to a single function: flagField.
Diffstat (limited to 'spew/internalunsafe_test.go')
-rw-r--r--spew/internalunsafe_test.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/spew/internalunsafe_test.go b/spew/internalunsafe_test.go
index a0c612e..80dc221 100644
--- a/spew/internalunsafe_test.go
+++ b/spew/internalunsafe_test.go
@@ -16,7 +16,7 @@
// when the code is not running on Google App Engine, compiled by GopherJS, and
// "-tags safe" is not added to the go build command line. The "disableunsafe"
// tag is deprecated and thus should not be used.
-// +build !js,!appengine,!safe,!disableunsafe
+// +build !js,!appengine,!safe,!disableunsafe,go1.4
/*
This test file is part of the spew package rather than than the spew_test
@@ -30,7 +30,6 @@ import (
"bytes"
"reflect"
"testing"
- "unsafe"
)
// changeKind uses unsafe to intentionally change the kind of a reflect.Value to
@@ -38,13 +37,13 @@ import (
// fallback code which punts to the standard fmt library for new types that
// might get added to the language.
func changeKind(v *reflect.Value, readOnly bool) {
- rvf := (*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + offsetFlag))
- *rvf = *rvf | ((1<<flagKindWidth - 1) << flagKindShift)
+ flags := flagField(v)
if readOnly {
- *rvf |= flagRO
+ *flags |= flagRO
} else {
- *rvf &= ^uintptr(flagRO)
+ *flags &^= flagRO
}
+ *flags |= flagKindMask
}
// TestAddedReflectValue tests functionaly of the dump and formatter code which