Commits

Joseph Poirier committed 8be905d Merge

Merged changes from golang.

  • Participants
  • Parent commits 44627d9, 50000b8

Comments (0)

Files changed (159)

 dc5e410f0b4c32ab11dc992593a2bcf5f607381b weekly
 920e9d1ffd1f46665dd152aa9cf3c0f17d68dd88 go1
 2ccfd4b451d319941bfe3e08037e1462d3c15093 go1.0.1
-2ccfd4b451d319941bfe3e08037e1462d3c15093 release
+5e806355a9e1491aaab53d3612fed4c550b130c0 go1.0.2
+5e806355a9e1491aaab53d3612fed4c550b130c0 release
 Alexander Orlov <alexander.orlov@loxal.net>
 Alexander Reece <awreece@gmail.com>
 Alexey Borzenkov <snaury@gmail.com>
+Amir Mohammad Saied <amir@gluegadget.com>
 Amrut Joshi <amrut.joshi@gmail.com>
 Andrei Vieru <euvieru@gmail.com>
 Andrew Balholm <andybalholm@gmail.com>
 Chris Jones <chris@cjones.org>
 Chris Lennert <calennert@gmail.com>
 Christian Himpel <chressie@googlemail.com>
+Christine Hansmann <chhansmann@gmail.com>
 Christoph Hack <christoph@tux21b.org>
 Christopher Nielsen <m4dh4tt3r@gmail.com>
 Christopher Redden <christopher.redden@gmail.com>
 Jim McGrath <jimmc2@gmail.com>
 Joe Poirier <jdpoirier@gmail.com>
 John Asmuth <jasmuth@gmail.com>
+Jonathan Gold <jgold.bg@gmail.com>
 Jonathan Mark <jhmark@xenops.com>
 Jonathan Wills <runningwild@gmail.com>
 Jongmin Kim <atomaths@gmail.com>
 Kevin Ballard <kevin@sb.org>
 Kyle Consalus <consalus@gmail.com>
 Kyle Lemons <kyle@kylelemons.net>
+L Campbell <unpantsu@gmail.com>
 Lai Jiangshan <eag0628@gmail.com>
 Lorenzo Stoakes <lstoakes@gmail.com>
 Luca Greco <luca.greco@alcacoop.it>
 Michael Gehring <mg@ebfe.org>
 Michael Hoisie <hoisie@gmail.com>
 Michael Lewis <mikelikespie@gmail.com>
+Michael Stapelberg <michael@stapelberg.de>
 Michał Derkacz <ziutek@lnet.pl>
 Miek Gieben <miek@miek.nl>
 Mikael Tillenius <mikti42@gmail.com>
 Szabolcs Nagy <nsz@port70.net>
 Tarmigan Casebolt <tarmigan@gmail.com>
 Taru Karttunen <taruti@taruti.net>
+Thomas Alan Copeland <talan.copeland@gmail.com>
 Timo Savola <timo.savola@gmail.com>
 Tor Andersson <tor.andersson@gmail.com>
 Ugorji Nwoke <ugorji@gmail.com>

File CONTRIBUTORS

 Alexander Reece <awreece@gmail.com>
 Alexandru Moșoi <brtzsnr@gmail.com>
 Alexey Borzenkov <snaury@gmail.com>
+Amir Mohammad Saied <amir@gluegadget.com>
 Amrut Joshi <amrut.joshi@gmail.com>
 Andrea Spadaccini <spadaccio@google.com>
 Andrei Vieru <euvieru@gmail.com>
 Chris Jones <chris@cjones.org> <chris.jones.yar@gmail.com>
 Chris Lennert <calennert@gmail.com>
 Christian Himpel <chressie@googlemail.com> <chressie@gmail.com>
+Christine Hansmann <chhansmann@gmail.com>
 Christoph Hack <christoph@tux21b.org>
 Christopher Nielsen <m4dh4tt3r@gmail.com>
 Christopher Redden <christopher.redden@gmail.com>
 Gustav Paul <gustav.paul@gmail.com>
 Gustavo Niemeyer <gustavo@niemeyer.net> <n13m3y3r@gmail.com>
 Gwenael Treguier <gwenn.kahz@gmail.com>
+Han-Wen Nienhuys <hanwen@google.com>
 Harley Laue <losinggeneration@gmail.com>
 Hector Chu <hectorchu@gmail.com>
 Hong Ruiqi <hongruiqi@gmail.com>
 John Beisley <huin@google.com>
 John DeNero <denero@google.com>
 Jonathan Allie <jonallie@google.com>
+Jonathan Gold <jgold.bg@gmail.com>
 Jonathan Mark <jhmark@xenops.com> <jhmark000@gmail.com>
 Jonathan Pittman <jmpittman@google.com> <jonathan.mark.pittman@gmail.com>
 Jonathan Wills <runningwild@gmail.com>
 Kirklin McDonald <kirklin.mcdonald@gmail.com>
 Kyle Consalus <consalus@gmail.com>
 Kyle Lemons <kyle@kylelemons.net> <kevlar@google.com>
+L Campbell <unpantsu@gmail.com>
 Lai Jiangshan <eag0628@gmail.com>
 Larry Hosken <lahosken@golang.org>
 Lorenzo Stoakes <lstoakes@gmail.com>
 Michael Hoisie <hoisie@gmail.com>
 Michael Lewis <mikelikespie@gmail.com>
 Michael Shields <mshields@google.com>
+Michael Stapelberg <michael@stapelberg.de> <mstplbrg@googlemail.com>
 Michael T. Jones <mtj@google.com> <michael.jones@gmail.com>
 Michał Derkacz <ziutek@lnet.pl>
 Miek Gieben <miek@miek.nl> <remigius.gieben@gmail.com>
 Szabolcs Nagy <nsz@port70.net>
 Tarmigan Casebolt <tarmigan@gmail.com>
 Taru Karttunen <taruti@taruti.net>
+Thomas Alan Copeland <talan.copeland@gmail.com>
 Timo Savola <timo.savola@gmail.com>
 Tom Szymanski <tgs@google.com>
 Tor Andersson <tor.andersson@gmail.com>

File api/next.txt

 pkg crypto/x509, const ECDSAWithSHA256 SignatureAlgorithm
 pkg crypto/x509, const ECDSAWithSHA384 SignatureAlgorithm
 pkg crypto/x509, const ECDSAWithSHA512 SignatureAlgorithm
+pkg crypto/x509, const ExtKeyUsageIPSECEndSystem ExtKeyUsage
+pkg crypto/x509, const ExtKeyUsageIPSECTunnel ExtKeyUsage
+pkg crypto/x509, const ExtKeyUsageIPSECUser ExtKeyUsage
+pkg crypto/x509, const IncompatibleUsage InvalidReason
+pkg crypto/x509, type VerifyOptions struct, KeyUsages []ExtKeyUsage
 pkg debug/elf, type FileHeader struct, Entry uint64
+pkg encoding/json, method (*Decoder) UseNumber()
+pkg encoding/json, method (Number) Float64() (float64, error)
+pkg encoding/json, method (Number) Int64() (int64, error)
+pkg encoding/json, method (Number) String() string
+pkg encoding/json, type Number string
+pkg go/ast, func NewCommentMap(*token.FileSet, Node, []*CommentGroup) CommentMap
+pkg go/ast, method (CommentMap) Comments() []*CommentGroup
+pkg go/ast, method (CommentMap) Filter(Node) CommentMap
+pkg go/ast, method (CommentMap) String() string
+pkg go/ast, method (CommentMap) Update(Node) Node
+pkg go/ast, type CommentMap map[Node][]*CommentGroup
 pkg go/doc, var IllegalPrefixes []string
+pkg image, const YCbCrSubsampleRatio440 YCbCrSubsampleRatio
 pkg math/big, method (*Int) MarshalJSON() ([]byte, error)
 pkg math/big, method (*Int) UnmarshalJSON([]byte) error
 pkg net, method (*UnixConn) CloseRead() error
 pkg net, method (*UnixConn) CloseWrite() error
-pkg regexp/syntax, const ErrUnexpectedParen ErrorCode
+pkg net/http, method (*Request) PostFormValue(string) string
+pkg net/http, type Request struct, PostForm url.Values
+pkg net/textproto, func TrimBytes([]byte) []byte
+pkg net/textproto, func TrimString(string) string
 pkg syscall (darwin-386), const B0 ideal-int
 pkg syscall (darwin-386), const B110 ideal-int
 pkg syscall (darwin-386), const B115200 ideal-int
 pkg syscall (darwin-amd64-cgo), type Termios struct, Oflag uint64
 pkg syscall (darwin-amd64-cgo), type Termios struct, Ospeed uint64
 pkg syscall (darwin-amd64-cgo), type Termios struct, Pad_cgo_0 [4]byte
