diff options
author | Ian Lance Taylor <iant@golang.org> | 2017-01-14 00:05:42 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-01-14 00:05:42 +0000 |
commit | c2047754c300b68c05d65faa8dc2925fe67b71b4 (patch) | |
tree | e183ae81a1f48a02945cb6de463a70c5be1b06f6 /libgo/go/strconv | |
parent | 829afb8f05602bb31c9c597b24df7377fed4f059 (diff) | |
download | gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.zip gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.gz gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.bz2 |
libgo: update to Go 1.8 release candidate 1
Compiler changes:
* Change map assignment to use mapassign and assign value directly.
* Change string iteration to use decoderune, faster for ASCII strings.
* Change makeslice to take int, and use makeslice64 for larger values.
* Add new noverflow field to hmap struct used for maps.
Unresolved problems, to be fixed later:
* Commented out test in go/types/sizes_test.go that doesn't compile.
* Commented out reflect.TestStructOf test for padding after zero-sized field.
Reviewed-on: https://go-review.googlesource.com/35231
gotools/:
Updates for Go 1.8rc1.
* Makefile.am (go_cmd_go_files): Add bug.go.
(s-zdefaultcc): Write defaultPkgConfig.
* Makefile.in: Rebuild.
From-SVN: r244456
Diffstat (limited to 'libgo/go/strconv')
-rw-r--r-- | libgo/go/strconv/atoi.go | 4 | ||||
-rw-r--r-- | libgo/go/strconv/decimal.go | 6 | ||||
-rw-r--r-- | libgo/go/strconv/ftoa_test.go | 3 | ||||
-rw-r--r-- | libgo/go/strconv/quote.go | 10 | ||||
-rw-r--r-- | libgo/go/strconv/quote_test.go | 3 | ||||
-rw-r--r-- | libgo/go/strconv/strconv_test.go | 38 |
6 files changed, 56 insertions, 8 deletions
diff --git a/libgo/go/strconv/atoi.go b/libgo/go/strconv/atoi.go index a236de4..66df149 100644 --- a/libgo/go/strconv/atoi.go +++ b/libgo/go/strconv/atoi.go @@ -199,6 +199,10 @@ func ParseInt(s string, base int, bitSize int) (i int64, err error) { // Atoi returns the result of ParseInt(s, 10, 0) converted to type int. func Atoi(s string) (int, error) { + const fnAtoi = "Atoi" i64, err := ParseInt(s, 10, 0) + if nerr, ok := err.(*NumError); ok { + nerr.Func = fnAtoi + } return int(i64), err } diff --git a/libgo/go/strconv/decimal.go b/libgo/go/strconv/decimal.go index 5252d6e..957acd9 100644 --- a/libgo/go/strconv/decimal.go +++ b/libgo/go/strconv/decimal.go @@ -131,11 +131,13 @@ func rightShift(a *decimal, k uint) { } a.dp -= r - 1 + var mask uint = (1 << k) - 1 + // Pick up a digit, put down a digit. for ; r < a.nd; r++ { c := uint(a.d[r]) dig := n >> k - n -= dig << k + n &= mask a.d[w] = byte(dig + '0') w++ n = n*10 + c - '0' @@ -144,7 +146,7 @@ func rightShift(a *decimal, k uint) { // Put down extra digits. for n > 0 { dig := n >> k - n -= dig << k + n &= mask if w < len(a.d) { a.d[w] = byte(dig + '0') w++ diff --git a/libgo/go/strconv/ftoa_test.go b/libgo/go/strconv/ftoa_test.go index 1d25242..976bd2c 100644 --- a/libgo/go/strconv/ftoa_test.go +++ b/libgo/go/strconv/ftoa_test.go @@ -208,6 +208,9 @@ var ftoaBenches = []struct { {"64Fixed2", 123.456, 'e', 3, 64}, {"64Fixed3", 1.23456e+78, 'e', 3, 64}, {"64Fixed4", 1.23456e-78, 'e', 3, 64}, + + // Trigger slow path (see issue #15672). + {"Slowpath64", 622666234635.3213e-320, 'e', -1, 64}, } func BenchmarkFormatFloat(b *testing.B) { diff --git a/libgo/go/strconv/quote.go b/libgo/go/strconv/quote.go index becfe1d..76c5c2a 100644 --- a/libgo/go/strconv/quote.go +++ b/libgo/go/strconv/quote.go @@ -362,6 +362,16 @@ func Unquote(s string) (string, error) { if contains(s, '`') { return "", ErrSyntax } + if contains(s, '\r') { + // -1 because we know there is at least one \r to remove. + buf := make([]byte, 0, len(s)-1) + for i := 0; i < len(s); i++ { + if s[i] != '\r' { + buf = append(buf, s[i]) + } + } + return string(buf), nil + } return s, nil } if quote != '"' && quote != '\'' { diff --git a/libgo/go/strconv/quote_test.go b/libgo/go/strconv/quote_test.go index 10735e3..a4b5804 100644 --- a/libgo/go/strconv/quote_test.go +++ b/libgo/go/strconv/quote_test.go @@ -274,6 +274,7 @@ var unquotetests = []unQuoteTest{ {"`\n`", "\n"}, {"` `", ` `}, {"` `", ` `}, + {"`a\rb`", "ab"}, } var misquoted = []string{ @@ -306,7 +307,7 @@ var misquoted = []string{ func TestUnquote(t *testing.T) { for _, tt := range unquotetests { - if out, err := Unquote(tt.in); err != nil && out != tt.out { + if out, err := Unquote(tt.in); err != nil || out != tt.out { t.Errorf("Unquote(%#q) = %q, %v want %q, nil", tt.in, out, err, tt.out) } } diff --git a/libgo/go/strconv/strconv_test.go b/libgo/go/strconv/strconv_test.go index 207e00e..ebec0cc 100644 --- a/libgo/go/strconv/strconv_test.go +++ b/libgo/go/strconv/strconv_test.go @@ -4,10 +4,6 @@ package strconv_test -/* - -gccgo does not pass this. - import ( "runtime" . "strconv" @@ -46,6 +42,9 @@ var ( ) func TestCountMallocs(t *testing.T) { + if runtime.Compiler == "gccgo" { + t.Skip("skipping on gccgo until escape analysis is turned on") + } if testing.Short() { t.Skip("skipping malloc count in short mode") } @@ -60,4 +59,33 @@ func TestCountMallocs(t *testing.T) { } } -*/ +func TestErrorPrefixes(t *testing.T) { + _, errInt := Atoi("INVALID") + _, errBool := ParseBool("INVALID") + _, errFloat := ParseFloat("INVALID", 64) + _, errInt64 := ParseInt("INVALID", 10, 64) + _, errUint64 := ParseUint("INVALID", 10, 64) + + vectors := []struct { + err error // Input error + want string // Function name wanted + }{ + {errInt, "Atoi"}, + {errBool, "ParseBool"}, + {errFloat, "ParseFloat"}, + {errInt64, "ParseInt"}, + {errUint64, "ParseUint"}, + } + + for _, v := range vectors { + nerr, ok := v.err.(*NumError) + if !ok { + t.Errorf("test %s, error was not a *NumError", v.want) + continue + } + if got := nerr.Func; got != v.want { + t.Errorf("mismatching Func: got %s, want %s", got, v.want) + } + } + +} |