summaryrefslogtreecommitdiff
path: root/api
Commit message (Collapse)AuthorAgeFilesLines
* net/http: let ErrNotSupported match errors.ErrUnsupportedIan Lance Taylor2023-05-101-0/+1
| | | | | | | | | | | | For #41198 Change-Id: Ibb030e94618a1f594cfd98ddea214ad7a88d2e73 Reviewed-on: https://go-review.googlesource.com/c/go/+/494122 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* log/slog: Group takes ...anyJonathan Amsterdam2023-05-042-1/+1
| | | | | | | | | | | | | The Group function takes a key and a ...any, which is converted into attrs. Fixes #59204. Change-Id: Ib714365dcda2eda37863ce433f3dd8cf5eeda610 Reviewed-on: https://go-review.googlesource.com/c/go/+/487855 Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* log/slog: built-in handler constructors take options as a second argJonathan Amsterdam2023-05-042-4/+2
| | | | | | | | | | | | | | | There is now one constructor function for each built-in handler, with signature NewXXXHandler(io.Writer, *HandlerOptions) *XXXHandler Fixes #59339. Change-Id: Ia02183c5ce0dc15c64e33ad05fd69bca09df2d2d Reviewed-on: https://go-review.googlesource.com/c/go/+/486415 Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com>
* io/fs: add FormatFileInfo and FormatDirEntry functionsIan Lance Taylor2023-05-021-0/+2
| | | | | | | | | | | | | | For #54451 Change-Id: I3214066f77b1398ac1f2786ea035c83f32f0a826 Reviewed-on: https://go-review.googlesource.com/c/go/+/489555 Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
* go/ast: add IsGenerated(*File) predicateAlan Donovan2023-04-251-0/+1
| | | | | | | | | | | | | See https://go.dev/s/generatedcode for spec. Fixes #28089 Change-Id: Ic9bb138bdd180f136f9e8e74e187319acca5dbac Reviewed-on: https://go-review.googlesource.com/c/go/+/487935 Run-TryBot: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
* testing/slogtest: tests for slog handlersJonathan Amsterdam2023-04-241-1/+1
| | | | | | | | | | | | | | | Add a package for testing that a slog.Handler implementation satisfies that interface's documented requirements. Code copied from x/exp/slog/slogtest. Updates #56345. Change-Id: I89e94d93bfbe58e3c524758f7ac3c3fba2a2ea96 Reviewed-on: https://go-review.googlesource.com/c/go/+/487895 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
* log/slog: add Source type for source locationJonathan Amsterdam2023-04-201-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a struct called Source that holds the function, file and line of a location in the program's source code. When HandleOptions.AddSource is true, the ReplaceAttr function will get an Attr whose key is SourceKey and whose value is a *Source. We use *Source instead of Source to save an allocation. The pointer and the value each cause one allocation up front: the pointer when it is created, and the value when it is assigned to the `any` field of a slog.Value (handle.go:283). If a ReplaceAttr function wanted to modify a Source value, it would have to create a new slog.Value to return, causing a second allocation, but the function can modify a *Source in place. TextHandler displays a Source as "file:line". JSONHandler displays a Source as a group of its non-zero fields. This replaces the previous design, where source location was always a string with the format "file:line". The new design gives users more control over how to output and consume source locations. Fixes #59280. Change-Id: I84475abd5ed83fc354b50e34325c7b246cf327c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/486376 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
* context: add AfterFuncDamien Neil2023-04-191-0/+1
| | | | | | | | | | | | | | | | | Add an AfterFunc function, which registers a function to run after a context has been canceled. Add support for contexts that implement an AfterFunc method, which can be used to avoid the need to start a new goroutine watching the Done channel when propagating cancellation signals. Fixes #57928 Change-Id: If0b2cdcc4332961276a1ff57311338e74916259c Reviewed-on: https://go-review.googlesource.com/c/go/+/482695 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Sameer Ajmani <sameer@golang.org>
* debug/elf: support zstd compressionIan Lance Taylor2023-04-181-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Test cases added to debug/dwarf because that is where it matters in practice. The new test binary line-gcc-zstd.elf built with gcc -g -no-pie -Wl,--compress-debug-sections=zstd line[12].c using gcc (Debian 12.2.0-10) 12.2.0 with a development version of the GNU binutils. Fixes #55107 Change-Id: I48507c96902e1f83a174e5647b5cc403d965b52b Reviewed-on: https://go-review.googlesource.com/c/go/+/473256 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
* net: mptcp: add TCPConn's MultipathTCP checkerMatthieu Baerts2023-04-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new TCPConn method returns whether the connection is using MPTCP or if a fallback to TCP has been done, e.g. because the other peer doesn't support MPTCP. When working on the new E2E test linked to MPTCP (#56539), it looks like the user might need to know such info to be able to do some special actions (report, stop, etc.). This also improves the test to make sure MPTCP has been used as expected. Regarding the implementation, from kernel version 5.16, it is possible to use: getsockopt(..., SOL_MPTCP, MPTCP_INFO, ...) and check if EOPNOTSUPP (IPv4) or ENOPROTOOPT (IPv6) is returned. If it is, it means a fallback to TCP has been done. See this link for more details: https://github.com/multipath-tcp/mptcp_net-next/issues/294 Before v5.16, there is no other simple way, from the userspace, to check if the created socket did a fallback to TCP. Netlink requests could be done to try to find more details about a specific socket but that seems quite a heavy machinery. Instead, only the protocol is checked on older kernels. The E2E test has been modified to check that the MPTCP connection didn't do any fallback to TCP, explicitely validating the two methods (SO_PROTOCOL and MPTCP_INFO) if it is supported by the host. This work has been co-developed by Gregory Detal <gregory.detal@tessares.net> and Benjamin Hesmans <benjamin.hesmans@tessares.net>. Fixes #59166 Change-Id: I5a313207146f71c66c349aa8588a2525179dd8b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/471140 Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* log/slog: function argument to Record.Attrs returns boolJonathan Amsterdam2023-04-121-0/+2
| | | | | | | | | | | | Record.Attrs stops as soon as its argument function returns false. Fixes #59060. Change-Id: I578d64635e0e52b0fcdbc57f6d5a27a6efac8c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/484096 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com>
* regexp: add Regexp.TextMarshaler/TextUnmarshalerJonathan Hall2023-04-121-0/+2
| | | | | | | | | | | | | Fixes #46159 Change-Id: I51dc4e9e8915ab5a73f053690fb2395edbeb1151 Reviewed-on: https://go-review.googlesource.com/c/go/+/479401 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
* go/ast: add File.GoVersionRuss Cox2023-04-111-0/+1
| | | | | | | | | | | | | | | | | | For #57001, compilers and others tools will need to understand that a different Go version can be used in different files in a program, according to the //go:build lines in those files. This CL adds a GoVersion string field to ast.File, to allow exposing this per-file Go version information. For #59033. Change-Id: I3931ea86c237983d152964f48dce498bcb1f06aa Reviewed-on: https://go-review.googlesource.com/c/go/+/476276 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
* go/build/constraint: add GoVersionRuss Cox2023-04-111-0/+2
| | | | | | | | | | | | | | | | For #57001, programs need to be able to deduce the Go version implied by a given build constraint. GoVersion determines that, by discarding all build tags other than Go versions and computing the minimum Go version implied by the resulting expression. For #59033. Change-Id: Ifb1e7af2bdbdf172f82aa490c826c9b6ca5e824b Reviewed-on: https://go-review.googlesource.com/c/go/+/476275 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* slices: add DeleteFuncIan Lance Taylor2023-04-071-0/+1
| | | | | | | | | | | | Fixes #54768 Change-Id: I588ae33c13e0bbd9d324c11771667b22a864047d Reviewed-on: https://go-review.googlesource.com/c/go/+/483175 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Eli Bendersky <eliben@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
* net/http: expose "http: server gave HTTP response to HTTPS client" errorAkihiro Suda2023-04-071-0/+1
| | | | | | | | | | | | | | | | Expose "http: server gave HTTP response to HTTPS client" error as `ErrSchemeMismatch`, so that it can be compared with `errors.Is` . Fixes #44855 Change-Id: If96e0d000fdef641fea407310faf9e1c4f7ad0f0 GitHub-Last-Rev: 22879fc88367d77817d7d96c9164f22e55f3a192 GitHub-Pull-Request: golang/go#50939 Reviewed-on: https://go-review.googlesource.com/c/go/+/382117 Run-TryBot: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
* reflect: deprecate SliceHeader and StringHeaderRuss Cox2023-04-031-0/+2
| | | | | | | | | | | | | | | | These are replaced by unsafe.String etc, which were added in Go 1.20. Per https://go.dev/wiki/Deprecated, we must wait until Go 1.21 to mark them deprecated. Fixes #56906. Change-Id: I4198c3f3456e9e2031f6c7232842e187e6448892 Reviewed-on: https://go-review.googlesource.com/c/go/+/452762 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Russ Cox <rsc@golang.org>
* sync: implement OnceFunc, OnceValue, and OnceValuesAustin Clements2023-03-311-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds the three functions from #56102 to the sync package. These provide a convenient API for the most common uses of sync.Once. The performance of these is comparable to direct use of sync.Once: $ go test -run ^$ -bench OnceFunc\|OnceVal -count 20 | benchstat -row .name -col /v goos: linux goarch: amd64 pkg: sync cpu: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz │ Once │ Global │ Local │ │ sec/op │ sec/op vs base │ sec/op vs base │ OnceFunc 1.3500n ± 6% 2.7030n ± 1% +100.22% (p=0.000 n=20) 0.3935n ± 0% -70.86% (p=0.000 n=20) OnceValue 1.3155n ± 0% 2.7460n ± 1% +108.74% (p=0.000 n=20) 0.5478n ± 1% -58.35% (p=0.000 n=20) The "Once" column represents the baseline of how code would typically express these patterns using sync.Once. "Global" binds the closure returned by OnceFunc/OnceValue to global, which is how I expect these to be used most of the time. Currently, this defeats some inlining opportunities, which roughly doubles the cost over sync.Once; however, it's still *extremely* fast. Finally, "Local" binds the returned closure to a local variable. This unlocks several levels of inlining and represents pretty much the best possible case for these APIs, but is also unlikely to happen in practice. In principle the compiler could recognize that the global in the "Global" case is initialized in place and never mutated and do the same optimizations it does in the "Local" case, but it currently does not. Fixes #56102 Change-Id: If7355eccd7c8de7288d89a4282ff15ab1469e420 Reviewed-on: https://go-review.googlesource.com/c/go/+/451356 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Caleb Spare <cespare@gmail.com> Auto-Submit: Austin Clements <austin@google.com>
* net: mptcp: implement listenMPTCPMatthieu Baerts2023-03-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Similar to dialMPTCP, this listenMPTCP function is called when the user has requested MPTCP via SetMultipathTCP in the ListenConfig. This function falls back to listenTCP on operating systems that do not support MPTCP or if MPTCP is not supported. On ListenConfig side, MultipathTCP function can be used to know if the package will try to use MPTCP or not when Listen is called. Note that this new listenMPTCP function returns a TCPListener object and not a new MPTCP dedicated one. The reasons are similar as the ones explained in the parent commit introducing dialTCP: if MPTCP is used by default later, Listen will return a different object that could break existing applications expecting TCPListener. This work has been co-developped by Gregory Detal <gregory.detal@tessares.net>. Updates #56539 Change-Id: I010f1d87f921bbac9e157cef2212c51917852353 Reviewed-on: https://go-review.googlesource.com/c/go/+/471137 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* net: mptcp: implement dialMPTCPMatthieu Baerts2023-03-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This function is called when the user has requested MPTCP via SetMultipathTCP in the Dialer. This new function falls back to dialTCP on operating systems that do not support MPTCP or if MPTCP is not supported. On Dialer side, MultipathTCP function can be used to know if the package will try to use MPTCP or not when Dial is called. Note that this new dialMPTCP function returns a TCPConn object, like dialTCP. A new MPTCPConn object using the following composition could have been returned: type MPTCPConn struct { *TCPConn } But the drawback is that if MPTCP is used by default one day (see #56539 issue on GitHub), Dial will return a different object: this new MPTCPConn type instead of the previously expected TCPConn. This can cause issues for apps checking the returned object. This work has been co-developped by Gregory Detal <gregory.detal@tessares.net>. Updates #56539 Change-Id: I0f9b5b81f630b39142bdd553d4f1b4c775f1dff0 Reviewed-on: https://go-review.googlesource.com/c/go/+/471136 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* context: add WithoutCancelSameer Ajmani2023-03-291-0/+1
| | | | | | | | | | | | | | | | | WithoutCancel returns a copy of parent that is not canceled when parent is canceled. The returned context returns no Deadline or Err, and its Done channel is nil. Calling Cause on the returned context returns nil. API changes: +pkg context, func WithoutCancel(Context) Context Fixes #40221 Change-Id: Ide29631c08881176a2c2a58409fed9ca6072e65d Reviewed-on: https://go-review.googlesource.com/c/go/+/479918 Run-TryBot: Sameer Ajmani <sameer@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* log/slog: initial commitJonathan Amsterdam2023-03-211-0/+158
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The slog structured logging package. This code was copied from the slog directory of the x/exp repo at commit 642cacee5cc05231f45555a333d07f1005ffc287, with the following changes: - Change import paths. - Delete unused files list.go, list_test.go. - Rename example_depth_test.go to example_wrap_test.go and adjust example output. - Change the tag safe_values to safe_slog_values. - Make captureHandler goroutine-safe to fix a race condition in benchmarks. - Other small changes as suggested in review comments. Also, add dependencies to go/build/deps_test.go. Also, add new API for the API checker. Updates golang/go#56345. Change-Id: Id8d720967571ced5c5f32c84a8dd9584943cd7df Reviewed-on: https://go-review.googlesource.com/c/go/+/477295 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
* flag: add BoolFunc; FlagSet.BoolFuncCarl Johnson2023-03-161-0/+2
| | | | | | | | | | | | | | | | | | Fixes #53747 Based on CL 416514 Change-Id: I1ff79c6290b06dfa8672a473045e8fe80c22afcf GitHub-Last-Rev: 74fba9b3096487c04c8dc1f2237f67f3558212f1 GitHub-Pull-Request: golang/go#59013 Reviewed-on: https://go-review.googlesource.com/c/go/+/476015 Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* crypto/elliptic: deprecate unsafe APIsFilippo Valsorda2023-03-162-0/+13
| | | | | | | | | | | | | | | | | Per the updated go.dev/wiki/Deprecated, those APIs replaced by crypto/ecdh (added in Go 1.20) can now be marked as deprecated in Go 1.21. Updates #52221 Updates #34648 Change-Id: Id0e11d7faa3a58a1716ce1ec6e2fff97bab96259 Reviewed-on: https://go-review.googlesource.com/c/go/+/459977 Run-TryBot: Filippo Valsorda <filippo@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* crypto/rsa: deprecate multiprime RSA supportFilippo Valsorda2023-03-161-0/+2
| | | | | | | | | | | | Fixes #56921 Change-Id: I03f9969a5146ab7becd983784d8cb5b23a3fbb18 Reviewed-on: https://go-review.googlesource.com/c/go/+/459976 TryBot-Bypass: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Filippo Valsorda <filippo@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
* testing: add Testing functionIan Lance Taylor2023-03-131-0/+1
| | | | | | | | | | | | | | | The Testing function reports whether the program is a test created by "go test". Fixes #52600 Change-Id: Ie0fff7c7dfdfdf997c18b4b6112632600b327cc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/475496 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
* crypto/x509: surface ReasonCode in RevocationList APIAaron Gable2023-03-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Creates x509.RevocationListEntry, a new type representing a single revoked certificate entry in a CRL. Like the existing Certificate and RevocationList types, this new type has a field for its Raw bytes, and exposes its mostly-commonly-used extension (ReasonCode) as a top-level field. This provides more functionality to the user than the existing pkix.RevokedCertificate type. Adds a RevokedCertificateEntries field which is a []RevocationListEntry to RevocationList. This field deprecates the RevokedCertificates field. When the RevokedCertificates field is removed in a future release, this will remove one of the last places where a pkix type is directly exposed in the x509 package API. Updates the ParseRevocationList function to populate both fields for now, and updates the CreateRevocationList function to prefer the new field if it is populated, but use the deprecated field if not. Finally, also updates the x509 unit tests to use the new .ReasonCode field in most cases. Fixes #53573 Change-Id: Ia6de171802a5bd251938366508532e806772d7d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/468875 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
* bytes: add Buffer.Available and Buffer.AvailableBufferJoe Tsai2023-03-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a new Buffer.AvailableBuffer method that returns an empty buffer with a possibly non-empty capacity for use with append-like APIs. The typical usage pattern is something like: b := bb.AvailableBuffer() b = appendValue(b, v) bb.Write(b) It allows logic combining append-like APIs with Buffer to avoid needing to allocate and manage buffers themselves and allows the append-like APIs to directly write into the Buffer. The Buffer.Write method uses the builtin copy function, which avoids copying bytes if the source and destination are identical. Thus, Buffer.Write is a constant-time call for this pattern. Performance: BenchmarkBufferAppendNoCopy 2.909 ns/op 5766942167.24 MB/s This benchmark should only be testing the cost of bookkeeping and never the copying of the input slice. Thus, the MB/s should be orders of magnitude faster than RAM. Fixes #53685 Change-Id: I0b41e54361339df309db8d03527689b123f99085 Reviewed-on: https://go-review.googlesource.com/c/go/+/474635 Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com>
* errors: add ErrUnsupportedAndy Pan2023-03-111-0/+1
| | | | | | | | | | | | | Fixes #41198 Change-Id: Ib33a11d0eb311f8e2b81de24d11df49e00b2fc81 Reviewed-on: https://go-review.googlesource.com/c/go/+/473935 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* net/http: support full-duplex HTTP/1 responsesDamien Neil2023-03-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | Add support for concurrently reading from an HTTP/1 request body while writing the response. Normally, the HTTP/1 server automatically consumes any remaining request body before starting to write a response, to avoid deadlocking clients which attempt to write a complete request before reading the response. Add a ResponseController.EnableFullDuplex method which disables this behavior. For #15527 For #57786 Change-Id: Ie7ee8267d8333e9b32b82b9b84d4ad28ab8edf01 Reviewed-on: https://go-review.googlesource.com/c/go/+/472636 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
* debug/elf: retrieve values for dynamic section tagsFlorin Papa2023-03-071-0/+1
| | | | | | | | | | | | | | Add functionality to retrieve values for .dynamic entries that don't correspond to entries in the string table. Fixes #56892 Change-Id: I6edabc8ca331c819e442d06e19b7f4df8343372b Reviewed-on: https://go-review.googlesource.com/c/go/+/452617 Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go, go/build: parse directives in file headersRuss Cox2023-02-231-0/+6
| | | | | | | | | | | | | | | | | | | | | For #56986, go/build needs to report up to cmd/go about //go:debug lines found in the source code. Rather than make a special case for //go:debug, this change gathers all top-level directives above the package line and includes them in the result. The go command's module index must match go/build, so this CL contains the code to update the index as well. A future CL will use the //go:debug lines to prepare the default GODEBUG settings, as well as rejecting such lines in non-main packages. Change-Id: I66ab8dc72f9cd65c503b10b744367caca233f8a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/453603 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* syscall: add jail support to ForkExec on FreeBSDHarald Böhm2023-02-221-0/+10
| | | | | | | | | | | | | | | | | | Introduce a new SysProcAttr member called Jail on FreeBSD. This allows supplying an existing jail's ID to which the child process is attached before calling the exec system call. Fixes #46259 Change-Id: Ie282e5b83429131f9a9e1e27cfcb3bcc995d1d4d Reviewed-on: https://go-review.googlesource.com/c/go/+/458335 Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Goutnik <dgoutnik@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Samuel Karp <samuelkarp@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
* cmd/api: add API checks for freebsd/riscv64Dmitri Goutnik2023-02-171-0/+8722
| | | | | | | | | | | | | | | | The freebsd/riscv64 port was added in go1.20, make cmd/api aware of it and backfill API files. For #58582 Change-Id: I242b161cdb6221c8f60a1868c6435be26fca0078 Reviewed-on: https://go-review.googlesource.com/c/go/+/469135 Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/api: add API checks for freebsd/arm64Dmitri Goutnik2023-02-175-0/+8766
| | | | | | | | | | | | | | | | The freebsd/arm64 port was added in go1.14, make cmd/api aware of it and backfill API files. For #58582 Change-Id: I8b25c6cf5a66611d90d225762b257679a4abface Reviewed-on: https://go-review.googlesource.com/c/go/+/469115 Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* math: add Compare and Compare32Akhil Indurti2023-02-151-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This change introduces the Compare and Compare32 functions based on the total-ordering predicate in IEEE-754, section 5.10. In particular, * -NaN is ordered before any other value * +NaN is ordered after any other value * -0 is ordered before +0 * All other values are ordered the usual way Compare-8 0.4537n ± 1% Compare32-8 0.3752n ± 1% geomean 0.4126n Fixes #56491. Change-Id: I5c9c77430a2872f380688c1b0a66f2105b77d5ac Reviewed-on: https://go-review.googlesource.com/c/go/+/467515 Reviewed-by: WANG Xuerui <git@xen0n.name> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* slices: new packageIan Lance Taylor2023-02-131-0/+14
| | | | | | | | | | | | | | | | | | This copies parts of x/exp/slices into the standard library. We omit all functions that depend on constraints.Ordered, and the Func variants of all such functions. In particular this omits the various Sort and Search functions. Fixes #57433 Change-Id: I3c28f4c2e6bd1e3c9ad70e120a0dd68065388f77 Reviewed-on: https://go-review.googlesource.com/c/go/+/467417 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Eli Bendersky <eliben@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
* Revert "math: add Compare and Compare32"Than McIntosh2023-02-101-2/+0
| | | | | | | | | | | | | | | This reverts CL 459435. Reason for revert: Tests failing on MIPS. Change-Id: I9017bf718ba938df6d6766041555034d55d90b8a Reviewed-on: https://go-review.googlesource.com/c/go/+/467255 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Akhil Indurti <aindurti@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
* math: add Compare and Compare32Akhil Indurti2023-02-091-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | This change introduces the Compare and Compare32 functions based on the total-ordering predicate in IEEE-754, section 5.10. In particular, * -NaN is ordered before any other value * +NaN is ordered after any other value * -0 is ordered before +0 * All other values are ordered the usual way name time/op Compare-8 0.24ns ± 1% Compare32-8 0.24ns ± 0% Fixes #56491. Change-Id: I9444fbfefe26741794c4436a26d403b8da97bdaf Reviewed-on: https://go-review.googlesource.com/c/go/+/459435 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
* all: upgrade Unicode from 13.0.0 to 15.0.0weebney2023-02-062-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Update unicode/tables.go to reflect changes in the Unicode Standard up to Unicode 15.0.0, released 13 Sept 2022. In order to accommodate this update, strconv/isPrint has been updated to reflect changes in printable characters. Also changed is template/exec_test.go for both text and html packages- in the test "TestJSEscaping", rune U+FDFF was used as a placeholder for an unprintable character. This codepoint was assigned and made printable in Unicode 14.0.0, breaking this test. It has been replaced with the assigned and never-printable U+FFFE to fix the test and provide resiliency in the future. This upgrade bypasses Unicode 14.0.0, but is compatible. Updates https://github.com/golang/go/issues/48621 Fixes https://github.com/golang/go/issues/55079 Change-Id: I40efd097eb746db0727ebf7437280916d1242e47 GitHub-Last-Rev: c8885cab7a0c23632e1e5a433b1e8d5634a45a30 GitHub-Pull-Request: golang/go#57265 Reviewed-on: https://go-review.googlesource.com/c/go/+/456837 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Rob Pike <r@golang.org>
* maps: new packageIan Lance Taylor2023-02-031-0/+7
| | | | | | | | | | | | | | | | | This copies x/exp/maps into the standard library (except for the Clear function which is now available as the clear builtin.) Fixes #57436 Change-Id: I30dd470c2f7ae34c7c82b4c1025a7582d61fabaa Reviewed-on: https://go-review.googlesource.com/c/go/+/464343 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Eli Bendersky <eliben@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
* debug/elf: add DT_FLAGS_1 constantsFlorin Papa2023-02-031-0/+65
| | | | | | | | | | | | | Add constants for all ELF dynamic flags (pertaining to DT_FLAGS_1). This will help, for example, determining whether an object is a position-independent executable (PIE). The constants are defined according to Table 15-10 in https://docs.oracle.com/en/operating-systems/solaris/oracle-solaris/11.4/linkers-libraries/dynamic-section.html. Fixes #56887 Change-Id: I6cd501af50d9dbcc2aa8a9a002e12c6fb6726761 Reviewed-on: https://go-review.googlesource.com/c/go/+/452496 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* math/big: add Int.Float64 conversionAlan Donovan2023-02-021-0/+1
| | | | | | | | | | | | | | This operation converts a big.Int to float64, reporting the accuracy of the result, with a fast path in hardware. Fixes #56984 Change-Id: I86d0fb0e105a06a4009986f2f5fd87a4d446f6f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/453115 Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Alan Donovan <adonovan@google.com>
* go/token: add (*File).Lines methodAlan Donovan2023-02-021-0/+1
| | | | | | | | | | | | | | | This method returns the array updated by SetLines, for use in exporter packages. Fixes #57708 Change-Id: I12ed5e7e1bae7517f40cb25e76e51997c25d84f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/464515 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Alan Donovan <adonovan@google.com>
* reflect,runtime: add Value.ClearCuong Manh Le2023-01-301-0/+1
| | | | | | | | | | | | | Fixes #55002 Change-Id: I7d0f14cc54f67f2769b51d2efafc4ae3714f0e3d Reviewed-on: https://go-review.googlesource.com/c/go/+/457895 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* encoding/binary: add var NativeEndiancuiweixie2023-01-271-0/+1
| | | | | | | | | | | | | Updates #57237 Change-Id: I149c8b7eeac91b87b5810250f96d48ca87135807 Reviewed-on: https://go-review.googlesource.com/c/go/+/463218 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: xie cui <523516579@qq.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
* bytes, strings: add ContainsFunchopehook2023-01-241-0/+2
| | | | | | | | | | | | Fixes #54386. Change-Id: I78747da337ed6129e4f7426dd0483a644bed82e3 Reviewed-on: https://go-review.googlesource.com/c/go/+/460216 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: hopehook <hopehook@golangcn.org> Auto-Submit: Ian Lance Taylor <iant@golang.org>
* context: add APIs for setting a cancelation cause when deadline or timer expiresSameer Ajmani2023-01-201-0/+2
| | | | | | | | | | Fixes #56661 Change-Id: I1c23ebc52e6b7ae6ee956614e1a0a45d6ecbd5b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/449318 Run-TryBot: Sameer Ajmani <sameer@golang.org> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* runtime: replace panic(nil) with panic(new(runtime.PanicNilError))Russ Cox2023-01-191-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Long ago we decided that panic(nil) was too unlikely to bother making a special case for purposes of recover. Unfortunately, it has turned out not to be a special case. There are many examples of code in the Go ecosystem where an author has written panic(nil) because they want to panic and don't care about the panic value. Using panic(nil) in this case has the unfortunate behavior of making recover behave as though the goroutine isn't panicking. As a result, code like: func f() { defer func() { if err := recover(); err != nil { log.Fatalf("panicked! %v", err) } }() call1() call2() } looks like it guarantees that call2 has been run any time f returns, but that turns out not to be strictly true. If call1 does panic(nil), then f returns "successfully", having recovered the panic, but without calling call2. Instead you have to write something like: func f() { done := false defer func() { if err := recover(); !done { log.Fatalf("panicked! %v", err) } }() call1() call2() done = true } which defeats nearly the whole point of recover. No one does this, with the result that almost all uses of recover are subtly broken. One specific broken use along these lines is in net/http, which recovers from panics in handlers and sends back an HTTP error. Users discovered in the early days of Go that panic(nil) was a convenient way to jump out of a handler up to the serving loop without sending back an HTTP error. This was a bug, not a feature. Go 1.8 added panic(http.ErrAbortHandler) as a better way to access the feature. Any lingering code that uses panic(nil) to abort an HTTP handler without a failure message should be changed to use http.ErrAbortHandler. Programs that need the old, unintended behavior from net/http or other packages can set GODEBUG=panicnil=1 to stop the run-time error. Uses of recover that want to detect panic(nil) in new programs can check for recover returning a value of type *runtime.PanicNilError. Because the new GODEBUG is used inside the runtime, we can't import internal/godebug, so there is some new machinery to cross-connect those in this CL, to allow a mutable GODEBUG setting. That won't be necessary if we add any other mutable GODEBUG settings in the future. The CL also corrects the handling of defaulted GODEBUG values in the runtime, for #56986. Fixes #25448. Change-Id: I2b39c7e83e4f7aa308777dabf2edae54773e03f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/461956 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
* api: promote next to go1.20Michael Pratt2022-12-0750-428/+428
| | | | | | | | Change-Id: I180f262837b164095f9ac9459d900ec1ac0585a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/455697 Reviewed-by: Jenny Rakoczy <jenny@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>