diff options
| author | Dave Collins <[email protected]> | 2015-06-17 22:34:22 -0500 |
|---|---|---|
| committer | Dave Collins <[email protected]> | 2015-06-19 15:29:34 -0500 |
| commit | 2df174808ee097f90d259e432cc04442cf60be21 (patch) | |
| tree | 137a52652745f1dc47abb8ab3d379cb556e6e632 /spew/bypasssafe.go | |
| parent | f9f629a1d082960e5d1747f33c2b378612615fea (diff) | |
Add support for limited mode without unsafe pkg.
This commit adds support for compiling spew without the unsafe package.
When compiled without the unsafe package, some of the more advanced
features such as invoking stringers on pointers from non-pointer
variables and unexported struct fields are not available.
By default, spew will be compiled in the limited mode for Google App
Engine since the unsafe package is not available there. Additionally,
spew can be compiled without the unsafe package manually by specifying
the "disableunsafe" build tag.
Finally, a new package-level constant named "UnsafeDisabled" has been
exposed which can be used to programmatically determine if spew was
compiled with access to the unsafe package.
Diffstat (limited to 'spew/bypasssafe.go')
| -rw-r--r-- | spew/bypasssafe.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/spew/bypasssafe.go b/spew/bypasssafe.go new file mode 100644 index 0000000..457e412 --- /dev/null +++ b/spew/bypasssafe.go @@ -0,0 +1,37 @@ +// Copyright (c) 2015 Dave Collins <[email protected]> +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when either the code is running on Google App Engine or "-tags disableunsafe" +// is added to the go build command line. +// +build appengine disableunsafe + +package spew + +import "reflect" + +const ( + // UnsafeDisabled is a build-time constant which specifies whether or + // not access to the unsafe package is available. + UnsafeDisabled = true +) + +// unsafeReflectValue typically converts the passed reflect.Value into a one +// that bypasses the typical safety restrictions preventing access to +// unaddressable and unexported data. However, doing this relies on access to +// the unsafe package. This is a stub version which simply returns the passed +// reflect.Value when the unsafe package is not available. +func unsafeReflectValue(v reflect.Value) reflect.Value { + return v +} |
