mirror of
https://github.com/golang/go
synced 2024-11-19 02:14:43 -07:00
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
This commit is contained in:
parent
5b70b71219
commit
48452a276d
@ -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}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user