From 7d316222e18768fec502f76523cd295a12f7f09a Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Mon, 25 Feb 2019 17:42:07 -0800 Subject: Rename unsafe_x.go as export_x.go (#117) Rename the file based on what it does rather than how its implemented. --- cmp/export_unsafe.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 cmp/export_unsafe.go (limited to 'cmp/export_unsafe.go') 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() +} -- cgit v1.2.3