1
0
mirror of https://github.com/golang/go synced 2024-10-02 06:28:33 -06:00
Commit Graph

20976 Commits

Author SHA1 Message Date
Dmitri Shuralyov
912ec1990b go/format, cmd/gofmt: fix issues with partial Go code with indent
Fixes #5551.
Fixes #4449.

Adds tests for both issues.

Note that the two issues occur only when formatting partial Go code
with indent.

The best way to understand the change is as follows: I took the code
of cmd/gofmt and go/format, combined it into one unified code that
does not suffer from either 4449 nor 5551, and then applied that code
to both cmd/gofmt and go/format.

As a result, there is now much more identical code between the two
packages, making future code deduplication easier (it was not possible
to do that now without adding public APIs, which I was advised not to
do at this time).

More specifically, I took the parse() of cmd/gofmt which correctly
preserves comments (issue 5551) and modified it to fix issue where
it would sometimes modify literal values (issue 4449).

I ended up removing the matchSpace() function because it no longer
needed to do some of its work (insert indent), and a part of its work
had to be done in advance (determining the indentation of first code
line), because that calculation is required for cfg.Fprint() to run.

adjustIndent is used to adjust the indent of cfg.Fprint() to compensate
for the body of wrapper func being indented by one level. This allows
to get rid of the bytes.Replace text manipulation of inner content,
which was problematic and sometimes altered raw string literals (issue
4449). This means that sometimes the value of cfg.Indent is negative,
but that works as expected.

So now the algorithm for formatting partial Go code is:

1. Determine and prepend leading space of original source.
2. Determine and prepend indentation of first code line.
3. Format and write partial Go code (with all of its leading &
   trailing space trimmed).
4. Determine and append trailing space of original source.

LGTM=gri
R=golang-codereviews, bradfitz, gri
CC=golang-codereviews
https://golang.org/cl/142360043
2014-09-29 17:04:48 -07:00
Dave Cheney
0b36211cfb liblink: generate MRC replacement in liblink, not tls_arm
Fixes #8690.

This CL moves the save of LR around BL runtime.read_tls_fallback to liblink as it is not needed when MRC is not replaced.

LGTM=rsc, minux
R=rsc, khr, minux
CC=golang-codereviews
https://golang.org/cl/147310043
2014-09-30 10:03:10 +10:00
Tom Linford
5368e63b57 x509: add root certs for android.
On android, root certificates appear to be stored in the folder
/system/etc/security/cacerts, which has many certs in several
different files. This change adds a new array of directories in
which certs can be found.

To test this, I simply tried making a request with the http
library to an HTTPS URL on an android emulator and manually
verified that it worked.

LGTM=crawshaw
R=golang-codereviews, gobot, crawshaw
CC=golang-codereviews
https://golang.org/cl/151800043
2014-09-30 09:51:49 +10:00
Brad Fitzpatrick
3df5780126 A+C: Tom Linford (individual CLA)
Generated by a+c.

R=gobot
CC=golang-codereviews
https://golang.org/cl/149260044
2014-09-29 15:57:03 -07:00
Keith Randall
b4380a3ba2 runtime: delete unused variables.
We're not comparing with code addresses any more.  Instead,
we use nil algorithm functions to mark uncomparable types.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/151040044
2014-09-29 14:05:33 -07:00
James Tucker
2da734189d net/http: enable Transfer-Encoding: identity without Content-Length for HTTP 1.1.
Use case is SSE recommended configuration: http://www.w3.org/TR/eventsource/#notes
Removes a TODO.

LGTM=bradfitz
R=golang-codereviews, bradfitz, tommi.virtanen
CC=golang-codereviews
https://golang.org/cl/100000044
2014-09-29 13:53:42 -07:00
Brad Fitzpatrick
705c1f5cd4 net/http: clarify Request.FormValue docs
Fixes #8067

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/146480043
2014-09-29 13:42:33 -07:00
Ian Lance Taylor
fe2bc11e1f cmd/yacc: fix handling of tokens that don't start with letters
CL 149110043 changed yacc to no longer keep a leading space
for quoted tokens.  That is OK by itself but unfortunately
yacc was relying on that leading space to notice which tokens
it should not output as const declarations.