+pkg syscall (freebsd-amd64), func Syscall9(uintptr) (uintptr, Errno)
 pkg syscall (windows-386), const CREATE_NEW_PROCESS_GROUP ideal-int
 pkg syscall (windows-386), const CTRL_BREAK_EVENT ideal-int
 pkg syscall (windows-386), const CTRL_C_EVENT ideal-int
-pkg syscall (windows-386), func GetCurrentProcessId() uint32
 pkg syscall (windows-386), func Getsockopt(Handle, int32, int32, *byte, *int32) error
 pkg syscall (windows-386), type SysProcAttr struct, CreationFlags uint32
 pkg syscall (windows-amd64), const CREATE_NEW_PROCESS_GROUP ideal-int
 pkg syscall (windows-amd64), const CTRL_BREAK_EVENT ideal-int
 pkg syscall (windows-amd64), const CTRL_C_EVENT ideal-int
-pkg syscall (windows-amd64), func GetCurrentProcessId() uint32
 pkg syscall (windows-amd64), func Getsockopt(Handle, int32, int32, *byte, *int32) error
 pkg syscall (windows-amd64), type SysProcAttr struct, CreationFlags uint32

File doc/articles/slices_usage_and_internals.html

 d := []byte{'r', 'o', 'a', 'd'}
 e := d[2:] 
 // e == []byte{'a', 'd'}
-e[1] == 'm'
+e[1] = 'm'
 // e == []byte{'a', 'm'}
 // d == []byte{'r', 'o', 'a', 'm'}
 </pre>

File doc/codereview_with_mq.html

-<!--{
-	"Title": "Using Mercurial Queues with Codereview"
-}-->
-
-<h2 id="Introduction">Introduction</h2>
-
-<p>
-The Mercurial Queues extension (<code>mq</code>) provides a mechanism for
-managing patches on top of a Mercurial repository and is described in detail
-in Chapters
-<a href="http://hgbook.red-bean.com/read/managing-change-with-mercurial-queues.html">12</a>
-and <a href="http://hgbook.red-bean.com/read/advanced-uses-of-mercurial-queues.html">13</a>
-of <a href="http://hgbook.red-bean.com/read/">Mercurial: The Definitive Guide</a>.
-This document explains how to use <code>mq</code> in conjunction
-with the <code>codereview</code> Mercurial extension described in the
-instructions for <a href="contribute.html">contributing to the Go project</a>.
-It assumes you have read those instructions.
-</p>
-
-<h2>Configuration</h2>
-
-<p>
-To enable <code>mq</code> edit either <code>$HOME/.hgrc</code> (to enable it
-for all of your repositories) or <code>$GOROOT/.hg/hgrc</code> (to enable it for the
-repository at <code>$GOROOT</code>) to add:</p>
-
-<pre>
-[extensions]
-mq=
-</pre>
-
-<p>
-Since pulling, pushing, updating and committing while <code>mq</code> patches
-are applied can damage your repository or a remote one, add these lines to
-prevent that case: 
-</p>
-
-<pre>
-[hooks]
-# Prevent "hg pull" if MQ patches are applied.
-prechangegroup.mq-no-pull = ! hg qtop > /dev/null 2>&amp;1
-# Prevent "hg push" if MQ patches are applied.
-preoutgoing.mq-no-push = ! hg qtop > /dev/null 2>&amp;1
-# Prevent "hg update" if MQ patches are applied.
-preupdate.mq-no-update = ! hg qtop > /dev/null 2>&amp;1
-</pre>
-
-<h2>Making a change</h2>
-
-<p>
-The entire checked-out tree is writable and you can use <code>mq</code>,
-as documented in Chapter
-<a href="http://hgbook.red-bean.com/read/managing-change-with-mercurial-queues.html">12</a>
-of "The Guide",
-to implement your change as a single patch or a series of patches.
-
-</p>
-
-<p>When you are ready to send a change out for review, run</p>
-
-<pre>
-$ hg change
-</pre>
-
-<p>from any directory in your Go repository with all of the <code>mq</code> patches relevant to your
-change applied and then proceed as instructed in <a href="contribute.html">contributing
-to the Go project</a>.
-</p>
-
-<p>
-The change number reported by <code>hg change</code>, preceded by a <code>+</code>,
-can be used as an <code>mq</code> patch guard to assist in controlling which patches
-are applied as described in Chapter
-<a href="http://hgbook.red-bean.com/read/advanced-uses-of-mercurial-queues.html">13</a>
-of "The Guide".
-For example, the command:
-</p>
-
-<pre>
-for p in $(hg qapplied); do hg qguard $p +99999; done
-</pre>
-
-<p>
-will apply the guard <code>+99999</code> guard to all currently applied <code>mq</code>
-patches.
-</p>
-
-<h2>Synchronizing your client</h2>
-
-<p>While you were working, others might have submitted changes
-to the repository and, as explained in <a href="contribute.html">contributing
-to the Go project</a>, it is necessary to synchronize your repository using
-<code>hg sync</code>before sending your change list for review.
-Because <code>hg sync</code> runs <code>hg pull -u</code>,
-you should not run <code>hg sync</code> while <code>mq</code> patches are
-applied. Instead
-pop all your patches before running <code>hg sync</code> and reapply them after
-it has completed.
-</p>
-
-<p>
-When reapplying the patches, you may need to resolve conflicts
-as described in <a href="contribute.html">contributing to the Go project</a>.
-</p>
-
-<h2>Mailing the change for review</h2>
-
-<p>
-You should have all of the <code>mq</code> patches relevant to your
-change applied when you run <code>hg mail</code>.
-
-<h2>Submitting the change after the review</h2>
-
-If you are a committer, you should have all of the <code>mq</code> patches relevant to your
-change applied when you run <code>hg commit</code>.

File doc/contribute.html

 command.
 </p>
 
-<p>
-Mercurial power users: if you prefer to use the Mercurial Queues extension, see
-<a href="codereview_with_mq.html">Using Mercurial Queues with Codereview</a>.
-</p>
-
 <h3>Configure the extension</h3>
 
 <p>Edit <code>$GOROOT/.hg/hgrc</code> to add:</p>

File doc/debugging_with_gdb.html

 (for example, <code>go build -ldflags "-s" prog.go</code>).
 </p>
 
+<p>
+The code generated by the <code>gc</code> compiler includes inlining of
+function invocations and registerization of variables. These optimizations
+can sometimes make debugging with <code>gdb</code> harder. To disable them
+when debugging, pass the flags <code>-gcflags "-N -l"</code> to the
+<a href="/cmd/go"><code>go</code></a> command used to build the code being
+debugged.
+</p>
 
 <h3 id="Common_Operations">Common Operations</h3>
 

File doc/devel/release.html

 </p>
 
 <p>
+go1.0.2 (released 2012/06/13) was issued to fix two bugs in the implementation
+of maps using struct or array keys: 
+<a href="http://code.google.com/p/go/issues/detail?id=3695">issue 3695</a> and
+<a href="http://code.google.com/p/go/issues/detail?id=3573">issue 3573</a>.
+It also includes many minor code and documentation fixes.
+</p>
+
+<p>
 See the <a href="http://code.google.com/p/go/source/list?name=release-branch.go1">go1 release branch history</a> for the complete list of changes.
 </p>
 

File doc/go_spec.html

 <!--{
 	"Title": "The Go Programming Language Specification",
-	"Subtitle": "Version of June 4, 2012",
+	"Subtitle": "Version of June 27, 2012",
 	"Path": "/ref/spec"
 }-->
 
 [ ] need explicit language about the result type of operations
 [ ] should probably write something about evaluation order of statements even
 	though obvious
-[ ] review language on implicit dereferencing
 -->
 
 
 
 <p>
 A type determines the set of values and operations specific to values of that
-type.  A type may be specified by a (possibly qualified) <i>type name</i>
-(§<a href="#Qualified_identifiers">Qualified identifier</a>, §<a href="#Type_declarations">Type declarations</a>) or a <i>type literal</i>,
+type.  A type may be specified by a
+(possibly <a href="#Qualified_identifiers">qualified</a>) <i>type name</i>
+(§<a href="#Type_declarations">Type declarations</a>) or a <i>type literal</i>,
 which composes a new type from previously declared types.
 </p>
 
 <pre class="ebnf">
 Type      = TypeName | TypeLit | "(" Type ")" .
