Skip to content

Commit

Permalink
Add logic to deal with reflect pkg changes on tip.
Browse files Browse the repository at this point in the history
This commit adds logic to gracefully the internal reflect.Value flag bit
changes as of golang commit adf9b30e5594 while maintaining support all
the back to Go 1.0.

It accomplishes this by adding code to the init time inspection to
detect the change and set the flag positions accordingly.

While here, also removes a TODO comment since it was already done
previously.
  • Loading branch information
davecgh committed Nov 5, 2015
1 parent 2df1748 commit 5215b55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 15 additions & 0 deletions spew/bypass.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ func init() {
flagKindShift = 0
flagRO = 1 << 5
flagIndir = 1 << 6

// Commit adf9b30e5594 modified the flags to separate the
// flagRO flag into two bits which specifies whether or not the
// field is embedded. This causes flagIndir to move over a bit
// and means that flagRO is the combination of either of the
// original flagRO bit and the new bit.
//
// This code detects the change by extracting what used to be
// the indirect bit to ensure it's set. When it's not, the flag
// order has been changed to the newer format, so the flags are
// updated accordingly.
if upfv&flagIndir == 0 {
flagRO = 3 << 5
flagIndir = 1 << 7
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions spew/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ func (d *dumpState) dumpSlice(v reflect.Value) {
// Try to use existing uint8 slices and fall back to converting
// and copying if that fails.
case vt.Kind() == reflect.Uint8:
// TODO(davec): Fix up the disableUnsafe bits...

// We need an addressable interface to convert the type
// to a byte slice. However, the reflect package won't
// give us an interface on certain things like
Expand Down

0 comments on commit 5215b55

Please sign in to comment.