83 return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]} |
83 return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]} |
84 } |
84 } |
85 |
85 |
86 // toAddrPointer converts an interface to a pointer that points to |
86 // toAddrPointer converts an interface to a pointer that points to |
87 // the interface data. |
87 // the interface data. |
88 func toAddrPointer(i *interface{}, isptr bool) pointer { |
88 func toAddrPointer(i *interface{}, isptr, deref bool) (p pointer) { |
89 // Super-tricky - read or get the address of data word of interface value. |
89 // Super-tricky - read or get the address of data word of interface value. |
90 if isptr { |
90 if isptr { |
91 // The interface is of pointer type, thus it is a direct interface. |
91 // The interface is of pointer type, thus it is a direct interface. |
92 // The data word is the pointer data itself. We take its address. |
92 // The data word is the pointer data itself. We take its address. |
93 return pointer{p: unsafe.Pointer(uintptr(unsafe.Pointer(i)) + ptrSize)} |
93 p = pointer{p: unsafe.Pointer(uintptr(unsafe.Pointer(i)) + ptrSize)} |
|
94 } else { |
|
95 // The interface is not of pointer type. The data word is the pointer |
|
96 // to the data. |
|
97 p = pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]} |
94 } |
98 } |
95 // The interface is not of pointer type. The data word is the pointer |
99 if deref { |
96 // to the data. |
100 p.p = *(*unsafe.Pointer)(p.p) |
97 return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]} |
101 } |
|
102 return p |
98 } |
103 } |
99 |
104 |
100 // valToPointer converts v to a pointer. v must be of pointer type. |
105 // valToPointer converts v to a pointer. v must be of pointer type. |
101 func valToPointer(v reflect.Value) pointer { |
106 func valToPointer(v reflect.Value) pointer { |
102 return pointer{p: unsafe.Pointer(v.Pointer())} |
107 return pointer{p: unsafe.Pointer(v.Pointer())} |