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