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.
 
 
 

27 lines
690 B

  1. // Copyright 2018, 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 value
  6. import (
  7. "reflect"
  8. "unsafe"
  9. )
  10. // Pointer is an opaque typed pointer and is guaranteed to be comparable.
  11. type Pointer struct {
  12. p unsafe.Pointer
  13. t reflect.Type
  14. }
  15. // PointerOf returns a Pointer from v, which must be a
  16. // reflect.Ptr, reflect.Slice, or reflect.Map.
  17. func PointerOf(v reflect.Value) Pointer {
  18. // The proper representation of a pointer is unsafe.Pointer,
  19. // which is necessary if the GC ever uses a moving collector.
  20. return Pointer{unsafe.Pointer(v.Pointer()), v.Type()}
  21. }