Add a few such tokens to expr.y, although it won't make any
immediate difference as we seem to have no tests for yacc.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/152720043
2014-09-29 13:32:14 -07:00
Brad Fitzpatrick
1cfa5958f0 undo CL 141840043 / 65e21380cb2a
Unnecessary; covered by https://golang.org/cl/141690043

Verified by jonathan@titanous.com on golang-dev.

««« original CL description
cmd/ld: close outfile before cleanup

This prevents the temporary directory from being leaked when
the linker is run on a FUSE filesystem.

Fixes #8684.

LGTM=bradfitz
R=golang-codereviews, rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/141840043

»»»

LGTM=jonathan, iant
R=iant, jonathan
CC=golang-codereviews
https://golang.org/cl/150250045
2014-09-29 13:28:08 -07:00
Robert Griesemer
259f0ffade spec: specify variable initialization order explicitly
The existing spec rules on package initialization were
contradictory: They specified that 1) dependent variables
are initialized in dependency order, and 2) independent
variables are initialized in declaration order. This 2nd
rule cannot be satisfied in general. For instance, for

var (
        c = b + 2
        a = 0
        b = 1
)

because of its dependency on b, c must be initialized after b,
leading to the partial order b, c. Because a is independent of
b but is declared before b, we end up with the order: a, b, c.
But a is also independent of c and is declared after c, so the
order b, c, a should also be valid in contradiction to a, b, c.

The new rules are given in form of an algorithm which outlines
initialization order explicitly.

gccgo and go/types already follow these rules.

Fixes #8485.

LGTM=iant, r, rsc
R=r, rsc, iant, ken, gordon.klaus, adonovan
CC=golang-codereviews
https://golang.org/cl/142880043
2014-09-29 12:44:50 -07:00
Adam Langley
dfddd802ac crypto/x509: accept CRLs without an expiry.
RFC5280 says that the nextUpdate field is optional.

Fixes #8085.

R=bradfitz
CC=golang-codereviews
https://golang.org/cl/149770044
2014-09-29 12:26:51 -07:00
Brad Fitzpatrick
dca460574f net: fix misleading package comment example
Fixes #8607

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/146470043
2014-09-29 12:24:06 -07:00
Adam Langley
bd72d2c650 go/build: add go1.4 tag.
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/138000044
2014-09-29 12:23:43 -07:00
Adam Langley
192665ed99 C: add Andres Erbsen (Google CLA)
LGTM=bradfitz, minux
R=bradfitz, minux
CC=golang-codereviews
https://golang.org/cl/119540043
2014-09-29 12:15:25 -07:00
Jonathan Rudenberg
e7e3b3ec10 cmd/ld: close outfile before cleanup
This prevents the temporary directory from being leaked when
the linker is run on a FUSE filesystem.

Fixes #8684.

LGTM=bradfitz
R=golang-codereviews, rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/141840043
2014-09-29 12:13:22 -07:00
Keith Randall
e1364a6d0e runtime: fix cgo_topofstack to save clobbered registers
Fixes #8816

At least, I hope it does.

TBR=rsc
CC=golang-codereviews
https://golang.org/cl/153730043
2014-09-28 23:52:08 -07:00
Ian Lance Taylor
f6fc14094a cmd/ld: don't automatically mark symbols created by -X as reachable
This fixes the bug in which the linker reports "missing Go
type information" when a -X option refers to a symbol that is
not used.

Fixes #8821.

LGTM=rsc
R=rsc, r
CC=golang-codereviews
https://golang.org/cl/151000043
2014-09-28 08:27:05 -07:00
Rob Pike
56c4d0a5c6 doc/faq: update for 1.4
LGTM=iant
R=golang-codereviews, bradfitz, iant
CC=golang-codereviews
https://golang.org/cl/150190043
2014-09-27 11:56:54 -07:00
Russ Cox
4a8cb4a49c math: avoid assumption of denormalized math mode in Sincos
The extra-clever code in Sincos is trying to do

        if v&2 == 0 {
                mask = 0xffffffffffffffff
        } else {
                mask = 0
        }

