1. 29 Nov, 2016 4 commits
    • Brad Fitzpatrick's avatar
      doc: update go1.8.html after feedback from Russ · 0c5c7c34
      Brad Fitzpatrick authored
      Address Russ's feedback from https://golang.org/cl/33244
      
      TBR=See https://golang.org/cl/33244
      
      Updates #17929
      
      Change-Id: I708d71f519f6414ecec629d3c273d9e737d8ed50
      Reviewed-on: https://go-review.googlesource.com/33656Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      0c5c7c34
    • Ian Lance Taylor's avatar
      cmd/link: handle STT_COMMON symbols · 45f75950
      Ian Lance Taylor authored
      Tested by running
      
      GOTRACEBACK=2 CGO_CFLAGS="-Wa,--elf-stt-common=yes" go test -ldflags=-linkmode=internal
      
      in misc/cgo/test. That failed before this CL, succeeded after.
      
      I don't think it's worth doing that as a regular test, though,
      especially since only recent versions of the GNU binutils support the
      --elf-stt-common option.
      
      Fixes #18088.
      
      Change-Id: I893d86181faee217b1504c054b0ed3f7c8d977d3
      Reviewed-on: https://go-review.googlesource.com/33653
      Run-TryBot: Ian Lance Taylor <iant@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      45f75950
    • Russ Cox's avatar
      os: fix handling of Windows Unicode console input and ^Z · 610d5221
      Russ Cox authored
      Go 1.5 worked with Unicode console input but not ^Z.
      Go 1.6 did not work with Unicode console input but did handle one ^Z case.
      Go 1.7 did not work with Unicode console input but did handle one ^Z case.
      
      The intent of this CL is for Go 1.8 to work with Unicode console input
      and also handle all ^Z cases.
      
      Here's a simple test program for reading from the console.
      It prints a "> " prompt, calls read, prints what it gets, and repeats.
      
      	package main
      
      	import (
      	    "fmt"
      	    "os"
      	)
      
      	func main() {
      	    p := make([]byte, 100)
      	    fmt.Printf("> ")
      	    for {
      	        n, err := os.Stdin.Read(p)
      	        fmt.Printf("[%d %q %v]\n> ", n, p[:n], err)
      	    }
      	}
      
      On Unix, typing a ^D produces a break in the input stream.
      If the ^D is at the beginning of a line, then the 0 bytes returned
      appear as an io.EOF:
      
      	$ go run /tmp/x.go
      	> hello
      	[6 "hello\n" <nil>]
      	> hello^D[5 "hello" <nil>]
      	> ^D[0 "" EOF]
      	> ^D[0 "" EOF]
      	> hello^Dworld
      	[5 "hello" <nil>]
      	> [6 "world\n" <nil>]
      	>
      
      On Windows, the EOF character is ^Z, not ^D, and there has
      been a long-standing problem that in Go programs, ^Z on Windows
      does not behave in the expected way, namely like ^D on Unix.
      Instead, the ^Z come through as literal ^Z characters:
      
      	C:\>c:\go1.5.4\bin\go run x.go
      	> ^Z
      	[3 "\x1a\r\n" <nil>]
      	> hello^Zworld
      	[13 "hello\x1aworld\r\n" <nil>]
      	>
      
      CL 4310 attempted to fix this bug, then known as #6303,
      by changing the use of ReadConsole to ReadFile.
      This CL was released as part of Go 1.6 and did fix the case
      of a ^Z by itself, but not as part of a larger input:
      
      	C:\>c:\go1.6.3\bin\go run x.go
      	> ^Z
      	[0 "" EOF]
      	> hello^Zworld
      	[13 "hello\x1aworld\r\n" <nil>]
      	>
      
      So the fix was incomplete.
      Worse, the fix broke Unicode console input.
      
      ReadFile does not handle Unicode console input correctly.
      To handle Unicode correctly, programs must use ReadConsole.
      Early versions of Go used ReadFile to read the console,
      leading to incorrect Unicode handling, which was filed as #4760
      and fixed in CL 7312053, which switched to ReadConsole
      and was released as part of Go 1.1 and still worked as of Go 1.5:
      
      	C:\>c:\go1.5.4\bin\go run x.go
      	> hello
      	[7 "hello\r\n" <nil>]
      	> hello world
      	[16 "hello world\r\n" <nil>]
      	>
      
      But in Go 1.6:
      
      	C:\>c:\go1.6.3\bin\go run x.go
      	> hello
      	[7 "hello\r\n" <nil>]
      	> hello world
      	[0 "" EOF]
      	>
      
      That is, changing back to ReadFile in Go 1.6 reintroduced #4760,
      which has been refiled as #17097. (We have no automated test
      for this because we don't know how to simulate console input
      in a test: it appears that one must actually type at a keyboard
      to use the real APIs. This CL at least adds a comment warning
      not to reintroduce ReadFile again.)
      
      CL 29493 attempted to fix #17097, but it was not a complete fix:
      the hello world example above still fails, as does Shift-JIS input,
      which was filed as #17939.
      
      CL 29493 also broke ^Z handling, which was filed as #17427.
      
      This CL attempts the never before successfully performed trick
      of simultaneously fixing Unicode console input and ^Z handling.
      It changes the console input to use ReadConsole again,
      as in Go 1.5, which seemed to work for all known Unicode input.
      Then it adds explicit handling of ^Z in the input stream.
      (In the case where standard input is a redirected file, ^Z processing
      should not happen, and it does not, because this code path is only
      invoked when standard input is the console.)
      
      With this CL:
      
      	C:\>go run x.go
      	> hello
      	[7 "hello\r\n" <nil>]
      	> hello world
      	[16 "hello world\r\n" <nil>]
      	> ^Z
      	[0 "" EOF]
      	> [2 "\r\n" <nil>]
      	> hello^Zworld
      	[5 "hello" <nil>]
      	> [0 "" EOF]
      	> [7 "world\r\n" <nil>]
      
      This almost matches Unix:
      
      	$ go run /tmp/x.go
      	> hello
      	[6 "hello\n" <nil>]
      	> hello world
      	[15 "hello world\n" <nil>]
      	> ^D
      	[0 "" EOF]
      	> [1 "\n" <nil>]
      	> hello^Dworld
      	[5 "hello" <nil>]
      	> [6 "world\n" <nil>]
      	>
      
      The difference is in the handling of hello^Dworld / hello^Zworld.
      On Unix, hello^Dworld terminates the read of hello but does not
      result in a zero-length read between reading hello and world.
      This is dictated by the tty driver, not any special Go code.
      
      On Windows, in this CL, hello^Zworld inserts a zero length read
      result between hello and world, which is treated as an interior EOF.
      This is implemented by the Go code in this CL, but it matches the
      handling of ^Z on the console in other programs:
      
      	C:\>copy con x.txt
      	hello^Zworld
      	        1 file(s) copied.
      
      	C:\>type x.txt
      	hello
      	C:\>
      
      A natural question is how to test all this. As noted above, we don't
      know how to write automated tests using the actual Windows console.
      CL 29493 introduced the idea of substituting a different syscall.ReadFile
      implementation for testing; this CL continues that idea but substituting
      for syscall.ReadConsole instead. To avoid the regression of putting
      ReadFile back, this CL adds a comment warning against that.
      
      Fixes #17427.
      Fixes #17939.
      
      Change-Id: Ibaabd0ceb2d7af501d44ac66d53f64aba3944142
      Reviewed-on: https://go-review.googlesource.com/33451
      Run-TryBot: Russ Cox <rsc@golang.org>
      Reviewed-by: default avatarQuentin Smith <quentin@golang.org>
      Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      610d5221
    • David Crawshaw's avatar
      os: Executable can use /proc/self/exe on android · 8a2c34e4
      David Crawshaw authored
      Fixes the os test on the Android builder.
      
      Change-Id: Ibb9db712156a620fcccf515e035475c5e2f535a5
      Reviewed-on: https://go-review.googlesource.com/33650
      Run-TryBot: David Crawshaw <crawshaw@golang.org>
      Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      8a2c34e4
  2. 28 Nov, 2016 6 commits
  3. 26 Nov, 2016 1 commit
  4. 25 Nov, 2016 1 commit
    • Daniel Martí's avatar
      testing: comment out flag.Parse from example · 11106492
      Daniel Martí authored
      The TestMain docs explain that flag.Parse() should be called if TestMain
      itself depends on command-line flags.
      
      The issue here is that the example implementation does not use any
      flags, and thus the flag.Parse call is unnecessary. This leads to people
      who use this example as a starting point for their own implementations
      to forget that the call is not necessary in most cases.
      
      Comment it out instead of removing the line to keep it as a reminder, as
      suggested by Minux Ma.
      
      Change-Id: I6ffc5413e7036366ae3cf0f069b7065e832a3b45
      Reviewed-on: https://go-review.googlesource.com/33273Reviewed-by: default avatarMinux Ma <minux@golang.org>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      11106492
  5. 24 Nov, 2016 3 commits
  6. 23 Nov, 2016 8 commits
  7. 22 Nov, 2016 17 commits
    • Daniel Theophanes's avatar
      database/sql: fix TestPendingConnsAfterErr · e12f6ee0
      Daniel Theophanes authored
      TestPendingConnsAfterErr showed a failure on slower systems.
      Wait and check for the database to close all connections
      before pronouncing failure.
      
      A more careful method was attempted but the connection pool
      behavior is too dependent on the scheduler behavior to be
      predictable.
      
      Fixes #15684
      
      Change-Id: Iafdbc90ba51170c76a079db04c3d5452047433a4
      Reviewed-on: https://go-review.googlesource.com/33418Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      e12f6ee0
    • Joe Tsai's avatar
      doc: fix typos in go1.8.html · 199d410d
      Joe Tsai authored
      Change-Id: I51180e1c685e488f7ea4c51a63fd035148671b05
      Reviewed-on: https://go-review.googlesource.com/33470Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      199d410d
    • Brad Fitzpatrick's avatar
      doc: more go1.8.html content · f756204f
      Brad Fitzpatrick authored
      TBR=See https://golang.org/cl/33244 and review there.
      
      Updates #17929
      
      Change-Id: I7cb0b666469dba35426d1f0ae1b185e0bdfeac05
      Reviewed-on: https://go-review.googlesource.com/33474Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      f756204f
    • David du Colombier's avatar
      cmd/go: print CC environment variables on Plan 9 · 46323795
      David du Colombier authored
      This changes makes the output of `go env` the same
      as on other operating systems.
      
      Fixes #18013.
      
      Change-Id: I3079e14dcf7b30c75ec3fde6c78cb95721111320
      Reviewed-on: https://go-review.googlesource.com/33396Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      Run-TryBot: Ian Lance Taylor <iant@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      46323795
    • Michael Munday's avatar
      runtime/pprof/internal/protopprof: fix test on s390x · 55085611
      Michael Munday authored
      Applies the fix from CL 32920 to the new test TestSampledHeapAllocProfile
      introduced in CL 33422. The test should be skipped rather than fail if
      there is only one executable region of memory.
      
      Updates #17852.
      
      Change-Id: Id8c47b1f17ead14f02a58a024c9a04ebb8ec0429
      Reviewed-on: https://go-review.googlesource.com/33453
      Run-TryBot: Michael Munday <munday@ca.ibm.com>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      55085611
    • Russ Cox's avatar
      runtime: do not print runtime panic frame at top of user stack · f9feaffd
      Russ Cox authored
      The expected default behavior (no explicit GOTRACEBACK setting)
      is for the stack trace to start in user code, eliding unnecessary runtime
      frames that led up to the actual trace printing code. The idea was that
      the first line number printed was the one that crashed.
      
      For #5832 we added code to show 'panic' frames so that if code panics
      and then starts running defers and then we trace from there, the panic
      frame can help explain why the code seems to have made a call not
      present in the code. But that's only needed for panics between two different
      call frames, not the panic at the very top of the stack trace.
      Fix the fix to again elide the runtime code at the very top of the stack trace.
      
      Simple panic:
      
      	package main
      
      	func main() {
      		var x []int
      		println(x[1])
      	}
      
      Before this CL:
      
      	panic: runtime error: index out of range
      
      	goroutine 1 [running]:
      	panic(0x1056980, 0x1091bf0)
      		/Users/rsc/go/src/runtime/panic.go:531 +0x1cf
      	main.main()
      		/tmp/x.go:5 +0x5
      
      After this CL:
      
      	panic: runtime error: index out of range
      
      	goroutine 1 [running]:
      	main.main()
      		/tmp/x.go:5 +0x5
      
      Panic inside defer triggered by panic:
      
      	package main
      
      	func main() {
      		var x []int
      		defer func() {
      			println(x[1])
      		}()
      		println(x[2])
      	}
      
      Before this CL:
      
      	panic: runtime error: index out of range
      		panic: runtime error: index out of range
      
      	goroutine 1 [running]:
      	panic(0x1056aa0, 0x1091bf0)
      		/Users/rsc/go/src/runtime/panic.go:531 +0x1cf
      	main.main.func1(0x0, 0x0, 0x0)
      		/tmp/y.go:6 +0x62
      	panic(0x1056aa0, 0x1091bf0)
      		/Users/rsc/go/src/runtime/panic.go:489 +0x2cf
      	main.main()
      		/tmp/y.go:8 +0x59
      
      The middle panic is important: it explains why main.main ended up calling main.main.func1 on a line that looks like a call to println. The top panic is noise.
      
      After this CL:
      
      	panic: runtime error: index out of range
      		panic: runtime error: index out of range
      
      	goroutine 1 [running]:
      	main.main.func1(0x0, 0x0, 0x0)
      		/tmp/y.go:6 +0x62
      	panic(0x1056ac0, 0x1091bf0)
      		/Users/rsc/go/src/runtime/panic.go:489 +0x2cf
      	main.main()
      		/tmp/y.go:8 +0x59
      
      Fixes #17901.
      
      Change-Id: Id6d7c76373f7a658a537a39ca32b7dc23e1e76aa
      Reviewed-on: https://go-review.googlesource.com/33165
      Run-TryBot: Russ Cox <rsc@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      f9feaffd
    • Brad Fitzpatrick's avatar
      doc: more go1.8.html content · ac1dbe63
      Brad Fitzpatrick authored
      TBR=See https://golang.org/cl/33244 and review there.
      
      Updates #17929
      
      Change-Id: I37b49318a9203b16c0c788926039288b99a36ce5
      Reviewed-on: https://go-review.googlesource.com/33450Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      ac1dbe63
    • Michael Matloob's avatar
      runtime/pprof: generate heap profiles in compressed proto format · 86ab09ee
      Michael Matloob authored
      When debug is 0, emit the compressed proto format.
      The debug>0 format stays the same.
      
      Updates #16093
      
      Change-Id: I45aa1874a22d34cf44dd4aa78bbff9302381cb34
      Reviewed-on: https://go-review.googlesource.com/33422
      Run-TryBot: Michael Matloob <matloob@golang.org>
      Reviewed-by: default avatarRuss Cox <rsc@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      86ab09ee
    • Brad Fitzpatrick's avatar
      doc: go1.8.html updates from Joe Tsai · f88a33ae
      Brad Fitzpatrick authored
      Updates #17929
      
      Change-Id: Ibc711d39d9ff83458d213778117493796b678aa7
      Reviewed-on: https://go-review.googlesource.com/33437Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      f88a33ae
    • Brad Fitzpatrick's avatar
      doc: start of go1.8.html release notes · e47b7af6
      Brad Fitzpatrick authored
      Updates #17929
      
      Change-Id: Ie90736cfce3fc5f23cbe0a0f1971476705aac5f9
      Reviewed-on: https://go-review.googlesource.com/33436Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
      e47b7af6
    • Brad Fitzpatrick's avatar
      time: make Parse validate day's lower bound in addition to upper bound · 323b5c9d
      Brad Fitzpatrick authored
      Day 0 is as invalid as day 32.
      
      Fixes #17874
      
      Change-Id: I52109d12bafd6d957d00c44d540cb88389fff0a7
      Reviewed-on: https://go-review.googlesource.com/33429
      Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      323b5c9d
    • Brad Fitzpatrick's avatar
      net/http: fix parallel tests using global DefaultTransport · 409a667f
      Brad Fitzpatrick authored
      When I added t.Parallel to some tests earlier, I overlooked some using
      the global "Get" func, which uses DefaultTransport.
      
      The DefaultTransport can have its CloseIdleConnections called by other
      parallel tests. Use a private Transport instead.
      
      Fixes #18006
      
      Change-Id: Ia4faca5bac235cfa95dcf2703c25f3627112a5e9
      Reviewed-on: https://go-review.googlesource.com/33432
      Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      409a667f
    • Ian Lance Taylor's avatar
      runtime: sleep a bit to let a bad signal be delivered · 75055de8
      Ian Lance Taylor authored
      When we raise a signal that was delivered to C code, it's possible that
      the kernel will not deliver it immediately. This is especially possible
      on Darwin where we use send the signal to the entire process rather than
      just the current thread. Sleep for a millisecond after sending the
      signal to give it a chance to be delivered before we restore the Go
      signal handler. In most real cases the program is going to crash at this
      point, so sleeping is kind of irrelevant anyhow.
      
      Fixes #14809.
      
      Change-Id: Ib2c0d2c4e240977fb4535dc1dd2bdc50d430eb85
      Reviewed-on: https://go-review.googlesource.com/33300
      Run-TryBot: Ian Lance Taylor <iant@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarRuss Cox <rsc@golang.org>
      75055de8
    • Ian Lance Taylor's avatar
      cmd/go: don't clobber `go env GOGCCFLAGS` · e9ffda45
      Ian Lance Taylor authored
      When CC is set in the environment, the mkEnv function sets its version
      of CC to the first word $CC and sets GOGCCFLAGS to the remainder. That
      worked since Go 1 but was broken accidentally by
      https://golang.org/cl/6409, which changed the code such that `go env`
      calls mkEnv twice. The second call to mkEnv would clobber GOGCCFLAGS
      based on the value of CC set by the first call. Go back to the old
      handling by only calling mkEnv once.
      
      Fixes #15457.
      
      Change-Id: I000a1ebcc48684667e48f2b9b24605867b9e06cd
      Reviewed-on: https://go-review.googlesource.com/33293Reviewed-by: default avatarRuss Cox <rsc@golang.org>
      e9ffda45
    • David Crawshaw's avatar
      cmd/compile, cmd/link: weak relocation for ptrTo · 6f31abd2
      David Crawshaw authored
      Introduce R_WEAKADDROFF, a "weak" variation of the R_ADDROFF relocation
      that will only reference the type described if it is in some other way
      reachable.
      
      Use this for the ptrToThis field in reflect type information where it
      is safe to do so (that is, types that don't need to be included for
      interface satisfaction, and types that won't cause the compiler to
      recursively generate an endless series of ptr-to-ptr-to-ptr-to...
      types).
      
      Also fix a small bug in reflect, where StructOf was not clearing the
      ptrToThis field of new types.
      
      Fixes #17931
      
      Change-Id: I4d3b53cb9c916c97b3b16e367794eee142247281
      Reviewed-on: https://go-review.googlesource.com/33427
      Run-TryBot: David Crawshaw <crawshaw@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
      6f31abd2
    • Brad Fitzpatrick's avatar
      net/http: skip TestLinuxSendfile on mips64 for now · aeaa4c3c
      Brad Fitzpatrick authored
      See issues for details. We can expand this test during the Go 1.9
      cycle.
      
      Updates #18008
      
      Change-Id: I78b6b7e8dede414769be97898e29f969bc2a9651
      Reviewed-on: https://go-review.googlesource.com/33430Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
      aeaa4c3c
    • Russ Cox's avatar
      math/big: add Baillie-PSW test to (*Int).ProbablyPrime · 37d078ed
      Russ Cox authored
      After x.ProbablyPrime(n) passes the n Miller-Rabin rounds,
      add a Baillie-PSW test before declaring x probably prime.
      
      Although the provable error bounds are unchanged, the empirical
      error bounds drop dramatically: there are no known inputs
      for which Baillie-PSW gives the wrong answer. For example,
      before this CL, big.NewInt(443*1327).ProbablyPrime(1) == true.
      Now it is (correctly) false.
      
      The new Baillie-PSW test is two pieces: an added Miller-Rabin
      round with base 2, and a so-called extra strong Lucas test.
      (See the references listed in prime.go for more details.)
      The Lucas test takes about 3.5x as long as the Miller-Rabin round,
      which is close to theoretical expectations.
      
      name                              time/op
      ProbablyPrime/Lucas             2.91ms ± 2%
      ProbablyPrime/MillerRabinBase2   850µs ± 1%
      ProbablyPrime/n=0               3.75ms ± 3%
      
      The speed of prime testing for a prime input does get slower:
      
      name                  old time/op  new time/op   delta
      ProbablyPrime/n=1    849µs ± 1%   4521µs ± 1%  +432.31%   (p=0.000 n=10+9)
      ProbablyPrime/n=5   4.31ms ± 3%   7.87ms ± 1%   +82.70%  (p=0.000 n=10+10)
      ProbablyPrime/n=10  8.52ms ± 3%  12.28ms ± 1%   +44.11%  (p=0.000 n=10+10)
      ProbablyPrime/n=20  16.9ms ± 2%   21.4ms ± 2%   +26.35%   (p=0.000 n=9+10)
      
      However, because the Baillie-PSW test is only added when the old
      ProbablyPrime(n) would return true, testing composites runs at
      the same speed as before, except in the case where the result
      would have been incorrect and is now correct.
      
      In particular, the most important use of this code is for
      generating random primes in crypto/rand. That use spends
      essentially all its time testing composites, so it is not
      slowed down by the new Baillie-PSW check:
      
      name                  old time/op  new time/op   delta
      Prime                104ms ±22%    111ms ±16%      ~     (p=0.165 n=10+10)
      
      Thanks to Serhat Şevki Dinçer for CL 20170, which this CL builds on.
      
      Fixes #13229.
      
      Change-Id: Id26dde9b012c7637c85f2e96355d029b6382812a
      Reviewed-on: https://go-review.googlesource.com/30770
      Run-TryBot: Russ Cox <rsc@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
      37d078ed