simplify pc

This commit is contained in:
Dave Cheney 2016-04-22 19:32:12 +09:00
parent 258d1265c4
commit 109ee590a8

View File

@ -28,12 +28,13 @@ func (l loc) Location() (string, int) {
// New returns an error that formats as the given text.
func New(text string) error {
pc, _, _, _ := runtime.Caller(1)
return struct {
error
loc
}{
fmt.Errorf(text),
loc(pc()),
loc(pc),
}
}
@ -57,10 +58,11 @@ func Wrap(cause error, message string) error {
if cause == nil {
return nil
}
pc, _, _, _ := runtime.Caller(1)
return &e{
cause: cause,
message: message,
loc: loc(pc()),
loc: loc(pc),
}
}
@ -132,8 +134,3 @@ func Fprint(w io.Writer, err error) {
err = cause.Cause()
}
}
func pc() uintptr {
pc, _, _, _ := runtime.Caller(2)
return pc
}