From: Russ Cox Date: Sun, 24 Aug 2014 03:01:59 +0000 (-0400) Subject: runtime: adjust errorCString definition to avoid allocation X-Git-Tag: go1.4beta1~741 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=48452a276d63639f54d3ce1a8d36663e26949526;p=gostls13.git runtime: adjust errorCString definition to avoid allocation The low-level implementation of divide on ARM assumes that it can panic with an error created by newErrorCString without allocating. If we make interface data words require pointer values, the current definition would require an allocation when stored in an interface. Changing the definition to use unsafe.Pointer instead of uintptr avoids the allocation. This change is okay because the field really is a pointer (to a C string in rodata). Update #8405. This should make CL 133830043 safe to try again. LGTM=bradfitz R=golang-codereviews, bradfitz CC=dave, golang-codereviews, r https://golang.org/cl/133820043 --- diff --git a/src/pkg/runtime/error.go b/src/pkg/runtime/error.go index 12fd09eaf9..f379fc443a 100644 --- a/src/pkg/runtime/error.go +++ b/src/pkg/runtime/error.go @@ -4,6 +4,8 @@ package runtime +import "unsafe" + // The Error interface identifies a run time error. type Error interface { error @@ -75,17 +77,19 @@ func newErrorString(s string, ret *interface{}) { } // An errorCString represents a runtime error described by a single C string. -// Not "type errorCString uintptr" because of http://golang.org/issue/7084. -type errorCString struct{ cstr uintptr } +// Not "type errorCString unsafe.Pointer" because of http://golang.org/issue/7084. +// Not uintptr because we want to avoid an allocation if interfaces can't hold +// uintptrs directly (and cstr _is_ a pointer). +type errorCString struct{ cstr unsafe.Pointer } func (e errorCString) RuntimeError() {} func (e errorCString) Error() string { - return "runtime error: " + cstringToGo(e.cstr) + return "runtime error: " + cstringToGo(uintptr(e.cstr)) } // For calling from C. -func newErrorCString(s uintptr, ret *interface{}) { +func newErrorCString(s unsafe.Pointer, ret *interface{}) { *ret = errorCString{s} }