It does this by turning v&2 into a float64 X0 and then using

        MOVSD $0.0, X3
        CMPSD X0, X3, 0

That CMPSD is defined to behave like:

        if X0 == X3 {
                X3 = 0xffffffffffffffff
        } else {
                X3 = 0
        }

which gives the desired mask in X3. The goal in using the
CMPSD was to avoid a conditional branch.

This code fails when called from a PortAudio callback.
In particular, the failure behavior is exactly as if the
CMPSD always chose the 'true' execution.

Notice that the comparison X0 == X3 is comparing as
floating point values the 64-bit pattern v&2 and the actual
floating point value zero. The only possible values for v&2
are 0x0000000000000000 (floating point zero)
and 0x0000000000000002 (floating point 1e-323, a denormal).
If they are both comparing equal to zero, I conclude that
in a PortAudio callback (whatever that means), the processor
is running in "denormals are zero" mode.

I confirmed this by placing the processor into that mode
and running the test case in the bug; it produces the
incorrect output reported in the bug.

In general, if a Go program changes the floating point math
modes to something other than what Go expects, the math
library is not going to work exactly as intended, so we might
be justified in not fixing this at all.

However, it seems reasonable that the client code might
have expected "denormals are zero" mode to only affect
actual processing of denormals. This code has produced
what is in effect a gratuitous denormal by being extra clever.
There is nothing about the computation being requested
that fundamentally requires a denormal.

It is also easy to do this computation in integer math instead:

        mask = ((v&2)>>1)-1

Do that.

For the record, the other math tests that fail if you put the
processor in "denormals are zero" mode are the tests for
Frexp, Ilogb, Ldexp, Logb, Log2, and FloatMinMax, but all
fail processing denormal inputs. Sincos was the only function
for which that mode causes incorrect behavior on non-denormal inputs.

The existing tests check that the new assembly is correct.
There is no test for behavior in "denormals are zero" mode,
because I don't want to add assembly to change that.

Fixes #8623.

LGTM=josharian
R=golang-codereviews, josharian
CC=golang-codereviews, iant, r
https://golang.org/cl/151750043
2014-09-26 17:13:24 -04:00
Russ Cox
1d9c03150e doc/go1.4: go test builds + links all test files (CL 150980043)
CC=golang-codereviews
https://golang.org/cl/144660043
2014-09-26 17:09:40 -04:00
Russ Cox
754cd5419a cmd/go: always build _test.go files and link into test
go test's handling of _test.go files when the entire
package's set of files has no Test functions has varied
over the past few releases. There are a few interesting
cases (all contain no Test functions):
        (1) x_test.go has syntax errors
        (2) x_test.go has type errors
        (3) x_test.go has runtime errors (say, a func init that panics)

In Go 1.1, tests with (1) or (2) failed; (3) passed.
In Go 1.2, tests with (1) or (2) failed; (3) passed.
In Go 1.3, tests with (1) failed; (2) or (3) passed.
After this CL, tests with (1), (2), or (3) all fail.

This is clearly a corner case, but it seems to me that
the behavior of the test should not change if you
add or remove a line like

        func TestAlwaysPasses(t *testing.T) {}

That implies that the _test.go files must always
be built and always be imported into the test binary.
Doing so means that (1), (2), and (3) must all fail.

Fixes #8337.

LGTM=iant
R=golang-codereviews, iant
CC=adg, golang-codereviews, r
https://golang.org/cl/150980043
2014-09-26 17:09:11 -04:00
Russ Cox
bfebf9ea80 cmd/yacc: fix parsing of character tokens
From issue 7967 I learned:

1) yacc accepts either 'x' or "x" to mean token value 0x78
2) yacc also accepts 'xyz' and "XYZ" to mean token value 0x78

Use strconv.Unquote to simplify the handling of quoted
strings and check that each has only one rune.

Although this does clean things up, it makes 'x' and "x"
treated as different internally (now they are stored as
`'x'` and `"x"`; before they were both ` x`). Grammars that
use both interchangeably will now die with an error
similar to the one from issue 7967:

        yacc bug -- cannot have 2 different Ts with same value
                "+" and '+'

The echoing of the quotes should make clear what is going on.

