pointer_purego.go 862 B

123456789101112131415161718192021222324252627282930313233
  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 file.
  4. // +build purego
  5. package value
  6. import "reflect"
  7. // Pointer is an opaque typed pointer and is guaranteed to be comparable.
  8. type Pointer struct {
  9. p uintptr
  10. t reflect.Type
  11. }
  12. // PointerOf returns a Pointer from v, which must be a
  13. // reflect.Ptr, reflect.Slice, or reflect.Map.
  14. func PointerOf(v reflect.Value) Pointer {
  15. // NOTE: Storing a pointer as an uintptr is technically incorrect as it
  16. // assumes that the GC implementation does not use a moving collector.
  17. return Pointer{v.Pointer(), v.Type()}
  18. }
  19. // IsNil reports whether the pointer is nil.
  20. func (p Pointer) IsNil() bool {
  21. return p.p == 0
  22. }
  23. // Uintptr returns the pointer as a uintptr.
  24. func (p Pointer) Uintptr() uintptr {
  25. return p.p
  26. }