pointer_purego.go 880 B

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