aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/modern-go/reflect2/unsafe_eface.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/modern-go/reflect2/unsafe_eface.go')
-rw-r--r--vendor/github.com/modern-go/reflect2/unsafe_eface.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/github.com/modern-go/reflect2/unsafe_eface.go b/vendor/github.com/modern-go/reflect2/unsafe_eface.go
new file mode 100644
index 0000000..805010f
--- /dev/null
+++ b/vendor/github.com/modern-go/reflect2/unsafe_eface.go
@@ -0,0 +1,59 @@
1package reflect2
2
3import (
4 "reflect"
5 "unsafe"
6)
7
8type eface struct {
9 rtype unsafe.Pointer
10 data unsafe.Pointer
11}
12
13func unpackEFace(obj interface{}) *eface {
14 return (*eface)(unsafe.Pointer(&obj))
15}
16
17func packEFace(rtype unsafe.Pointer, data unsafe.Pointer) interface{} {
18 var i interface{}
19 e := (*eface)(unsafe.Pointer(&i))
20 e.rtype = rtype
21 e.data = data
22 return i
23}
24
25type UnsafeEFaceType struct {
26 unsafeType
27}
28
29func newUnsafeEFaceType(cfg *frozenConfig, type1 reflect.Type) *UnsafeEFaceType {
30 return &UnsafeEFaceType{
31 unsafeType: *newUnsafeType(cfg, type1),
32 }
33}
34
35func (type2 *UnsafeEFaceType) IsNil(obj interface{}) bool {
36 if obj == nil {
37 return true
38 }
39 objEFace := unpackEFace(obj)
40 assertType("Type.IsNil argument 1", type2.ptrRType, objEFace.rtype)
41 return type2.UnsafeIsNil(objEFace.data)
42}
43
44func (type2 *UnsafeEFaceType) UnsafeIsNil(ptr unsafe.Pointer) bool {
45 if ptr == nil {
46 return true
47 }
48 return unpackEFace(*(*interface{})(ptr)).data == nil
49}
50
51func (type2 *UnsafeEFaceType) Indirect(obj interface{}) interface{} {
52 objEFace := unpackEFace(obj)
53 assertType("Type.Indirect argument 1", type2.ptrRType, objEFace.rtype)
54 return type2.UnsafeIndirect(objEFace.data)
55}
56
57func (type2 *UnsafeEFaceType) UnsafeIndirect(ptr unsafe.Pointer) interface{} {
58 return *(*interface{})(ptr)
59}