Commit 48452a27 authored by Russ Cox's avatar Russ Cox

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
parent 5b70b712
......@@ -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}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment