unsafe_ptr.go raw

   1  package reflect2
   2  
   3  import (
   4  	"reflect"
   5  	"unsafe"
   6  )
   7  
   8  type UnsafePtrType struct {
   9  	unsafeType
  10  }
  11  
  12  func newUnsafePtrType(cfg *frozenConfig, type1 reflect.Type) *UnsafePtrType {
  13  	return &UnsafePtrType{
  14  		unsafeType: *newUnsafeType(cfg, type1),
  15  	}
  16  }
  17  
  18  func (type2 *UnsafePtrType) IsNil(obj interface{}) bool {
  19  	if obj == nil {
  20  		return true
  21  	}
  22  	objEFace := unpackEFace(obj)
  23  	assertType("Type.IsNil argument 1", type2.ptrRType, objEFace.rtype)
  24  	return type2.UnsafeIsNil(objEFace.data)
  25  }
  26  
  27  func (type2 *UnsafePtrType) UnsafeIsNil(ptr unsafe.Pointer) bool {
  28  	if ptr == nil {
  29  		return true
  30  	}
  31  	return *(*unsafe.Pointer)(ptr) == nil
  32  }
  33  
  34  func (type2 *UnsafePtrType) LikePtr() bool {
  35  	return true
  36  }
  37  
  38  func (type2 *UnsafePtrType) Indirect(obj interface{}) interface{} {
  39  	objEFace := unpackEFace(obj)
  40  	assertType("Type.Indirect argument 1", type2.ptrRType, objEFace.rtype)
  41  	return type2.UnsafeIndirect(objEFace.data)
  42  }
  43  
  44  func (type2 *UnsafePtrType) UnsafeIndirect(ptr unsafe.Pointer) interface{} {
  45  	return packEFace(type2.rtype, *(*unsafe.Pointer)(ptr))
  46  }
  47