...

Source file src/github.com/google/go-cmp/cmp/internal/value/pointer.go

Documentation: github.com/google/go-cmp/cmp/internal/value

     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  package value
     6  
     7  import (
     8  	"reflect"
     9  	"unsafe"
    10  )
    11  
    12  // Pointer is an opaque typed pointer and is guaranteed to be comparable.
    13  type Pointer struct {
    14  	p unsafe.Pointer
    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.
    20  func PointerOf(v reflect.Value) Pointer {
    21  	// The proper representation of a pointer is unsafe.Pointer,
    22  	// which is necessary if the GC ever uses a moving collector.
    23  	return Pointer{unsafe.Pointer(v.Pointer()), v.Type()}
    24  }
    25  
    26  // IsNil reports whether the pointer is nil.
    27  func (p Pointer) IsNil() bool {
    28  	return p.p == nil
    29  }
    30  
    31  // Uintptr returns the pointer as a uintptr.
    32  func (p Pointer) Uintptr() uintptr {
    33  	return uintptr(p.p)
    34  }
    35  

View as plain text