aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/davecgh/go-spew/spew
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/davecgh/go-spew/spew')
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/bypass.go187
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/bypasssafe.go2
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/common.go2
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/dump.go10
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/format.go4
5 files changed, 99 insertions, 106 deletions
diff --git a/vendor/github.com/davecgh/go-spew/spew/bypass.go b/vendor/github.com/davecgh/go-spew/spew/bypass.go
index 8a4a658..7929947 100644
--- a/vendor/github.com/davecgh/go-spew/spew/bypass.go
+++ b/vendor/github.com/davecgh/go-spew/spew/bypass.go
@@ -16,7 +16,9 @@
16// when the code is not running on Google App Engine, compiled by GopherJS, and 16// when the code is not running on Google App Engine, compiled by GopherJS, and
17// "-tags safe" is not added to the go build command line. The "disableunsafe" 17// "-tags safe" is not added to the go build command line. The "disableunsafe"
18// tag is deprecated and thus should not be used. 18// tag is deprecated and thus should not be used.
19// +build !js,!appengine,!safe,!disableunsafe 19// Go versions prior to 1.4 are disabled because they use a different layout
20// for interfaces which make the implementation of unsafeReflectValue more complex.
21// +build !js,!appengine,!safe,!disableunsafe,go1.4
20 22
21package spew 23package spew
22 24
@@ -34,80 +36,49 @@ const (
34 ptrSize = unsafe.Sizeof((*byte)(nil)) 36 ptrSize = unsafe.Sizeof((*byte)(nil))
35) 37)
36 38
39type flag uintptr
40
37var ( 41var (
38 // offsetPtr, offsetScalar, and offsetFlag are the offsets for the 42 // flagRO indicates whether the value field of a reflect.Value
39 // internal reflect.Value fields. These values are valid before golang 43 // is read-only.
40 // commit ecccf07e7f9d which changed the format. The are also valid 44 flagRO flag
41 // after commit 82f48826c6c7 which changed the format again to mirror 45
42 // the original format. Code in the init function updates these offsets 46 // flagAddr indicates whether the address of the reflect.Value's
43 // as necessary. 47 // value may be taken.
44 offsetPtr = uintptr(ptrSize) 48 flagAddr flag
45 offsetScalar = uintptr(0)
46 offsetFlag = uintptr(ptrSize * 2)
47
48 // flagKindWidth and flagKindShift indicate various bits that the
49 // reflect package uses internally to track kind information.
50 //
51 // flagRO indicates whether or not the value field of a reflect.Value is
52 // read-only.
53 //
54 // flagIndir indicates whether the value field of a reflect.Value is
55 // the actual data or a pointer to the data.
56 //
57 // These values are valid before golang commit 90a7c3c86944 which
58 // changed their positions. Code in the init function updates these
59 // flags as necessary.
60 flagKindWidth = uintptr(5)
61 flagKindShift = uintptr(flagKindWidth - 1)
62 flagRO = uintptr(1 << 0)
63 flagIndir = uintptr(1 << 1)
64) 49)
65 50
66func init() { 51// flagKindMask holds the bits that make up the kind
67 // Older versions of reflect.Value stored small integers directly in the 52// part of the flags field. In all the supported versions,
68 // ptr field (which is named val in the older versions). Versions 53// it is in the lower 5 bits.
69 // between commits ecccf07e7f9d and 82f48826c6c7 added a new field named 54const flagKindMask = flag(0x1f)
70 // scalar for this purpose which unfortunately came before the flag
71 // field, so the offset of the flag field is different for those
72 // versions.
73 //
74 // This code constructs a new reflect.Value from a known small integer
75 // and checks if the size of the reflect.Value struct indicates it has
76 // the scalar field. When it does, the offsets are updated accordingly.
77 vv := reflect.ValueOf(0xf00)
78 if unsafe.Sizeof(vv) == (ptrSize * 4) {
79 offsetScalar = ptrSize * 2
80 offsetFlag = ptrSize * 3
81 }
82 55
83 // Commit 90a7c3c86944 changed the flag positions such that the low 56// Different versions of Go have used different
84 // order bits are the kind. This code extracts the kind from the flags 57// bit layouts for the flags type. This table
85 // field and ensures it's the correct type. When it's not, the flag 58// records the known combinations.
86 // order has been changed to the newer format, so the flags are updated 59var okFlags = []struct {
87 // accordingly. 60 ro, addr flag
88 upf := unsafe.Pointer(uintptr(unsafe.Pointer(&vv)) + offsetFlag) 61}{{
89 upfv := *(*uintptr)(upf) 62 // From Go 1.4 to 1.5
90 flagKindMask := uintptr((1<<flagKindWidth - 1) << flagKindShift) 63 ro: 1 << 5,
91 if (upfv&flagKindMask)>>flagKindShift != uintptr(reflect.Int) { 64 addr: 1 << 7,
92 flagKindShift = 0 65}, {
93 flagRO = 1 << 5 66 // Up to Go tip.
94 flagIndir = 1 << 6 67 ro: 1<<5 | 1<<6,
95 68 addr: 1 << 8,
96 // Commit adf9b30e5594 modified the flags to separate the 69}}
97 // flagRO flag into two bits which specifies whether or not the 70
98 // field is embedded. This causes flagIndir to move over a bit 71var flagValOffset = func() uintptr {
99 // and means that flagRO is the combination of either of the 72 field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag")
100 // original flagRO bit and the new bit. 73 if !ok {
101 // 74 panic("reflect.Value has no flag field")
102 // This code detects the change by extracting what used to be
103 // the indirect bit to ensure it's set. When it's not, the flag
104 // order has been changed to the newer format, so the flags are
105 // updated accordingly.
106 if upfv&flagIndir == 0 {
107 flagRO = 3 << 5
108 flagIndir = 1 << 7
109 }
110 } 75 }
76 return field.Offset
77}()
78
79// flagField returns a pointer to the flag field of a reflect.Value.
80func flagField(v *reflect.Value) *flag {
81 return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset))
111} 82}
112 83
113// unsafeReflectValue converts the passed reflect.Value into a one that bypasses 84// unsafeReflectValue converts the passed reflect.Value into a one that bypasses
@@ -119,34 +90,56 @@ func init() {
119// This allows us to check for implementations of the Stringer and error 90// This allows us to check for implementations of the Stringer and error
120// interfaces to be used for pretty printing ordinarily unaddressable and 91// interfaces to be used for pretty printing ordinarily unaddressable and
121// inaccessible values such as unexported struct fields. 92// inaccessible values such as unexported struct fields.
122func unsafeReflectValue(v reflect.Value) (rv reflect.Value) { 93func unsafeReflectValue(v reflect.Value) reflect.Value {
123 indirects := 1 94 if !v.IsValid() || (v.CanInterface() && v.CanAddr()) {
124 vt := v.Type() 95 return v
125 upv := unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetPtr)
126 rvf := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetFlag))
127 if rvf&flagIndir != 0 {
128 vt = reflect.PtrTo(v.Type())
129 indirects++
130 } else if offsetScalar != 0 {
131 // The value is in the scalar field when it's not one of the
132 // reference types.
133 switch vt.Kind() {
134 case reflect.Uintptr:
135 case reflect.Chan:
136 case reflect.Func:
137 case reflect.Map:
138 case reflect.Ptr:
139 case reflect.UnsafePointer:
140 default:
141 upv = unsafe.Pointer(uintptr(unsafe.Pointer(&v)) +
142 offsetScalar)
143 }
144 } 96 }
97 flagFieldPtr := flagField(&v)
98 *flagFieldPtr &^= flagRO
99 *flagFieldPtr |= flagAddr
100 return v
101}
145 102
146 pv := reflect.NewAt(vt, upv) 103// Sanity checks against future reflect package changes
147 rv = pv 104// to the type or semantics of the Value.flag field.
148 for i := 0; i < indirects; i++ { 105func init() {
149 rv = rv.Elem() 106 field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag")
107 if !ok {
108 panic("reflect.Value has no flag field")
109 }
110 if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() {
111 panic("reflect.Value flag field has changed kind")
112 }
113 type t0 int
114 var t struct {
115 A t0
116 // t0 will have flagEmbedRO set.
117 t0
118 // a will have flagStickyRO set
119 a t0
120 }
121 vA := reflect.ValueOf(t).FieldByName("A")
122 va := reflect.ValueOf(t).FieldByName("a")
123 vt0 := reflect.ValueOf(t).FieldByName("t0")
124
125 // Infer flagRO from the difference between the flags
126 // for the (otherwise identical) fields in t.
127 flagPublic := *flagField(&vA)
128 flagWithRO := *flagField(&va) | *flagField(&vt0)
129 flagRO = flagPublic ^ flagWithRO
130
131 // Infer flagAddr from the difference between a value
132 // taken from a pointer and not.
133 vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A")
134 flagNoPtr := *flagField(&vA)
135 flagPtr := *flagField(&vPtrA)
136 flagAddr = flagNoPtr ^ flagPtr
137
138 // Check that the inferred flags tally with one of the known versions.
139 for _, f := range okFlags {
140 if flagRO == f.ro && flagAddr == f.addr {
141 return
142 }
150 } 143 }
151 return rv 144 panic("reflect.Value read-only flag has changed semantics")
152} 145}
diff --git a/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go b/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go
index 1fe3cf3..205c28d 100644
--- a/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go
+++ b/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go
@@ -16,7 +16,7 @@
16// when the code is running on Google App Engine, compiled by GopherJS, or 16// when the code is running on Google App Engine, compiled by GopherJS, or
17// "-tags safe" is added to the go build command line. The "disableunsafe" 17// "-tags safe" is added to the go build command line. The "disableunsafe"
18// tag is deprecated and thus should not be used. 18// tag is deprecated and thus should not be used.
19// +build js appengine safe disableunsafe 19// +build js appengine safe disableunsafe !go1.4
20 20
21package spew 21package spew
22 22
diff --git a/vendor/github.com/davecgh/go-spew/spew/common.go b/vendor/github.com/davecgh/go-spew/spew/common.go
index 7c519ff..1be8ce9 100644
--- a/vendor/github.com/davecgh/go-spew/spew/common.go
+++ b/vendor/github.com/davecgh/go-spew/spew/common.go
@@ -180,7 +180,7 @@ func printComplex(w io.Writer, c complex128, floatPrecision int) {
180 w.Write(closeParenBytes) 180 w.Write(closeParenBytes)
181} 181}
182 182
183// printHexPtr outputs a uintptr formatted as hexidecimal with a leading '0x' 183// printHexPtr outputs a uintptr formatted as hexadecimal with a leading '0x'
184// prefix to Writer w. 184// prefix to Writer w.
185func printHexPtr(w io.Writer, p uintptr) { 185func printHexPtr(w io.Writer, p uintptr) {
186 // Null pointer. 186 // Null pointer.
diff --git a/vendor/github.com/davecgh/go-spew/spew/dump.go b/vendor/github.com/davecgh/go-spew/spew/dump.go
index df1d582..f78d89f 100644
--- a/vendor/github.com/davecgh/go-spew/spew/dump.go
+++ b/vendor/github.com/davecgh/go-spew/spew/dump.go
@@ -35,16 +35,16 @@ var (
35 35
36 // cCharRE is a regular expression that matches a cgo char. 36 // cCharRE is a regular expression that matches a cgo char.
37 // It is used to detect character arrays to hexdump them. 37 // It is used to detect character arrays to hexdump them.
38 cCharRE = regexp.MustCompile("^.*\\._Ctype_char$") 38 cCharRE = regexp.MustCompile(`^.*\._Ctype_char$`)
39 39
40 // cUnsignedCharRE is a regular expression that matches a cgo unsigned 40 // cUnsignedCharRE is a regular expression that matches a cgo unsigned
41 // char. It is used to detect unsigned character arrays to hexdump 41 // char. It is used to detect unsigned character arrays to hexdump
42 // them. 42 // them.
43 cUnsignedCharRE = regexp.MustCompile("^.*\\._Ctype_unsignedchar$") 43 cUnsignedCharRE = regexp.MustCompile(`^.*\._Ctype_unsignedchar$`)
44 44
45 // cUint8tCharRE is a regular expression that matches a cgo uint8_t. 45 // cUint8tCharRE is a regular expression that matches a cgo uint8_t.
46 // It is used to detect uint8_t arrays to hexdump them. 46 // It is used to detect uint8_t arrays to hexdump them.
47 cUint8tCharRE = regexp.MustCompile("^.*\\._Ctype_uint8_t$") 47 cUint8tCharRE = regexp.MustCompile(`^.*\._Ctype_uint8_t$`)
48) 48)
49 49
50// dumpState contains information about the state of a dump operation. 50// dumpState contains information about the state of a dump operation.
@@ -143,10 +143,10 @@ func (d *dumpState) dumpPtr(v reflect.Value) {
143 // Display dereferenced value. 143 // Display dereferenced value.
144 d.w.Write(openParenBytes) 144 d.w.Write(openParenBytes)
145 switch { 145 switch {
146 case nilFound == true: 146 case nilFound:
147 d.w.Write(nilAngleBytes) 147 d.w.Write(nilAngleBytes)
148 148
149 case cycleFound == true: 149 case cycleFound:
150 d.w.Write(circularBytes) 150 d.w.Write(circularBytes)
151 151
152 default: 152 default:
diff --git a/vendor/github.com/davecgh/go-spew/spew/format.go b/vendor/github.com/davecgh/go-spew/spew/format.go
index c49875b..b04edb7 100644
--- a/vendor/github.com/davecgh/go-spew/spew/format.go
+++ b/vendor/github.com/davecgh/go-spew/spew/format.go
@@ -182,10 +182,10 @@ func (f *formatState) formatPtr(v reflect.Value) {
182 182
183 // Display dereferenced value. 183 // Display dereferenced value.
184 switch { 184 switch {
185 case nilFound == true: 185 case nilFound:
186 f.fs.Write(nilAngleBytes) 186 f.fs.Write(nilAngleBytes)
187 187
188 case cycleFound == true: 188 case cycleFound:
189 f.fs.Write(circularShortBytes) 189 f.fs.Write(circularShortBytes)
190 190
191 default: 191 default: