blob: 8e5ec9cf45ed86b762db6244e2cb31b5b7dcead4 [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001package reflect2
2
3import (
4 "reflect"
5 "unsafe"
6)
7
8type UnsafePtrType struct {
9 unsafeType
10}
11
12func newUnsafePtrType(cfg *frozenConfig, type1 reflect.Type) *UnsafePtrType {
13 return &UnsafePtrType{
14 unsafeType: *newUnsafeType(cfg, type1),
15 }
16}
17
18func (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
27func (type2 *UnsafePtrType) UnsafeIsNil(ptr unsafe.Pointer) bool {
28 if ptr == nil {
29 return true
30 }
31 return *(*unsafe.Pointer)(ptr) == nil
32}
33
34func (type2 *UnsafePtrType) LikePtr() bool {
35 return true
36}
37
38func (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
44func (type2 *UnsafePtrType) UnsafeIndirect(ptr unsafe.Pointer) interface{} {
45 return packEFace(type2.rtype, *(*unsafe.Pointer)(ptr))
46}