-TypeName  = QualifiedIdent .
+TypeName  = identifier | QualifiedIdent .
 TypeLit   = ArrayType | StructType | PointerType | FunctionType | InterfaceType |
 	    SliceType | MapType | ChannelType .
 </pre>
 <h3 id="Operands">Operands</h3>
 
 <p>
-Operands denote the elementary values in an expression.
+Operands denote the elementary values in an expression. An operand may be a
+literal, a (possibly <a href="#Qualified_identifiers">qualified</a>) identifier
+denoting a
+<a href="#Constant_declarations">constant</a>,
+<a href="#Variable_declarations">variable</a>, or
+<a href="#Function_declarations">function</a>,
+a <a href="#Method_expressions">method expression</a> yielding a function,
+or a parenthesized expression.
 </p>
 
 <pre class="ebnf">
-Operand    = Literal | QualifiedIdent | MethodExpr | "(" Expression ")" .
+Operand    = Literal | OperandName | MethodExpr | "(" Expression ")" .
 Literal    = BasicLit | CompositeLit | FunctionLit .
 BasicLit   = int_lit | float_lit | imaginary_lit | char_lit | string_lit .
-</pre>
-
+OperandName = identifier | QualifiedIdent.
+</pre>
 
 <h3 id="Qualified_identifiers">Qualified identifiers</h3>
 
 <p>
-A qualified identifier is a non-<a href="#Blank_identifier">blank</a> identifier
-qualified by a package name prefix.
+A qualified identifier is an identifier qualified with a package name prefix.
+Both the package name and the identifier must not be
+<a href="#Blank_identifier">blank</a>.
 </p>
 
 <pre class="ebnf">
-QualifiedIdent = [ PackageName "." ] identifier .
+QualifiedIdent = PackageName "." identifier .
 </pre>
 
 <p>
 m["foo"]
 s[i : j + 1]
 obj.color
-math.Sin
 f.p[i].x()
 </pre>
 
 <h3 id="Selectors">Selectors</h3>
 
 <p>
-A primary expression of the form
+For a <a href="#Primary_expressions">primary expression</a> <code>x</code>
+that is not a <a href="#Package_clause">package name</a>, the
+<i>selector expression</i>
 </p>
 
 <pre>
 </pre>
 
 <p>
-denotes the field or method <code>f</code> of the value denoted by <code>x</code>
-(or sometimes <code>*x</code>; see below). The identifier <code>f</code>
-is called the (field or method)
-<i>selector</i>; it must not be the <a href="#Blank_identifier">blank identifier</a>.
-The type of the expression is the type of <code>f</code>.
-</p>
+denotes the field or method <code>f</code> of the value <code>x</code>
+(or sometimes <code>*x</code>; see below).
+The identifier <code>f</code> is called the (field or method) <i>selector</i>;
+it must not be the <a href="#Blank_identifier">blank identifier</a>.
+The type of the selector expression is the type of <code>f</code>.
+If <code>x</code> is a package name, see the section on
+<a href="#Qualified_identifiers">qualified identifiers</a>.
+</p>
+
 <p>
 A selector <code>f</code> may denote a field or method <code>f</code> of
 a type <code>T</code>, or it may refer
-to a field or method <code>f</code> of a nested anonymous field of
-<code>T</code>.
+to a field or method <code>f</code> of a nested
+<a href="#Struct_types">anonymous field</a> of <code>T</code>.
 The number of anonymous fields traversed
 to reach <code>f</code> is called its <i>depth</i> in <code>T</code>.
 The depth of a field or method <code>f</code>
 an anonymous field <code>A</code> in <code>T</code> is the
 depth of <code>f</code> in <code>A</code> plus one.
 </p>
+
 <p>
 The following rules apply to selectors:
 </p>
+
 <ol>
 <li>
 For a value <code>x</code> of type <code>T</code> or <code>*T</code>
 with shallowest depth, the selector expression is illegal.
 </li>
 <li>
-For a variable <code>x</code> of type <code>I</code>
-where <code>I</code> is an interface type,
-<code>x.f</code> denotes the actual method with name <code>f</code> of the value assigned
-to <code>x</code> if there is such a method.
-If no value or <code>nil</code> was assigned to <code>x</code>, <code>x.f</code> is illegal.
+For a variable <code>x</code> of type <code>I</code> where <code>I</code>
+is an interface type, <code>x.f</code> denotes the actual method with name
+<code>f</code> of the value assigned to <code>x</code>.
+If there is no method with name <code>f</code> in the
+<a href="#Method_sets">method set</a> of <code>I</code>, the selector
+expression is illegal.
 </li>
 <li>
 In all other cases, <code>x.f</code> is illegal.
 </li>
+<li>
+If <code>x</code> is of pointer or interface type and has the value
+<code>nil</code>, assigning to, evaluating, or calling <code>x.f</code>
+causes a <a href="#Run_time_panics">run-time panic</a>.
+</i>
 </ol>
-<p>
-Selectors automatically dereference pointers to structs.
+
+<p>
+Selectors automatically <a href="#Address_operators">dereference</a>
+pointers to structs.
 If <code>x</code> is a pointer to a struct, <code>x.y</code>
 is shorthand for <code>(*x).y</code>; if the field <code>y</code>
 is also a pointer to a struct, <code>x.y.z</code> is shorthand
 where <code>A</code> is also a struct type,
 <code>x.f</code> is a shortcut for <code>(*x.A).f</code>.
 </p>
+
 <p>
 For example, given the declarations:
 </p>
 from the channel <code>ch</code>. The type of the value is the element type of
 the channel. The expression blocks until a value is available.
 Receiving from a <code>nil</code> channel blocks forever.
+Receiving from a <a href="#Close">closed</a> channel always succeeds,
+immediately returning the element type's <a href="#The_zero_value">zero
+value</a>.
 </p>
 
 <pre>
 </pre>
 
 <p>
-yields an additional result.
-The boolean variable <code>ok</code> indicates whether
-the received value was sent on the channel (<code>true</code>)
-or is a <a href="#The_zero_value">zero value</a> returned
-because the channel is closed and empty (<code>false</code>).
+yields an additional result of type <code>bool</code> reporting whether the
+communication succeeded. The value of <code>ok</code> is <code>true</code>
+if the value received was delivered by a successful send operation to the
+channel, or <code>false</code> if it is a zero value generated because the
+channel is closed and empty.
 </p>
 
 <!--

File doc/root.html

 
 <div id="video">
 <div class="rootHeading">Featured video</div>
-<a class="title" href="http://www.youtube.com/watch?v=Mo1YKpIF1PQ">Building integrated apps on Google's cloud platform with Go</a>
-<iframe width="415" height="241" src="http://www.youtube.com/embed/Mo1YKpIF1PQ" frameborder="0" allowfullscreen></iframe>
+<iframe width="415" height="241" src="http://www.youtube.com/embed/ytEkHepK08c" frameborder="0" allowfullscreen></iframe>
 </div>
 
 </div>

File misc/cgo/test/issue3741.go

+// Copyright 2012 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+import "C"
+
+//export exportSliceIn
+func exportSliceIn(s []byte) bool {
+	return len(s) == cap(s)
+}
+
+//export exportSliceOut
+func exportSliceOut() []byte {
+	return []byte{1}
+}
+
+//export exportSliceInOut
+func exportSliceInOut(s []byte) []byte {
+	return s
+}