The other semantic change caused by using strconv.Unquote
is that '\"' and "\'" are no longer valid. Like in Go, they must be
spelled without the backslash: '"' and "'".

On the other hand, now yacc and Go agree about what character
and string literals mean.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/149110043
2014-09-26 17:03:31 -04:00
Rob Pike
b2487ef6a3 flag: allow CommandLine's Usage function to be set
Fixes #7779.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/147210043
2014-09-26 12:33:05 -07:00
Russ Cox
1bf18b42f8 cmd/go: fix -a
The one line that you can't test easily was broken.
This manifested as a failure of a pre-existing test
in test.bash but I didn't notice it (there are a few other
long-standing failures that need to be fixed).

TBR=r
CC=golang-codereviews
https://golang.org/cl/146340044
2014-09-26 15:15:48 -04:00
Russ Cox
8c3005c492 cmd/go: make build -a skip standard packages in Go releases
Today, 'go build -a my/pkg' and 'go install -a my/pkg'
recompile not just my/pkg and all its dependencies that
you wrote but also the standard library packages.
Recompiling the standard library is problematic on
some systems because the installed copy is not writable.

The -a behavior means that you can't use 'go install -a all'
or 'go install -a my/...' to rebuild everything after a Go
release - the rebuild stops early when it cannot overwrite
the installed standard library.

During development work, however, you do want install -a
to rebuild everything, because anything might have changed.

Resolve the conflict by making the behavior of -a depend
on whether we are using a released copy of Go or a devel copy.
In the release copies, -a no longer applies to the standard library.
In the devel copies, it still does.

This is the latest in a long line of refinements to the
"do I build this or not" logic. It is surely not the last.

Fixes #8290.

LGTM=r
R=golang-codereviews, r, tracey.brendan
CC=adg, golang-codereviews, iant
https://golang.org/cl/151730045
2014-09-26 14:41:26 -04:00
Russ Cox
e5afecbd0e doc/go1.4: add some cmd/go changes
CC=golang-codereviews
https://golang.org/cl/143650043
2014-09-26 14:37:38 -04:00
Alex Brainman
0b8bc7cee9 cmd/go: handle paths like \x.go on windows
Fixes #8130.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/143200043
2014-09-26 14:36:49 -04:00
Russ Cox
df781cc4ab liblink: fix cmd/ld -X flag
This fixes the test/linkx.go test, which does not run by default.
(Issue 4139 is about fixing that.)

Fixes #8806.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews, iant
https://golang.org/cl/145420043
2014-09-26 13:50:53 -04:00
Russ Cox
6d760fb082 cmd/go: document that testdata directories are ignored
Also rebuild doc.go; was stale, so contains extra changes.

Fixes #8677.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/148170043
2014-09-26 13:50:39 -04:00
Russ Cox
ce143f25e6 cmd/go: add test -o flag to control where test binary is written
While we are here, remove undocumented, meaningless test -file flag.

Fixes #7724.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/149070043
2014-09-26 13:50:02 -04:00
Russ Cox
13a2c1ca78 cmd/go: display program name when reporting crash
Fix by atom (from CL 89190044), comment and test by me.

Fixes #6823.

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=0xe2.0x9a.0x9b, adg, golang-codereviews, iant, r
https://golang.org/cl/148180043
2014-09-26 13:48:30 -04:00
Russ Cox
b86105e80d cmd/go: make malformed import path message more precise
If you say 'go get -v' you get extra information when import
paths are not of the expected form.

If you say 'go get -v src/rsc.io/pdf' the message says that
src/rsc.io/pdf does not contain a hostname, which is incorrect.
The problem is that it does not begin with a hostname.

Fixes #7432.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews, iant
https://golang.org/cl/144650043
2014-09-26 13:47:51 -04:00
Russ Cox
f3a98dee27 cmd/go: re-resolve and check vcs roots during go get -u
If you do 'go get -u rsc.io/pdf' and then rsc.io/pdf's redirect
changes to point somewhere else, after this CL a later
'go get -u rsc.io/pdf' will tell you that.

Fixes #8548.

