aboutsummaryrefslogtreecommitdiff
path: root/cmp/export_unsafe.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2019-02-25 17:42:07 -0800
committerGitHub <noreply@github.com>2019-02-25 17:42:07 -0800
commit7d316222e18768fec502f76523cd295a12f7f09a (patch)
treee7568ffbb518d8425005577c717c7339bcda14d2 /cmp/export_unsafe.go
parenta02fa9f0a2b3432ef9a311f083acef9aa9bb123b (diff)
downloadgo-cmp-7d316222e18768fec502f76523cd295a12f7f09a.tar.gz
Rename unsafe_x.go as export_x.go (#117)
Rename the file based on what it does rather than how its implemented.
Diffstat (limited to 'cmp/export_unsafe.go')
-rw-r--r--cmp/export_unsafe.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/cmp/export_unsafe.go b/cmp/export_unsafe.go
new file mode 100644
index 0000000..59d4ee9
--- /dev/null
+++ b/cmp/export_unsafe.go
@@ -0,0 +1,23 @@
+// Copyright 2017, The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE.md file.
+
+// +build !purego
+
+package cmp
+
+import (
+ "reflect"
+ "unsafe"
+)
+
+const supportAllowUnexported = true
+
+// retrieveUnexportedField uses unsafe to forcibly retrieve any field from
+// a struct such that the value has read-write permissions.
+//
+// The parent struct, v, must be addressable, while f must be a StructField
+// describing the field to retrieve.
+func retrieveUnexportedField(v reflect.Value, f reflect.StructField) reflect.Value {
+ return reflect.NewAt(f.Type, unsafe.Pointer(v.UnsafeAddr()+f.Offset)).Elem()
+}