File misc/chrome/gophertool/manifest.json

 {
   "name": "Hacking Gopher",
   "version": "1.0",
+  "manifest_version": 2,
   "description": "Go Hacking utility",
-  "background_page": "background.html",
+  "background": {
+    "page": "background.html"
+  },
   "browser_action": {
     "default_icon": "gopher.png",
     "popup": "popup.html"

File misc/emacs/go-mode.el

 	(remove-text-properties
 	 b (min go-mode-mark-string-end (point-max)) '(go-mode-comment nil))
 	(setq go-mode-mark-comment-end b)))
-    
+
     (when (< b go-mode-mark-nesting-end)
       (remove-text-properties b (min go-mode-mark-nesting-end (point-max)) '(go-mode-nesting nil))
       (setq go-mode-mark-nesting-end b))))
 	    ;; Back up to the last known state.
 	    (let ((last-cs
 		   (and (> go-mode-mark-cs-end 1)
-			(get-text-property (1- go-mode-mark-cs-end) 
+			(get-text-property (1- go-mode-mark-cs-end)
 					   'go-mode-cs))))
 	      (if last-cs
 		  (car last-cs)
 	    ;; Back up to the last known state.
 	    (let ((last-comment
 		   (and (> go-mode-mark-comment-end 1)
-			(get-text-property (1- go-mode-mark-comment-end) 
+			(get-text-property (1- go-mode-mark-comment-end)
 					   'go-mode-comment))))
 	      (if last-comment
 		  (car last-comment)
 	    ;; Back up to the last known state.
 	    (let ((last-cs
 		   (and (> go-mode-mark-string-end 1)
-			(get-text-property (1- go-mode-mark-string-end) 
+			(get-text-property (1- go-mode-mark-string-end)
 					   'go-mode-string))))
 	      (if last-cs
 		  (car last-cs)
        (while (< pos end)
 	 (goto-char pos)
 	 (let ((cs-end			; end of the text property
-		(cond 
+		(cond
 		 ((looking-at "\"")
 		  (goto-char (1+ pos))
 		  (if (looking-at "[^\"\n\\\\]*\\(\\\\.[^\"\n\\\\]*\\)*\"")
 
 (defun gofmt-apply-patch (filename srcbuf patchbuf)
   (require 'diff-mode)
-  ;; apply all the patch hunks and restore the mark and point
+  ;; apply all the patch hunks
   (with-current-buffer patchbuf
-    (let ((filename (file-name-nondirectory filename))
-          (min (point-min)))
-      (replace-string gofmt-stdin-tag  filename nil min (point-max))
-      (replace-regexp "^--- /tmp/gofmt[0-9]*" (concat "--- /tmp/" filename)
-                      nil min (point-max)))
+    (goto-char (point-min))
+    ;; The .* is for TMPDIR, but to avoid dealing with TMPDIR
+    ;; having a trailing / or not, it's easier to just search for .*
+    ;; especially as we're only replacing the first instance.
+    (if (re-search-forward "^--- \\(.*/gofmt[0-9]*\\)" nil t)
+      (replace-match filename nil nil nil 1))
     (condition-case nil
         (while t
           (diff-hunk-next)
 (defun gofmt-process-errors (filename errbuf)
   ;; Convert the gofmt stderr to something understood by the compilation mode.
   (with-current-buffer errbuf
-    (beginning-of-buffer)
+    (goto-char (point-min))
     (insert "gofmt errors:\n")
-    (replace-string gofmt-stdin-tag (file-name-nondirectory filename) nil (point-min) (point-max))
+    (if (search-forward gofmt-stdin-tag nil t)
+      (replace-match (file-name-nondirectory filename) nil t))
     (display-buffer errbuf)
     (compilation-mode)))
 

File src/cmd/5g/cgen.c

 		} else
 			cgen_slice(n, res);
 		return;
+	case OEFACE:
+		if (res->op != ONAME || !res->addable) {
+			tempname(&n1, n->type);
+			cgen_eface(n, &n1);
+			cgen(&n1, res);
+		} else
+			cgen_eface(n, res);
+		return;
 	}
 
 	while(n->op == OCONVNOP)
 		agen(&n1, res);
 		break;
 
+	case OEFACE:
+		tempname(&n1, n->type);
+		cgen_eface(n, &n1);
+		agen(&n1, res);
+		break;
+
 	case OINDEX:
 		p2 = nil;  // to be patched to panicindex.
 		w = n->type->width;

File src/cmd/5g/gsubr.c

 }
 
 void
-ggloblsym(Sym *s, int32 width, int dupok)
+ggloblsym(Sym *s, int32 width, int dupok, int rodata)
 {
 	Prog *p;
 
 	p->to.name = D_NONE;
 	p->to.offset = width;
 	if(dupok)
-		p->reg = DUPOK;
-	p->reg |= RODATA;
+		p->reg |= DUPOK;
+	if(rodata)
+		p->reg |= RODATA;
 }
 
 int

File src/cmd/6g/cgen.c

 		} else
 			cgen_slice(n, res);
 		goto ret;
+	case OEFACE:
+		if (res->op != ONAME || !res->addable) {
+			tempname(&n1, n->type);
+			cgen_eface(n, &n1);
+			cgen(&n1, res);
+		} else
+			cgen_eface(n, res);
+		goto ret;
 	}
 
 	if(n->ullman >= UINF) {
 		agen(&n1, res);
 		break;
 
+	case OEFACE:
+		tempname(&n1, n->type);
+		cgen_eface(n, &n1);
+		agen(&n1, res);
+		break;
+
 	case OINDEX:
 		w = n->type->width;
 		if(nr->addable)

File src/cmd/6g/gsubr.c

 }
 
 void
-ggloblsym(Sym *s, int32 width, int dupok)
+ggloblsym(Sym *s, int32 width, int dupok, int rodata)
 {
 	Prog *p;
 
 	p->to.index = D_NONE;
 	p->to.offset = width;
 	if(dupok)
-		p->from.scale = DUPOK;
-	p->from.scale |= RODATA;
+		p->from.scale |= DUPOK;
+	if(rodata)
+		p->from.scale |= RODATA;
 }
 
 int

File src/cmd/8g/cgen.c

 		} else
 			cgen_slice(n, res);
 		return;
+	case OEFACE:
+		if (res->op != ONAME || !res->addable) {
+			tempname(&n1, n->type);
+			cgen_eface(n, &n1);
+			cgen(&n1, res);
+		} else
+			cgen_eface(n, res);
+		return;
 	}
 
 	while(n->op == OCONVNOP)
 		agen(&n1, res);
 		break;
 
+	case OEFACE:
+		tempname(&n1, n->type);
+		cgen_eface(n, &n1);
+		agen(&n1, res);
+		break;
+
 	case OINDEX:
 		p2 = nil;  // to be patched to panicindex.
 		w = n->type->width;

File src/cmd/8g/gsubr.c

 }
 
 void
-ggloblsym(Sym *s, int32 width, int dupok)
+ggloblsym(Sym *s, int32 width, int dupok, int rodata)
 {
 	Prog *p;
 
 	p->to.index = D_NONE;
 	p->to.offset = width;
 	if(dupok)
-		p->from.scale = DUPOK;
-	p->from.scale |= RODATA;
+		p->from.scale |= DUPOK;
+	if(rodata)
+		p->from.scale |= RODATA;
 }
 
 int

File src/cmd/cgo/out.go

 typedef void *GoMap;
 typedef void *GoChan;
 typedef struct { void *t; void *v; } GoInterface;
+typedef struct { void *data; int len; int cap; } GoSlice;
 `

File src/cmd/dist/windows.c

 	return bstr(&b);  // leak but we're dying anyway
 }
 
+static void
+errprintf(char *fmt, ...) {
+	va_list arg;
+	char *p;
+	DWORD n, w;
+
+	va_start(arg, fmt);
+	n = vsnprintf(NULL, 0, fmt, arg);
+	p = xmalloc(n+1);
+	vsnprintf(p, n+1, fmt, arg);
+	va_end(arg);
+	w = 0;
+	WriteFile(GetStdHandle(STD_ERROR_HANDLE), p, n, &w, 0);
+	xfree(p);
+}
+
 void
 xgetenv(Buf *b, char *name)
 {
 	vsnprintf(buf1, sizeof buf1, msg, arg);
 	va_end(arg);
 
-	xprintf("go tool dist: %s\n", buf1);
+	errprintf("go tool dist: %s\n", buf1);
 	
 	bgwait();
 	ExitProcess(1);

File src/cmd/gc/builtin.c

 	"func @\"\".convI2E(@\"\".elem any) (@\"\".ret any)\n"
 	"func @\"\".convI2I(@\"\".typ *byte, @\"\".elem any) (@\"\".ret any)\n"
 	"func @\"\".convT2E(@\"\".typ *byte, @\"\".elem any) (@\"\".ret any)\n"
-	"func @\"\".convT2I(@\"\".typ *byte, @\"\".typ2 *byte, @\"\".elem any) (@\"\".ret any)\n"
+	"func @\"\".convT2I(@\"\".typ *byte, @\"\".typ2 *byte, @\"\".cache **byte, @\"\".elem any) (@\"\".ret any)\n"
 	"func @\"\".assertE2E(@\"\".typ *byte, @\"\".iface any) (@\"\".ret any)\n"
 	"func @\"\".assertE2E2(@\"\".typ *byte, @\"\".iface any) (@\"\".ret any, @\"\".ok bool)\n"
 	"func @\"\".assertE2I(@\"\".typ *byte, @\"\".iface any) (@\"\".ret any)\n"

File src/cmd/gc/const.c

 		}
 		n->type = t;
 		return;
+	case OCOM:
 	case ONOT:
 		defaultlit(&n->left, t);
 		n->type = n->left->type;
 		return;
 	default:
-		if(n->left == N) {
+		if(n->left == N || n->right == N) {
 			dump("defaultlit", n);
 			fatal("defaultlit");
 		}

File src/cmd/gc/gen.c

 	;
 }
 
+/*
+ * generate:
+ *	res = iface{typ, data}
+ * n->left is typ
+ * n->right is data
+ */
+void
+cgen_eface(Node *n, Node *res)
+{
+	Node dst;
+	dst = *res;
+	dst.type = types[tptr];
+	cgen(n->left, &dst);
+	dst.xoffset += widthptr;
+	cgen(n->right, &dst);
+}
 
 /*
  * generate:
  * n->left is s
  * n->list is (cap(s)-lo(TUINT32), hi-lo(TUINT32)[, lo*width(TUINTPTR)])
  * caller (cgen) guarantees res is an addable ONAME.
- *
  */
 void
 cgen_slice(Node *n, Node *res)
 {
 	Node src, dst, *cap, *len, *offs, *add;
 
-//	print("cgen_slice: %N = %+N\n", res, n);
-
 	cap = n->list->n;
 	len = n->list->next->n;
 	offs = N;

File src/cmd/gc/go.h

 	ODDD,
 	ODDDARG,
 	OINLCALL,	// intermediary representation of an inlined call
+	OEFACE,	// itable and data words of empty-interface value
 	OITAB,	// itable word of interface value
 
 	// for back ends
 EXTERN	Pkg*	structpkg;	// package that declared struct, during import
 EXTERN	Pkg*	builtinpkg;	// fake package for builtins
 EXTERN	Pkg*	gostringpkg;	// fake pkg for Go strings
+EXTERN	Pkg*	itabpkg;	// fake pkg for itab cache
 EXTERN	Pkg*	runtimepkg;	// package runtime
 EXTERN	Pkg*	stringpkg;	// fake package for C strings
 EXTERN	Pkg*	typepkg;	// fake package for runtime type info
 void	addrescapes(Node *n);
 void	cgen_as(Node *nl, Node *nr);
 void	cgen_callmeth(Node *n, int proc);
+void	cgen_eface(Node* n, Node* res);
 void	cgen_slice(Node* n, Node* res);
 void	clearlabels(void);
 void	checklabels(void);
 void	gdatastring(Node*, Strlit*);
 void	genembedtramp(Type*, Type*, Sym*, int iface);
 void	ggloblnod(Node *nam, int32 width);
-void	ggloblsym(Sym *s, int32 width, int dupok);
+void	ggloblsym(Sym *s, int32 width, int dupok, int rodata);
 Prog*	gjmp(Prog*);
 void	gused(Node*);
 int	isfat(Type*);

File src/cmd/gc/lex.c

 	gostringpkg->name = "go.string";
 	gostringpkg->prefix = "go.string";	// not go%2estring
 
+	itabpkg = mkpkg(strlit("go.itab"));
+	itabpkg->name = "go.itab";
+	itabpkg->prefix = "go.itab";	// not go%2eitab
+
 	runtimepkg = mkpkg(strlit("runtime"));
 	runtimepkg->name = "runtime";
 

File src/cmd/gc/obj.c

 	}
 	off = duint8(sym, off, 0);  // terminating NUL for runtime
 	off = (off+widthptr-1)&~(widthptr-1);  // round to pointer alignment
-	ggloblsym(sym, off, 1);
+	ggloblsym(sym, off, 1, 1);
 
 	return sym;	
 }

File src/cmd/gc/reflect.c

 	p->pathsym = n->sym;
 
 	gdatastring(n, p->path);
-	ggloblsym(n->sym, types[TSTRING]->width, 1);
+	ggloblsym(n->sym, types[TSTRING]->width, 1, 1);
 }
 
 static int
 		break;
 	}
 	ot = dextratype(s, ot, t, xt);
-	ggloblsym(s, ot, dupok);
+	ggloblsym(s, ot, dupok, 1);
 	return s;
 }
 
 		break;
 	}
 
-	ggloblsym(s, ot, 1);
+	ggloblsym(s, ot, 1, 1);
 	return s;
 }
 

File src/cmd/gc/runtime.go

 func convI2E(elem any) (ret any)
 func convI2I(typ *byte, elem any) (ret any)
 func convT2E(typ *byte, elem any) (ret any)
-func convT2I(typ *byte, typ2 *byte, elem any) (ret any)
+func convT2I(typ *byte, typ2 *byte, cache **byte, elem any) (ret any)
 
 // interface type assertions  x.(T)
 func assertE2E(typ *byte, iface any) (ret any)

File src/cmd/gc/walk.c

 	int64 v;
 	int32 lno;
 	Node *n, *fn;
+	Sym *sym;
 	char buf[100], *p;
 
 	n = *np;
 		walkexpr(&n->left, init);
 		goto ret;
 
+	case OEFACE:
+		walkexpr(&n->left, init);
+		walkexpr(&n->right, init);
+		goto ret;
+
 	case OITAB:
 		walkexpr(&n->left, init);
 		goto ret;
 		goto ret;
 
 	case OCONVIFACE:
+		walkexpr(&n->left, init);
+
+		// Optimize convT2E as a two-word copy when T is uintptr-shaped.
+		if(!isinter(n->left->type) && isnilinter(n->type) &&
+		   (n->left->type->width == widthptr) &&
+		   isint[simsimtype(n->left->type)]) {
+			l = nod(OEFACE, typename(n->left->type), n->left);
+			l->type = n->type;
+			l->typecheck = n->typecheck;
+			n = l;
+			goto ret;
+		}
+
 		// Build name of function: convI2E etc.
 		// Not all names are possible
 		// (e.g., we'll never generate convE2E or convE2I).
-		walkexpr(&n->left, init);
 		strcpy(buf, "conv");
 		p = buf+strlen(buf);
 		if(isnilinter(n->left->type))
 			ll = list(ll, typename(n->left->type));
 		if(!isnilinter(n->type))
 			ll = list(ll, typename(n->type));
+		if(!isinter(n->left->type) && !isnilinter(n->type)){
+			sym = pkglookup(smprint("%-T.%-T", n->left->type, n->type), itabpkg);
+			if(sym->def == N) {
+				l = nod(ONAME, N, N);
+				l->sym = sym;
+				l->type = ptrto(types[TUINT8]);
+				l->addable = 1;
+				l->class = PEXTERN;
+				l->xoffset = 0;
+				sym->def = l;
+				ggloblsym(sym, widthptr, 1, 0);
+			}
+			l = nod(OADDR, sym->def, N);
+			l->addable = 1;
+			ll = list(ll, l);
+		}
 		ll = list(ll, n->left);
 		argtype(fn, n->left->type);
 		argtype(fn, n->type);

File src/cmd/go/http.go

 	"net/url"
 )
 
+// httpClient is the default HTTP client, but a variable so it can be
+// changed by tests, without modifying http.DefaultClient.
+var httpClient = http.DefaultClient
+
 // httpGET returns the data from an HTTP GET request for the given URL.
 func httpGET(url string) ([]byte, error) {
-	resp, err := http.Get(url)
+	resp, err := httpClient.Get(url)
 	if err != nil {
 		return nil, err
 	}
 	return b, nil
 }
 
-// httpClient is the default HTTP client, but a variable so it can be
-// changed by tests, without modifying http.DefaultClient.
-var httpClient = http.DefaultClient
-
 // httpsOrHTTP returns the body of either the importPath's
 // https resource or, if unavailable, the http resource.
 func httpsOrHTTP(importPath string) (urlStr string, body io.ReadCloser, err error) {

File src/cmd/godoc/godoc.go

 	return false
 }
 
+// packageExports is a local implementation of ast.PackageExports
+// which correctly updates each package file's comment list.
+// (The ast.PackageExports signature is frozen, hence the local
+// implementation).
+//
+func packageExports(fset *token.FileSet, pkg *ast.Package) {
+	for _, src := range pkg.Files {
+		cmap := ast.NewCommentMap(fset, src, src.Comments)
+		ast.FileExports(src)
+		src.Comments = cmap.Filter(src).Comments()
+	}
+}
+
 // getPageInfo returns the PageInfo for a package directory abspath. If the
 // parameter genAST is set, an AST containing only the package exports is
 // computed (PageInfo.PAst), otherwise package documentation (PageInfo.Doc)
 			// TODO(gri) Consider eliminating export filtering in this mode,
 			//           or perhaps eliminating the mode altogether.
 			if mode&noFiltering == 0 {
-				ast.PackageExports(pkg)
+				packageExports(fset, pkg)
 			}
-			past = ast.MergePackageFiles(pkg, ast.FilterUnassociatedComments)
+			past = ast.MergePackageFiles(pkg, 0)
 		}
 	}
 

File src/cmd/godoc/main.go

 	"fmt"
 	"go/ast"
 	"go/build"
+	"go/printer"
 	"io"
 	"log"
 	"net/http"
 		filter := func(s string) bool { return rx.MatchString(s) }
 		switch {
 		case info.PAst != nil:
+			cmap := ast.NewCommentMap(info.FSet, info.PAst, info.PAst.Comments)
 			ast.FilterFile(info.PAst, filter)
 			// Special case: Don't use templates for printing
 			// so we only get the filtered declarations without
 			// package clause or extra whitespace.
 			for i, d := range info.PAst.Decls {
+				// determine the comments associated with d only
+				comments := cmap.Filter(d).Comments()
+				cn := &printer.CommentedNode{Node: d, Comments: comments}
 				if i > 0 {
 					fmt.Println()
 				}
 				if *html {
 					var buf bytes.Buffer
-					writeNode(&buf, info.FSet, d)
+					writeNode(&buf, info.FSet, cn)
 					FormatText(os.Stdout, buf.Bytes(), -1, true, "", nil)
 				} else {
-					writeNode(os.Stdout, info.FSet, d)
+					writeNode(os.Stdout, info.FSet, cn)
 				}
 				fmt.Println()
 			}

File src/cmd/gofmt/gofmt_test.go

 	}
 }
 
-// TODO(gri) Add more test cases!
 var tests = []struct {
 	in, flags string
 }{
 	{"testdata/rewrite2.input", "-r=int->bool"},
 	{"testdata/rewrite3.input", "-r=x->x"},
 	{"testdata/rewrite4.input", "-r=(x)->x"},
+	{"testdata/rewrite5.input", "-r=x+x->2*x"},
 	{"testdata/stdin*.input", "-stdin"},
 	{"testdata/comments.input", ""},
 	{"testdata/import.input", ""},

File src/cmd/gofmt/rewrite.go

 
 // rewriteFile applies the rewrite rule 'pattern -> replace' to an entire file.
 func rewriteFile(pattern, replace ast.Expr, p *ast.File) *ast.File {
+	cmap := ast.NewCommentMap(fileSet, p, p.Comments)
 	m := make(map[string]reflect.Value)
 	pat := reflect.ValueOf(pattern)
 	repl := reflect.ValueOf(replace)
 		}
 		return val
 	}
-	return apply(f, reflect.ValueOf(p)).Interface().(*ast.File)
+	r := apply(f, reflect.ValueOf(p)).Interface().(*ast.File)
+	r.Comments = cmap.Filter(r).Comments() // recreate comments list
+	return r
 }
 
 // setValue is a wrapper for x.SetValue(y); it protects

File src/cmd/gofmt/testdata/rewrite5.golden

+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Rewriting of expressions containing nodes with associated comments to
+// expressions without those nodes must also eliminate the associated
+// comments.
+
+package p
+
+func f(x int) int {
+	_ = 2 * x // this comment remains in the rewrite
+	_ = 2 * x
+	return 2 * x
+}

File src/cmd/gofmt/testdata/rewrite5.input

+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Rewriting of expressions containing nodes with associated comments to
+// expressions without those nodes must also eliminate the associated
+// comments.
+
+package p
+
+func f(x int) int {
+	_ = x + x // this comment remains in the rewrite
+	_ = x /* this comment must not be in the rewrite */ + x
+	return x /* this comment must not be in the rewrite */ + x
+}

File src/pkg/bytes/bytes.go

 // ToUpper returns a copy of the byte array s with all Unicode letters mapped to their upper case.
 func ToUpper(s []byte) []byte { return Map(unicode.ToUpper, s) }
 
-// ToUpper returns a copy of the byte array s with all Unicode letters mapped to their lower case.
+// ToLower returns a copy of the byte array s with all Unicode letters mapped to their lower case.
 func ToLower(s []byte) []byte { return Map(unicode.ToLower, s) }
 
 // ToTitle returns a copy of the byte array s with all Unicode letters mapped to their title case.

File src/pkg/crypto/elliptic/elliptic.go

 	return p384
 }
 
-// P256 returns a Curve which implements P-521 (see FIPS 186-3, section D.2.5)
+// P521 returns a Curve which implements P-521 (see FIPS 186-3, section D.2.5)
 func P521() Curve {
 	initonce.Do(initAll)
 	return p521

File src/pkg/crypto/x509/verify.go

 	// TooManyIntermediates results when a path length constraint is
 	// violated.
 	TooManyIntermediates
+	// IncompatibleUsage results when the certificate's key usage indicates
+	// that it may only be used for a different purpose.
+	IncompatibleUsage
 )
 
 // CertificateInvalidError results when an odd error occurs. Users of this
 		return "x509: a root or intermediate certificate is not authorized to sign in this domain"
 	case TooManyIntermediates:
 		return "x509: too many intermediates for path length constraint"
+	case IncompatibleUsage:
+		return "x509: certificate specifies an incompatible key usage"
 	}
 	return "x509: unknown error"
 }
 	Intermediates *CertPool
 	Roots         *CertPool // if nil, the system roots are used
 	CurrentTime   time.Time // if zero, the current time is used
+	// KeyUsage specifies which Extended Key Usage values are acceptable.
+	// An empty list means ExtKeyUsageServerAuth. Key usage is considered a
+	// constraint down the chain which mirrors Windows CryptoAPI behaviour,
+	// but not the spec. To accept any key usage, include ExtKeyUsageAny.
+	KeyUsages []ExtKeyUsage
 }
 
 const (
 		}
 	}
 
-	return c.buildChains(make(map[int][][]*Certificate), []*Certificate{c}, &opts)
+	candidateChains, err := c.buildChains(make(map[int][][]*Certificate), []*Certificate{c}, &opts)
+	if err != nil {
+		return
+	}
+
+	keyUsages := opts.KeyUsages
+	if len(keyUsages) == 0 {
+		keyUsages = []ExtKeyUsage{ExtKeyUsageServerAuth}
+	}
+
+	// If any key usage is acceptable then we're done.
+	for _, usage := range keyUsages {
+		if usage == ExtKeyUsageAny {
+			chains = candidateChains
+			return
+		}
+	}
+
+	for _, candidate := range candidateChains {
+		if checkChainForKeyUsage(candidate, keyUsages) {
+			chains = append(chains, candidate)
+		}
+	}
+
+	if len(chains) == 0 {
+		err = CertificateInvalidError{c, IncompatibleUsage}
+	}
+
+	return
 }
 
 func appendToFreshChain(chain []*Certificate, cert *Certificate) []*Certificate {
 
 	return HostnameError{c, h}
 }
+
+func checkChainForKeyUsage(chain []*Certificate, keyUsages []ExtKeyUsage) bool {
+	usages := make([]ExtKeyUsage, len(keyUsages))
+	copy(usages, keyUsages)
+
+	if len(chain) == 0 {
+		return false
+	}
+
+	usagesRemaining := len(usages)
+
+	// We walk down the list and cross out any usages that aren't supported
+	// by each certificate. If we cross out all the usages, then the chain
+	// is unacceptable.
+
+	for i := len(chain) - 1; i >= 0; i-- {
+		cert := chain[i]
+		if len(cert.ExtKeyUsage) == 0 && len(cert.UnknownExtKeyUsage) == 0 {
+			// The certificate doesn't have any extended key usage specified.
+			continue
+		}
+
+		for _, usage := range cert.ExtKeyUsage {
+			if usage == ExtKeyUsageAny {
+				// The certificate is explicitly good for any usage.
+				continue
+			}
+		}
+
+		const invalidUsage ExtKeyUsage = -1
+
+	NextRequestedUsage:
+		for i, requestedUsage := range usages {
+			if requestedUsage == invalidUsage {
+				continue
+			}
+
+			for _, usage := range cert.ExtKeyUsage {
+				if requestedUsage == usage {
+					continue NextRequestedUsage
+				}
+			}
+
+			usages[i] = invalidUsage
+			usagesRemaining--
+			if usagesRemaining == 0 {
+				return false
+			}
+		}
+	}
+
+	return true
+}

File src/pkg/crypto/x509/verify_test.go

 	currentTime   int64
 	dnsName       string
 	systemSkip    bool
+	keyUsages     []ExtKeyUsage
 
 	errorCallback  func(*testing.T, int, error) bool
 	expectedChains [][]string
 			{"dnssec-exp", "StartCom Class 1", "StartCom Certification Authority", "StartCom Certification Authority"},
 		},
 	},
+	{
+		// The default configuration should reject an S/MIME chain.
+		leaf:        smimeLeaf,
+		roots:       []string{smimeIntermediate},
+		currentTime: 1339436154,
+
+		// Key usage not implemented for Windows yet.
+		systemSkip:    true,
+		errorCallback: expectUsageError,
+	},
+	{
+		leaf:        smimeLeaf,
+		roots:       []string{smimeIntermediate},
+		currentTime: 1339436154,
+		keyUsages:   []ExtKeyUsage{ExtKeyUsageServerAuth},
+
+		// Key usage not implemented for Windows yet.
+		systemSkip:    true,
+		errorCallback: expectUsageError,
+	},
+	{
+		leaf:        smimeLeaf,
+		roots:       []string{smimeIntermediate},
+		currentTime: 1339436154,
+		keyUsages:   []ExtKeyUsage{ExtKeyUsageEmailProtection},
+
+		// Key usage not implemented for Windows yet.
+		systemSkip: true,
+		expectedChains: [][]string{
+			{"Ryan Hurst", "GlobalSign PersonalSign 2 CA - G2"},
+		},
+	},
 }
 
 func expectHostnameError(t *testing.T, i int, err error) (ok bool) {
 	return true
 }
 
+func expectUsageError(t *testing.T, i int, err error) (ok bool) {
+	if inval, ok := err.(CertificateInvalidError); !ok || inval.Reason != IncompatibleUsage {
+		t.Errorf("#%d: error was not IncompatibleUsage: %s", i, err)
+		return false
+	}
+	return true
+}
+
 func expectAuthorityUnknown(t *testing.T, i int, err error) (ok bool) {
 	if _, ok := err.(UnknownAuthorityError); !ok {
 		t.Errorf("#%d: error was not UnknownAuthorityError: %s", i, err)
 			Intermediates: NewCertPool(),
 			DNSName:       test.dnsName,
 			CurrentTime:   time.Unix(test.currentTime, 0),
+			KeyUsages:     test.keyUsages,
 		}
 
 		if !useSystemRoots {
 um0ABj6y6koQOdjQK/W/7HW/lwLFCRsI3FU34oH7N4RDYiDK51ZLZer+bMEkkySh
 NOsF/5oirpt9P/FlUQqmMGqz9IgcgA38corog14=
 -----END CERTIFICATE-----`
+
+const smimeLeaf = `-----BEGIN CERTIFICATE-----
+MIIFBjCCA+6gAwIBAgISESFvrjT8XcJTEe6rBlPptILlMA0GCSqGSIb3DQEBBQUA
+MFQxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMSowKAYD
+VQQDEyFHbG9iYWxTaWduIFBlcnNvbmFsU2lnbiAyIENBIC0gRzIwHhcNMTIwMTIz
+MTYzNjU5WhcNMTUwMTIzMTYzNjU5WjCBlDELMAkGA1UEBhMCVVMxFjAUBgNVBAgT
+DU5ldyBIYW1zcGhpcmUxEzARBgNVBAcTClBvcnRzbW91dGgxGTAXBgNVBAoTEEds
+b2JhbFNpZ24sIEluYy4xEzARBgNVBAMTClJ5YW4gSHVyc3QxKDAmBgkqhkiG9w0B
+CQEWGXJ5YW4uaHVyc3RAZ2xvYmFsc2lnbi5jb20wggEiMA0GCSqGSIb3DQEBAQUA
+A4IBDwAwggEKAoIBAQC4ASSTvavmsFQAob60ukSSwOAL9nT/s99ltNUCAf5fPH5j
+NceMKxaQse2miOmRRIXaykcq1p/TbI70Ztce38r2mbOwqDHHPVi13GxJEyUXWgaR
+BteDMu5OGyWNG1kchVsGWpbstT0Z4v0md5m1BYFnxB20ebJyOR2lXDxsFK28nnKV
++5eMj76U8BpPQ4SCH7yTMG6y0XXsB3cCrBKr2o3TOYgEKv+oNnbaoMt3UxMt9nSf
+9jyIshjqfnT5Aew3CUNMatO55g5FXXdIukAweg1YSb1ls05qW3sW00T3d7dQs9/7
+NuxCg/A2elmVJSoy8+MLR8JSFEf/aMgjO/TyLg/jAgMBAAGjggGPMIIBizAOBgNV
+HQ8BAf8EBAMCBaAwTQYDVR0gBEYwRDBCBgorBgEEAaAyASgKMDQwMgYIKwYBBQUH
+AgEWJmh0dHBzOi8vd3d3Lmdsb2JhbHNpZ24uY29tL3JlcG9zaXRvcnkvMCQGA1Ud
+EQQdMBuBGXJ5YW4uaHVyc3RAZ2xvYmFsc2lnbi5jb20wCQYDVR0TBAIwADAdBgNV
+HSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwQwQwYDVR0fBDwwOjA4oDagNIYyaHR0
+cDovL2NybC5nbG9iYWxzaWduLmNvbS9ncy9nc3BlcnNvbmFsc2lnbjJnMi5jcmww
+VQYIKwYBBQUHAQEESTBHMEUGCCsGAQUFBzAChjlodHRwOi8vc2VjdXJlLmdsb2Jh
+bHNpZ24uY29tL2NhY2VydC9nc3BlcnNvbmFsc2lnbjJnMi5jcnQwHQYDVR0OBBYE
+FFWiECe0/L72eVYqcWYnLV6SSjzhMB8GA1UdIwQYMBaAFD8V0m18L+cxnkMKBqiU
+bCw7xe5lMA0GCSqGSIb3DQEBBQUAA4IBAQAhQi6hLPeudmf3IBF4IDzCvRI0FaYd
+BKfprSk/H0PDea4vpsLbWpA0t0SaijiJYtxKjlM4bPd+2chb7ejatDdyrZIzmDVy
+q4c30/xMninGKokpYA11/Ve+i2dvjulu65qasrtQRGybAuuZ67lrp/K3OMFgjV5N
+C3AHYLzvNU4Dwc4QQ1BaMOg6KzYSrKbABRZajfrpC9uiePsv7mDIXLx/toBPxWNl
+a5vJm5DrZdn7uHdvBCE6kMykbOLN5pmEK0UIlwKh6Qi5XD0pzlVkEZliFkBMJgub
+d/eF7xeg7TKPWC5xyOFp9SdMolJM7LTC3wnSO3frBAev+q/nGs9Xxyvs
+-----END CERTIFICATE-----`
+
+const smimeIntermediate = `-----BEGIN CERTIFICATE-----
+MIIEFjCCAv6gAwIBAgILBAAAAAABL07hL1IwDQYJKoZIhvcNAQEFBQAwVzELMAkG
+A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv
+b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw0xMTA0MTMxMDAw
+MDBaFw0xOTA0MTMxMDAwMDBaMFQxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i
+YWxTaWduIG52LXNhMSowKAYDVQQDEyFHbG9iYWxTaWduIFBlcnNvbmFsU2lnbiAy
+IENBIC0gRzIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDBa0H5Nez4
+En3dIlFpX7e5E0YndxQ74xOBbz7kdBd+DLX0LOQMjVPU3DAgKL9ujhH+ZhHkURbH
+3X/94TQSUL/z2JjsaQvS0NqyZXHhM5eeuquzOJRzEQ8+odETzHg2G0Erv7yjSeww
+gkwDWDJnYUDlOjYTDUEG6+i+8Mn425reo4I0E277wD542kmVWeW7+oHv5dZo9e1Q
+yWwiKTEP6BEQVVSBgThXMG4traSSDRUt3T1eQTZx5EObpiBEBO4OTqiBTJfg4vEI
+YgkXzKLpnfszTB6YMDpR9/QS6p3ANB3kfAb+t6udSO3WCst0DGrwHDLBFGDR4UeY
+T5KGGnI7cWL7AgMBAAGjgeUwgeIwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQI
+MAYBAf8CAQAwHQYDVR0OBBYEFD8V0m18L+cxnkMKBqiUbCw7xe5lMEcGA1UdIARA
+MD4wPAYEVR0gADA0MDIGCCsGAQUFBwIBFiZodHRwczovL3d3dy5nbG9iYWxzaWdu
+LmNvbS9yZXBvc2l0b3J5LzAzBgNVHR8ELDAqMCigJqAkhiJodHRwOi8vY3JsLmds
+b2JhbHNpZ24ubmV0L3Jvb3QuY3JsMB8GA1UdIwQYMBaAFGB7ZhpFDZfKiVAvfQTN
+NKj//P1LMA0GCSqGSIb3DQEBBQUAA4IBAQBDc3nMpMxJMQMcYUCB3+C73UpvwDE8
+eCOr7t2F/uaQKKcyqqstqLZc6vPwI/rcE9oDHugY5QEjQzIBIEaTnN6P0vege2IX
+eCOr7t2F/uaQKKcyqqstqLZc6vPwI/rcE9oDHugY5QEjQzIBIEaTnN6P0vege2IX
+YEvTWbWwGdPytDFPYIl3/6OqNSXSnZ7DxPcdLJq2uyiga8PB/TTIIHYkdM2+1DE0
+7y3rH/7TjwDVD7SLu5/SdOfKskuMPTjOEvz3K161mymW06klVhubCIWOro/Gx1Q2
+2FQOZ7/2k4uYoOdBTSlb8kTAuzZNgIE0rB2BIYCTz/P6zZIKW0ogbRSH
+-----END CERTIFICATE-----`

File src/pkg/crypto/x509/x509.go

 	oidExtKeyUsageClientAuth      = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 3, 2}
 	oidExtKeyUsageCodeSigning     = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 3, 3}
 	oidExtKeyUsageEmailProtection = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 3, 4}
+	oidExtKeyUsageIPSECEndSystem  = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 3, 5}
+	oidExtKeyUsageIPSECTunnel     = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 3, 6}
+	oidExtKeyUsageIPSECUser       = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 3, 7}
 	oidExtKeyUsageTimeStamping    = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 3, 8}
 	oidExtKeyUsageOCSPSigning     = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 3, 9}
 )
 	ExtKeyUsageClientAuth
 	ExtKeyUsageCodeSigning
 	ExtKeyUsageEmailProtection
+	ExtKeyUsageIPSECEndSystem
+	ExtKeyUsageIPSECTunnel
+	ExtKeyUsageIPSECUser
 	ExtKeyUsageTimeStamping
 	ExtKeyUsageOCSPSigning
 )
 						out.ExtKeyUsage = append(out.ExtKeyUsage, ExtKeyUsageCodeSigning)
 					case u.Equal(oidExtKeyUsageEmailProtection):
 						out.ExtKeyUsage = append(out.ExtKeyUsage, ExtKeyUsageEmailProtection)
+					case u.Equal(oidExtKeyUsageIPSECEndSystem):
+						out.ExtKeyUsage = append(out.ExtKeyUsage, ExtKeyUsageIPSECEndSystem)
+					case u.Equal(oidExtKeyUsageIPSECTunnel):
+						out.ExtKeyUsage = append(out.ExtKeyUsage, ExtKeyUsageIPSECTunnel)
+					case u.Equal(oidExtKeyUsageIPSECUser):
+						out.ExtKeyUsage = append(out.ExtKeyUsage, ExtKeyUsageIPSECUser)
 					case u.Equal(oidExtKeyUsageTimeStamping):
 						out.ExtKeyUsage = append(out.ExtKeyUsage, ExtKeyUsageTimeStamping)
 					case u.Equal(oidExtKeyUsageOCSPSigning):

File src/pkg/encoding/base32/base32.go

 		dlen := 8
 
 		// do the top bytes contain any data?
-	dbufloop:
 		for j := 0; j < 8; {
 			if len(src) == 0 {
 				return n, false, CorruptInputError(len(osrc) - len(src) - j)
 				}
 				dlen = j
 				end = true
-				break dbufloop
+				break
 			}
 			dbuf[j] = enc.decodeMap[in]
 			if dbuf[j] == 0xFF {

File src/pkg/encoding/base64/base64.go

 		var dbuf [4]byte
 		dlen := 4
 
-	dbufloop:
 		for j := 0; j < 4; {
 			if len(src) == 0 {
 				return n, false, CorruptInputError(len(osrc) - len(src) - j)
 				}
 				dlen = j
 				end = true
-				break dbufloop
+				break
 			}
 			dbuf[j] = enc.decodeMap[in]
 			if dbuf[j] == 0xFF {

File src/pkg/encoding/csv/writer.go

 	for _, record := range records {
 		err = w.Write(record)
 		if err != nil {
-			break
+			return err
 		}
 	}
-	w.Flush()
-	return nil
+	return w.w.Flush()
 }
 
 // fieldNeedsQuotes returns true if our field must be enclosed in quotes.

File src/pkg/encoding/gob/encode.go

 		error_(err1)
 	}
 	if info.encoder == nil {
-		// mark this engine as underway before compiling to handle recursive types.
+		// Assign the encEngine now, so recursive types work correctly. But...
 		info.encoder = new(encEngine)
+		// ... if we fail to complete building the engine, don't cache the half-built machine.
+		// Doing this here means we won't cache a type that is itself OK but
+		// that contains a nested type that won't compile. The result is consistent
+		// error behavior when Encode is called multiple times on the top-level type.
+		ok := false
+		defer func() {
+			if !ok {
+				info.encoder = nil
+			}
+		}()
 		info.encoder = enc.compileEnc(ut)
+		ok = true
 	}
 	return info.encoder
 }

File src/pkg/encoding/gob/encoder_test.go

 		t.Fatal("expected error about nil pointer and interface, got:", errMsg)
 	}
 }
+
+type Bug4Public struct {
+	Name   string
+	Secret Bug4Secret
+}
+
+type Bug4Secret struct {
+	a int // error: no exported fields.
+}
+
+// Test that a failed compilation doesn't leave around an executable encoder.
+// Issue 3273.
+func TestMutipleEncodingsOfBadType(t *testing.T) {
+	x := Bug4Public{
+		Name:   "name",
+		Secret: Bug4Secret{1},
+	}
+	buf := new(bytes.Buffer)
+	enc := NewEncoder(buf)
+	err := enc.Encode(x)
+	if err == nil {
+		t.Fatal("first encoding: expected error")
+	}
+	buf.Reset()
+	enc = NewEncoder(buf)
+	err = enc.Encode(x)
+	if err == nil {
+		t.Fatal("second encoding: expected error")
+	}
+	if !strings.Contains(err.Error(), "no exported fields") {
+		t.Errorf("expected error about no exported fields; got %v", err)
+	}
+}

File src/pkg/encoding/gob/type.go

 	if rt.Name() == "" {
 		if pt := rt; pt.Kind() == reflect.Ptr {
 			star = "*"
-			rt = pt
+			rt = pt.Elem()
 		}
 	}
 	if rt.Name() != "" {

File src/pkg/encoding/json/decode.go

 	return d.savedError
 }
 
+// A Number represents a JSON number literal.
+type Number string
+
+// String returns the literal text of the number.
+func (n Number) String() string { return string(n) }
+
+// Float64 returns the number as a float64.
+func (n Number) Float64() (float64, error) {
+	return strconv.ParseFloat(string(n), 64)
+}
+
+// Int64 returns the number as an int64.
+func (n Number) Int64() (int64, error) {
+	return strconv.ParseInt(string(n), 10, 64)
+}
+
 // decodeState represents the state while decoding a JSON value.
 type decodeState struct {
 	data       []byte
 	nextscan   scanner // for calls to nextValue
 	savedError error
 	tempstr    string // scratch space to avoid some allocations
+	useNumber  bool
 }
 
 // errPhase is used for errors that should not happen unless
 		v = v.Addr()
 	}
 	for {
-		var isUnmarshaler bool
-		if v.Type().NumMethod() > 0 {
-			// Remember that this is an unmarshaler,
-			// but wait to return it until after allocating
-			// the pointer (if necessary).
-			_, isUnmarshaler = v.Interface().(Unmarshaler)
-		}
-
 		// Load value from interface, but only if the result will be
 		// usefully addressable.
-		if iv := v; iv.Kind() == reflect.Interface && !iv.IsNil() {
-			e := iv.Elem()
+		if v.Kind() == reflect.Interface && !v.IsNil() {
+			e := v.Elem()
 			if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodingNull || e.Elem().Kind() == reflect.Ptr) {
 				v = e
 				continue
 			}
 		}
 
-		pv := v
-		if pv.Kind() != reflect.Ptr {
+		if v.Kind() != reflect.Ptr {
 			break
 		}
 
-		if pv.Elem().Kind() != reflect.Ptr && decodingNull && pv.CanSet() {
-			return nil, pv
+		if v.Elem().Kind() != reflect.Ptr && decodingNull && v.CanSet() {
+			break
 		}
-		if pv.IsNil() {
-			pv.Set(reflect.New(pv.Type().Elem()))
+		if v.IsNil() {
+			v.Set(reflect.New(v.Type().Elem()))
 		}
-		if isUnmarshaler {
-			// Using v.Interface().(Unmarshaler)
-			// here means that we have to use a pointer
-			// as the struct field.  We cannot use a value inside
-			// a pointer to a struct, because in that case
-			// v.Interface() is the value (x.f) not the pointer (&x.f).
-			// This is an unfortunate consequence of reflect.
-			// An alternative would be to look up the
-			// UnmarshalJSON method and return a FuncValue.
-			return v.Interface().(Unmarshaler), reflect.Value{}