summaryrefslogtreecommitdiff
path: root/libgo/go/bufio
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-01-09 01:23:08 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-01-09 01:23:08 +0000
commit1a2f01efa63036a5104f203a4789e682c0e0915d (patch)
tree373e15778dc8295354584e1f86915ae493b604ff /libgo/go/bufio
parent8799df67f2dab88f9fda11739c501780a85575e2 (diff)
downloadgcc-1a2f01efa63036a5104f203a4789e682c0e0915d.tar.gz
libgo: update to Go1.10beta1
Update the Go library to the 1.10beta1 release. Requires a few changes to the compiler for modifications to the map runtime code, and to handle some nowritebarrier cases in the runtime. Reviewed-on: https://go-review.googlesource.com/86455 gotools/: * Makefile.am (go_cmd_vet_files): New variable. (go_cmd_buildid_files, go_cmd_test2json_files): New variables. (s-zdefaultcc): Change from constants to functions. (noinst_PROGRAMS): Add vet, buildid, and test2json. (cgo$(EXEEXT)): Link against $(LIBGOTOOL). (vet$(EXEEXT)): New target. (buildid$(EXEEXT)): New target. (test2json$(EXEEXT)): New target. (install-exec-local): Install all $(noinst_PROGRAMS). (uninstall-local): Uninstasll all $(noinst_PROGRAMS). (check-go-tool): Depend on $(noinst_PROGRAMS). Copy down objabi.go. (check-runtime): Depend on $(noinst_PROGRAMS). (check-cgo-test, check-carchive-test): Likewise. (check-vet): New target. (check): Depend on check-vet. Look at cmd_vet-testlog. (.PHONY): Add check-vet. * Makefile.in: Rebuild. From-SVN: r256365
Diffstat (limited to 'libgo/go/bufio')
-rw-r--r--libgo/go/bufio/bufio.go6
-rw-r--r--libgo/go/bufio/bufio_test.go18
-rw-r--r--libgo/go/bufio/export_test.go2
-rw-r--r--libgo/go/bufio/scan.go9
4 files changed, 31 insertions, 4 deletions
diff --git a/libgo/go/bufio/bufio.go b/libgo/go/bufio/bufio.go
index da94a2503f0..ad9c9f5ddf7 100644
--- a/libgo/go/bufio/bufio.go
+++ b/libgo/go/bufio/bufio.go
@@ -62,6 +62,9 @@ func NewReader(rd io.Reader) *Reader {
return NewReaderSize(rd, defaultBufSize)
}
+// Size returns the size of the underlying buffer in bytes.
+func (r *Reader) Size() int { return len(r.buf) }
+
// Reset discards any buffered data, resets all state, and switches
// the buffered reader to read from r.
func (b *Reader) Reset(r io.Reader) {
@@ -548,6 +551,9 @@ func NewWriter(w io.Writer) *Writer {
return NewWriterSize(w, defaultBufSize)
}
+// Size returns the size of the underlying buffer in bytes.
+func (b *Writer) Size() int { return len(b.buf) }
+
// Reset discards any unflushed buffered data, clears any error, and
// resets b to write its output to w.
func (b *Writer) Reset(w io.Writer) {
diff --git a/libgo/go/bufio/bufio_test.go b/libgo/go/bufio/bufio_test.go
index ef0f6c834e8..c829d2b0648 100644
--- a/libgo/go/bufio/bufio_test.go
+++ b/libgo/go/bufio/bufio_test.go
@@ -1418,6 +1418,24 @@ func TestReaderDiscard(t *testing.T) {
}
+func TestReaderSize(t *testing.T) {
+ if got, want := NewReader(nil).Size(), DefaultBufSize; got != want {
+ t.Errorf("NewReader's Reader.Size = %d; want %d", got, want)
+ }
+ if got, want := NewReaderSize(nil, 1234).Size(), 1234; got != want {
+ t.Errorf("NewReaderSize's Reader.Size = %d; want %d", got, want)
+ }
+}
+
+func TestWriterSize(t *testing.T) {
+ if got, want := NewWriter(nil).Size(), DefaultBufSize; got != want {
+ t.Errorf("NewWriter's Writer.Size = %d; want %d", got, want)
+ }
+ if got, want := NewWriterSize(nil, 1234).Size(), 1234; got != want {
+ t.Errorf("NewWriterSize's Writer.Size = %d; want %d", got, want)
+ }
+}
+
// An onlyReader only implements io.Reader, no matter what other methods the underlying implementation may have.
type onlyReader struct {
io.Reader
diff --git a/libgo/go/bufio/export_test.go b/libgo/go/bufio/export_test.go
index 3d3bb27d8da..1667f01a841 100644
--- a/libgo/go/bufio/export_test.go
+++ b/libgo/go/bufio/export_test.go
@@ -11,6 +11,8 @@ import (
var IsSpace = isSpace
+const DefaultBufSize = defaultBufSize
+
func (s *Scanner) MaxTokenSize(n int) {
if n < utf8.UTFMax || n > 1e9 {
panic("bad max token size")
diff --git a/libgo/go/bufio/scan.go b/libgo/go/bufio/scan.go
index 9f741c98307..40aaa4ab817 100644
--- a/libgo/go/bufio/scan.go
+++ b/libgo/go/bufio/scan.go
@@ -123,8 +123,9 @@ var ErrFinalToken = errors.New("final token")
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
-// Scan panics if the split function returns 100 empty tokens without
-// advancing the input. This is a common error mode for scanners.
+// Scan panics if the split function returns too many empty
+// tokens without advancing the input. This is a common error mode for
+// scanners.
func (s *Scanner) Scan() bool {
if s.done {
return false
@@ -156,8 +157,8 @@ func (s *Scanner) Scan() bool {
} else {
// Returning tokens not advancing input at EOF.
s.empties++
- if s.empties > 100 {
- panic("bufio.Scan: 100 empty tokens without progressing")
+ if s.empties > maxConsecutiveEmptyReads {
+ panic("bufio.Scan: too many empty tokens without progressing")
}
}
return true