LGTM=iant
R=golang-codereviews, iant
CC=adg, golang-codereviews, n13m3y3r, r
https://golang.org/cl/147170043
2014-09-26 12:10:13 -04:00
Russ Cox
7fa96f08a4 cmd/go: fix 'go get vanity/repo/...' in clean GOPATH
The pattern was only working if the checkout had
already been done, but the code was trying to make
it work even the first time. Test and fix.

Fixes #8335.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/146310043
2014-09-26 12:09:27 -04:00
Adam Langley
64df53ed7f crypto/tls: ensure that we don't resume when tickets are disabled.
LGTM=r
R=r, adg, rsc
https://golang.org/cl/148080043
2014-09-26 11:02:09 +10:00
Andrew Gerrand
706efdb12c doc: document Go 1.3.2
LGTM=r
R=r, rsc, iant, agl
https://golang.org/cl/142650045
2014-09-26 11:00:49 +10:00
Andrew Gerrand
a326d1d00c tag go1.3.2
LGTM=r
R=r, rsc
CC=golang-codereviews
https://golang.org/cl/150100044
2014-09-26 10:53:09 +10:00
Rob Pike
0211771f2b .hgignore: delete some dregs
I'd rather delete the file but I doubt that will be popular.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/150100043
2014-09-25 17:30:12 -07:00
Rob Pike
868948badf encoding/gob: fix 386 build
LGTM=ruiu
R=golang-codereviews, ruiu
CC=golang-codereviews
https://golang.org/cl/146320043
2014-09-25 17:16:27 -07:00
Rob Pike
9c3fc838ba encoding/gob: error rather than panic when decoding enormous slices
Fixes #8084.

LGTM=ruiu
R=golang-codereviews, ruiu
CC=golang-codereviews
https://golang.org/cl/142710043
2014-09-25 15:18:25 -07:00
Rob Pike
dff461f935 doc/gopher: add biplane.jpg
LGTM=0intro
R=golang-codereviews, 0intro
CC=golang-codereviews
https://golang.org/cl/150960043
2014-09-25 14:10:56 -07:00
Russ Cox
dd84cf4ea0 cmd/go: install dependencies for 'go build -i' on a command
Fixes #8242.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/147150043
2014-09-25 15:57:52 -04:00
Robert Griesemer
2fa3e43fae spec: clarify scope and re-use of iteration variables
Fixes #7834.

LGTM=iant, rsc, r
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/148940044
2014-09-25 12:52:05 -07:00
Robert Griesemer
bb29c5a1ed spec: clarify embedding of interfaces
Fixes #7886.

LGTM=iant, r, rsc
R=r, iant, rsc, ken
CC=golang-codereviews
https://golang.org/cl/149010043
2014-09-25 12:49:42 -07:00
Rob Pike
74c0de8fb6 bufio: fix handling of empty tokens at end of line/file
Fixes #8672.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/145390043
2014-09-25 12:45:21 -07:00
Rob Pike
cfae41ff36 time: make it clear that time.Time values do not compare with ==
LGTM=bradfitz, josharian, adg, rsc
R=golang-codereviews, bradfitz, josharian, rsc, adg
CC=golang-codereviews
https://golang.org/cl/141340043
2014-09-25 10:52:02 -07:00
Russ Cox
870f4e190c cmd/gc: emit error for out-of-bounds slice of constant string
Fixes #7200.

LGTM=gri, iant
R=golang-codereviews, gri, iant
CC=golang-codereviews, r
https://golang.org/cl/150020044
2014-09-25 13:24:43 -04:00
Russ Cox
52e9bcafe1 cmd/gc: print x++ (not x += 1) in errors about x++
Fixes #8311.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/146270043
2014-09-25 13:13:02 -04:00
Russ Cox
53c66543e0 cmd/gc: avoid infinite recursion on invalid recursive type
Fixes #8507.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/144560043
2014-09-25 13:08:37 -04:00
Keith Randall
1aa65fe8d4 runtime: add load_g call in arm callback.
Need to restore the g register.  Somehow this line vaporized from
CL 144130043.  Also cgo_topofstack -> _cgo_topofstack, that vaporized also.

TBR=rsc
CC=golang-codereviews
https://golang.org/cl/150940044
2014-09-25 08:37:04 -07:00