You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

24 lines
682 B

  1. // Copyright 2017, The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE.md file.
  4. // +build !purego
  5. package cmp
  6. import (
  7. "reflect"
  8. "unsafe"
  9. )
  10. const supportAllowUnexported = true
  11. // retrieveUnexportedField uses unsafe to forcibly retrieve any field from
  12. // a struct such that the value has read-write permissions.
  13. //
  14. // The parent struct, v, must be addressable, while f must be a StructField
  15. // describing the field to retrieve.
  16. func retrieveUnexportedField(v reflect.Value, f reflect.StructField) reflect.Value {
  17. return reflect.NewAt(f.Type, unsafe.Pointer(v.UnsafeAddr()+f.Offset)).Elem()
  18. }