aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/modern-go/reflect2/unsafe_ptr.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/modern-go/reflect2/unsafe_ptr.go')
-rw-r--r--vendor/github.com/modern-go/reflect2/unsafe_ptr.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/modern-go/reflect2/unsafe_ptr.go b/vendor/github.com/modern-go/reflect2/unsafe_ptr.go
new file mode 100644
index 0000000..8e5ec9c
--- /dev/null
+++ b/vendor/github.com/modern-go/reflect2/unsafe_ptr.go
@@ -0,0 +1,46 @@
1package 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}