summaryrefslogtreecommitdiff
path: root/vendor/github.com/google/go-cmp/cmp/export_unsafe.go
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2022-07-28 23:27:42 +0200
committerMiloslav Trmač <mitr@redhat.com>2022-07-30 17:26:08 +0200
commit63d77da5b9b0578fcbfef927a7bd1579c6ed1198 (patch)
tree1e5bbdfff9f7f9fba1c135a73379479d9cb24232 /vendor/github.com/google/go-cmp/cmp/export_unsafe.go
parentb01478044b47ac07697a8db1b5eb7f7922b058cc (diff)
downloadpodman-63d77da5b9b0578fcbfef927a7bd1579c6ed1198.tar.gz
podman-63d77da5b9b0578fcbfef927a7bd1579c6ed1198.tar.bz2
podman-63d77da5b9b0578fcbfef927a7bd1579c6ed1198.zip
Update c/common to an unreleased version
... to get https://github.com/containers/common/pull/1106 . Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'vendor/github.com/google/go-cmp/cmp/export_unsafe.go')
-rw-r--r--vendor/github.com/google/go-cmp/cmp/export_unsafe.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/vendor/github.com/google/go-cmp/cmp/export_unsafe.go b/vendor/github.com/google/go-cmp/cmp/export_unsafe.go
new file mode 100644
index 000000000..e2c0f74e8
--- /dev/null
+++ b/vendor/github.com/google/go-cmp/cmp/export_unsafe.go
@@ -0,0 +1,36 @@
+// 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 file.
+
+//go:build !purego
+// +build !purego
+
+package cmp
+
+import (
+ "reflect"
+ "unsafe"
+)
+
+const supportExporters = 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. If addr is false,
+// then the returned value will be shallowed copied to be non-addressable.
+func retrieveUnexportedField(v reflect.Value, f reflect.StructField, addr bool) reflect.Value {
+ ve := reflect.NewAt(f.Type, unsafe.Pointer(uintptr(unsafe.Pointer(v.UnsafeAddr()))+f.Offset)).Elem()
+ if !addr {
+ // A field is addressable if and only if the struct is addressable.
+ // If the original parent value was not addressable, shallow copy the
+ // value to make it non-addressable to avoid leaking an implementation
+ // detail of how forcibly exporting a field works.
+ if ve.Kind() == reflect.Interface && ve.IsNil() {
+ return reflect.Zero(f.Type)
+ }
+ return reflect.ValueOf(ve.Interface()).Convert(f.Type)
+ }
+ return ve
+}