Commit graph

289 commits

Author SHA1 Message Date
Yuval Pavel Zholkover
d8220ac32f syscall: remove FreeBSD 11 and below 64bit inode compatibility shims
Update #53280

Change-Id: Iaa7c0cf5dbefaa8e14c2de499f99755911c17672
Reviewed-on: https://go-review.googlesource.com/c/go/+/411596
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Yuval Pavel Zholkover <paulzhol@gmail.com>
Reviewed-by: Dmitri Goutnik <dgoutnik@gmail.com>
2022-09-16 01:17:28 +00:00
Kir Kolyshkin
bca17d16ca syscall: add CgroupFD support for ForkExec on Linux
Implement CLONE_INTO_CGROUP feature, allowing to put a child in a
specified cgroup in a clean and simple way. Note that the feature only
works for cgroup v2, and requires Linux kernel 5.7 or newer.

Using the feature requires a new syscall, clone3. Currently this is the
only reason to use clone3, but the code is structured in a way so that
other cases may be easily added in the future.

Add a test case.

While at it, try to simplify the syscall calling code in
forkAndExecInChild1, which became complicated over time because:

1. It was using either rawVforkSyscall or RawSyscall6 depending on
   whether CLONE_NEWUSER was set.

2. On Linux/s390, the first two arguments to clone(2) system call are
   swapped (which deserved a mention in Linux ABI hall of shame). It
   was worked around in rawVforkSyscall on s390, but had to be
   implemented via a switch/case when using RawSyscall6, making the code
   less clear.

Let's

 - modify rawVforkSyscall to have two arguments (which is also required
   for clone3);

 - remove the arguments workaround from s390 asm, instead implementing
   arguments swap in the caller (which still looks ugly but at least
   it's done once and is clearly documented now);

 - use rawVforkSyscall for all cases (since it is essentially similar to
   RawSyscall6, except for having less parameters, not returning r2, and
   saving/restoring the return address before/after syscall on 386 and
   amd64).

Updates #51246.

Change-Id: Ifcd418ebead9257177338ffbcccd0bdecb94474e
Reviewed-on: https://go-review.googlesource.com/c/go/+/417695
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-09 15:34:16 +00:00
Paul E. Murphy
2b6ff90851 debug/elf: define additional PPC64 ELFv2 relocations
The PPC64 ELFv2 supplement version 1.5 defines a handful of
new relocation types, similarly some were not added.

Fixes #54345

Change-Id: Id39b29d404298fca4a10ccf1e96b5964dc452c9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/425555
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-08 13:31:46 +00:00
cuiweixie
67e6542467 go/ast: add Range token.Pos to RangeStmt
For #50429

Change-Id: Idb027244f901d9f482c894b5b979a054d0f07de5
Reviewed-on: https://go-review.googlesource.com/c/go/+/426091
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-09-05 08:12:37 +00:00
Cuong Manh Le
846c378b8c cmd/cgo: add and use runtime/cgo.Incomplete instead of //go:notinheap
Updates #46731

Change-Id: Ia83f27c177cc2f57e240cb5c6708d4552423f5be
Reviewed-on: https://go-review.googlesource.com/c/go/+/421879
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-28 16:04:49 +00:00
Jianwei Mao
a2d2e6e7cb net: add FlagRunning to exactly reflect the states of an interface.
Correctly set this flag while parsing the syscall result.

The FlagUp flag can not distinguish the following situations:
1. interface is plugged, automatically up, and in running(UP) state
2. interface is not plugged, administratively or manually set to up,
but in DOWN state

So, We can't distinguish the state of a NIC by the FlagUp flag alone.

Fixes #53482

Change-Id: I43796bea1a7f72d1fddfef914efe603c81995e1b
GitHub-Last-Rev: 686b5d888e
GitHub-Pull-Request: golang/go#53484
Reviewed-on: https://go-review.googlesource.com/c/go/+/413454
TryBot-Result: Gopher Robot <gobot@golang.org>
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: Ryan Schuster <shuey19831@gmail.com>
Reviewed-by: Jianwei Mao <maojianwei2020@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-08-27 05:42:03 +00:00
Paul E. Murphy
a0948493ac debug/elf: fix reloc number of R_PPC64_SECTOFF_LO_DS
R_PPC64_SECTOFF_LO_DS is defined as reloc 62 on all PPC64 ELF ABIs.

Fixes #53356

Change-Id: I5fabf6be32f3310c5aed47d4d654e05fb7bc9de0
Reviewed-on: https://go-review.googlesource.com/c/go/+/411915
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-27 02:36:28 +00:00
cuiweixie
acabf87127 reflect: add Value.{Comparable,Equal}
For #46746

Change-Id: I879124974cdb55932cd9d07d3b384d49d5059857
Reviewed-on: https://go-review.googlesource.com/c/go/+/423794
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-08-26 20:56:48 +00:00
Joe Tsai
bc1d0d8eb1 reflect: add Value.SetZero
The v.SetZero method is a faster equivalent of v.Set(Zero(v.Type())).

Performance:

	                     Direct         CachedZero     NewZero
	SetZero/Bool         2.20ns ± 0%    8.97ns ± 5%    11.4ns ± 1%
	SetZero/Int          3.08ns ± 1%    9.06ns ± 1%    11.5ns ± 0%
	SetZero/Uint         2.88ns ± 1%    9.04ns ± 1%    11.7ns ± 5%
	SetZero/Float        2.65ns ± 2%    9.05ns ± 1%    11.5ns ± 1%
	SetZero/Complex      2.68ns ± 3%    9.31ns ± 1%    11.7ns ± 1%
	SetZero/Array        6.69ns ± 4%    9.32ns ± 1%    11.8ns ± 1%
	SetZero/Chan         3.31ns ± 1%    6.19ns ± 1%    8.20ns ± 1%
	SetZero/Func         3.32ns ± 1%    6.20ns ± 0%    8.24ns ± 1%
	SetZero/Interface    2.66ns ± 1%    9.31ns ± 1%    11.8ns ± 1%
	SetZero/Map          3.31ns ± 1%    6.21ns ± 2%    8.19ns ± 1%
	SetZero/Pointer      3.30ns ± 1%    6.22ns ± 1%    8.17ns ± 1%
	SetZero/Slice        2.90ns ± 4%    9.13ns ± 1%    11.6ns ± 1%
	SetZero/String       3.11ns ± 1%    9.30ns ± 1%    11.8ns ± 2%
	SetZero/Struct       6.37ns ± 1%    9.18ns ± 4%    11.5ns ± 1%

where:

	* Direct is measuring Value.SetZero
	* CachedZero is measuring Value.Set with a cached Zero value
	* NewZero is measuring Value.Set with a new Zero value

Fixes #52376

Change-Id: I793ca723aa97627824c5f5b356b2da30c8e46d71
Reviewed-on: https://go-review.googlesource.com/c/go/+/411476
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Dan Kortschak <dan@kortschak.io>
2022-08-26 17:15:08 +00:00
Paschalis Tsilias
95a786da12 path/filepath, io/fs: add SkipAll
Fixes #47209

Change-Id: If75b0dd38f2c30a23517205d80c7a6683a5c921c
Reviewed-on: https://go-review.googlesource.com/c/go/+/363814
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-08-25 18:50:37 +00:00
hopehook
396b153ec4 testing: add Elapsed method to testing.B
Elapsed returns the measured elapsed time of the benchmark,
but does not change the running state of the timer.

Fixes #43620.

Change-Id: Idd9f64c4632518eec759d2ffccbf0050d84fcc03
Reviewed-on: https://go-review.googlesource.com/c/go/+/420254
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: hopehook <hopehook@qq.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-08-25 17:58:32 +00:00
Axel Wagner
7f632f76db encoding/xml: add (*Encoder).Close
Flush can not check for unclosed elements, as more data might be encoded
after Flush is called. Close implicitly calls Flush and also checks that
all opened elements are closed as well.

Fixes #53346

Change-Id: I889b9f5ae54e5dfabb9e6948d96c5ed7bc1110f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/424777
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-08-23 18:24:30 +00:00
hopehook
dc8e2a6a8e io: add OffsetWriter, NewOffsetWriter
Offsetwriter refers to the design of SectionReader and removes
the section parameter n.

Since the size of the written data is determined by the user,
we cannot know where the end offset of the original data is.
The offset of SeekEnd is not valid in Seek method.

Fixes #45899.

Change-Id: I9d9445aecfa0dd4fc5168f2f65e1e3055c201b45
Reviewed-on: https://go-review.googlesource.com/c/go/+/406776
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-08-19 17:03:55 +00:00
qmuntal
48297f1fb1 unicode/utf16: add AppendRune
AppendRune appends the UTF-16 encoding of a rune to a []uint16.

    BenchmarkEncodeValidASCII-12                24.61ns 16B 1allocs
    BenchmarkEncodeValidJapaneseChars-12        18.79ns 8B  1allocs
    BenchmarkAppendRuneValidASCII-12            6.826ns 0B  0allocs
    BenchmarkAppendRuneValidJapaneseChars-12    3.547ns 0B  0allocs

The ASCII case is written to be inlineable.

Fixes #51896

Change-Id: I593b1029f603297ef6e80e036f2fee2a0938d38d
Reviewed-on: https://go-review.googlesource.com/c/go/+/409054
TryBot-Result: Gopher Robot <gobot@golang.org>
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: Joedian Reid <joedian@golang.org>
2022-08-19 16:45:08 +00:00
Kir Kolyshkin
3204e62dd1 syscall: add new CLONE_ flags for Linux
The constants for these were auto-generated from the C includes
into zerrors_linux* files quite some time ago. The generator is
currently broken, but some new flags need to be added nevertheless.

As the flags won't change and the values are the same for all
architectures, we can just define them statically (as it's already
done in the runtime package):

 - remove the CLONE_* constants from zerrors_linux_*.go;
 - patch mkerrors.sh to not generate CLONE_ constants
   (in case it will be fixed and used in the future);
 - add the constants and some comments about them to exec_linux.go,
   using Linux v5.17 include/uapi/sched.h as the ultimate source.

This adds the following new flags:

 - CLONE_CLEAR_SIGHAND
 - CLONE_INTO_CGROUP
 - CLONE_NEWCGROUP
 - CLONE_NEWTIME
 - CLONE_PIDFD

For #51246.

Change-Id: I0c635723926218bd403d37e113ee4d62194463a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/407574
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-08-19 16:12:50 +00:00
Russ Cox
57d05512fe crypto/subtle: add XORBytes
Export cipher.xorBytes as subtle.XORBytes, for proposal #53021,
to provide fast XOR to cryptography libraries outside crypto/cipher.

Along with the move, implement the alignment check TODO
in xor_generic.go, so that systems with neither unaligned
accesses nor custom assembly can still XOR a word at a time
in word-based algorithms like GCM. This removes the need
for the separate cipher.xorWords.

Fixes #53021.

Change-Id: I58f80a922f1cff671b5ebc6168eb046e702b5a4c
Reviewed-on: https://go-review.googlesource.com/c/go/+/421435
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2022-08-17 18:47:33 +00:00
Damien Neil
a55793835f net/http/httputil: add ReverseProxy.Rewrite
Add a new Rewrite hook to ReverseProxy, superseding the Director hook.

Director does not distinguish between the inbound and outbound request,
which makes it possible for headers added by Director to be inadvertently
removed before forwarding if they are listed in the inbound request's
Connection header. Rewrite accepts a value containing the inbound
and outbound requests, with hop-by-hop headers already removed from
the outbound request, avoiding this problem.

ReverseProxy's appends the client IP to the inbound X-Forwarded-For
header by default. Users must manually delete untrusted X-Forwarded-For
values. When used with a Rewrite hook, ReverseProxy now strips
X-Forwarded-* headers by default.

NewSingleHostReverseProxy creates a proxy that does not rewrite the
Host header of inbound requests. Changing this behavior is
cumbersome, as it requires wrapping the Director function created
by NewSingleHostReverseProxy. The Rewrite hook's ProxyRequest
parameter provides a SetURL method that provides equivalent
functionality to NewSingleHostReverseProxy, rewrites the Host
header by default, and can be more easily extended with additional
customizations.

Fixes #28168.
Fixes #50580.
Fixes #53002.

Change-Id: Ib84e2fdd1d52c610e3887af66f517d4a74e594d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/407214
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
2022-08-16 20:01:36 +00:00
Changkun Ou
68005592b3 strings, bytes: add CutPrefix and CutSuffix
Fixes #42537

Change-Id: Ie03c2614ffee30ebe707acad6b9f6c28fb134a45
Reviewed-on: https://go-review.googlesource.com/c/go/+/407176
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Changkun Ou <mail@changkun.de>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-08-16 19:48:39 +00:00
Alan Donovan
a45bbeae33 go/token: add (*FileSet).RemoveFile(*File) method
The design of FileSet encourages it to be used as a global variable.
Each call to AddFile consumes about 3KB, that is never returned,
even after an application no longer cares about the File.
This change adds a RemoveFile method that a long-running application
can use to release a File that is no longer needed, saving memory.

Fixes golang/go#53200

Change-Id: Ifd34d650fe0d18b1395f922a4cd02a535afbe560
Reviewed-on: https://go-review.googlesource.com/c/go/+/410114
Auto-Submit: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-08-16 16:27:35 +00:00
Martin Möhrmann
7b45edb450 bytes: add Clone function
The new Clone function returns a copy of b[:len(b)]
for the input byte slice b.
The result may have additional unused capacity.
Clone(nil) returns nil.

Fixes #45038

Change-Id: I0469a202d77a7b491f1341c08915d07ddd1f0300
Reviewed-on: https://go-review.googlesource.com/c/go/+/359675
Run-TryBot: Martin Möhrmann <martin@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-08-15 19:17:20 +00:00
Alexander Yastrebov
05ff045dfe net/http: add Server.DisableOptionsHandler for custom handling of OPTIONS *
Fixes #41773

Change-Id: I432ad5410d5e3bb0aff3a6e0eea6906ab1b214e2
GitHub-Last-Rev: 57d1ee249d
GitHub-Pull-Request: golang/go#49014
Reviewed-on: https://go-review.googlesource.com/c/go/+/356410
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: hopehook <hopehook@qq.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-15 18:57:35 +00:00
Filippo Valsorda
d88d91e32e crypto/ecdh: new package
We use crypto/internal/edwards25519/field to implement X25519 directly,
so that golang.org/x/crypto/curve25519 can be dropped from the src
module dependencies, and eventually replaced with a crypto/ecdh wrapper,
removing the need to keep golang.org/x/crypto/curve25519/internal/field
in sync with crypto/internal/edwards25519/field.

In crypto/internal/nistec, we add BytesX to serialize only the x
coordinate, which we'll need for the horrible ECDSA x-coord-to-scalar
operation, too.

In crypto/tls, we replace the ECDHE implementation with crypto/ecdh,
dropping the X25519 special cases and related scaffolding.

Finally, FINALLY, we deprecate the ~white whale~ big.Int-based APIs of
the crypto/elliptic package.   •_•)   ( •_•)>⌐■-■   (⌐■_■)

Fixes #52182
Fixes #34648
Fixes #52221

Change-Id: Iccdda210319cc892e96bb28a0e7b7123551982c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/398914
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-12 00:03:39 +00:00
WANG Xuerui
0337fc7e0e debug/elf: add new-style LoongArch reloc types
LoongArch ELF psABI spec update:
https://github.com/loongson/LoongArch-Documentation/pull/57

Corresponding binutils implementation:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6d13722a97cee3fd397e116bde3bcedbb1e220be
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9801120721c3a702ce3bd50433ef920f92a83502

For #54222

Change-Id: I51e72294205847a69c01d741a3126248f7a7e41c
Reviewed-on: https://go-review.googlesource.com/c/go/+/420982
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
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: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
2022-08-11 19:32:40 +00:00
Joe Tsai
0981d9fff1 time: add DateTime, DateOnly, and TimeOnly
Add named constants for the 3rd, 4th, and 13th most popular formats.

Fixes #52746

Change-Id: I7ce92e44dcae18c089124f1d6f5bc2d6359d436c
Reviewed-on: https://go-review.googlesource.com/c/go/+/412495
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
2022-08-09 14:33:24 +00:00
Meng Zhuo
4884599a54 debug/pe: add IMAGE_FILE_MACHINE_RISCV{32,64,128}
https://docs.microsoft.com/en-us/windows/win32/debug/pe-format

Fixes #54251

Change-Id: I024130fd9f55b2f1c0439baacdc56cdbc3315215
Reviewed-on: https://go-review.googlesource.com/c/go/+/421357
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
2022-08-09 01:21:43 +00:00
Rob Pike
d75e186e2c fmt: add a function to recover the original format string given a State
Sometimes when implementing a Formatter it's helpful to use the fmt
package without invoking the formatter. This new function, FormatString,
makes that easier in some cases by recreating the original formatting
directive (such as "%3.2f") that caused Formatter.Format to be
called.

The original Formatter interface is probably not what we would
design today, but we're stuck with it. FormatString, although it
takes a State as an argument, compensates by making Formatter a
little more flexible.

The State does not include the verb so (unlike in the issue), we
must provide it explicitly in the call to FormatString. Doing it there
minimizes allocations by returning the complete format string.

Fixes #51668
Updates #51195

Change-Id: Ie31c8256515864b2f460df45fbd231286b8b7a28
Reviewed-on: https://go-review.googlesource.com/c/go/+/400875
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
2022-08-06 09:19:31 +00:00
Guoqi Chen
6a7c64fde5 debug/pe: add IMAGE_FILE_MACHINE_LOONGARCH{64,32}
Related: https://github.com/MicrosoftDocs/win32/pull/1067

Change-Id: I946253f217a5c616ae4a19be44634000cba5020e
Reviewed-on: https://go-review.googlesource.com/c/go/+/411616
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2022-06-29 22:29:34 +00:00
Russ Cox
d3ffff2790 api: correct debug/pe issue number for Go 1.19 changes
It was #51868 not #51686.

For #53310.

Change-Id: I2cf28ca4de65e7030fdbd05e7f32fe42c8f3ca0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/414515
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-06-28 13:01:41 +00:00
Cherry Mui
840e99ed74 api: promote next to go1.19
Change-Id: I3d80f0691b399fe4ee4a0d161b5cee907ae6b94f
Reviewed-on: https://go-review.googlesource.com/c/go/+/411394
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-09 15:15:48 +00:00
Cherry Mui
80f86f706d api/next: minor reformat
Add newline endings to files without them. Delete empty lines. So
it is consistent and easier to put them together.

Change-Id: I84e6b7a1fe59e9f4d7f00f61539f6449f19a5d40
Reviewed-on: https://go-review.googlesource.com/c/go/+/411121
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-06-08 23:36:05 +00:00
Russ Cox
f8a53df314 io: revert: add an Err field to LimitedReader
We are having a hard time deciding the exact semantics
of the Err field, and we need to ship the beta.
So revert the Err field change; it can wait for Go 1.20.

For #51115.

This reverts CL 396215.

Change-Id: I7719386567d3da10a614058a11f19dbccf304b4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/410133
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
2022-06-04 14:00:38 +00:00
Robert Findley
1170771074 go/types, types2: set an origin object for vars and funcs
Historically, Objects in go/types were canonical, meaning each entity
was represented by exactly one variable and could thus be identified by
its address. With object instantiation this is no longer the case: Var
and Func objects must be copied to hold substituted type information,
and there may be more than one Var or Func variable representing the
same source-level entity.

This CL adds Origin methods to *Var and *Func, so users can efficiently
navigate to the corresponding canonical object on the generic type.

Fixes #51682

Change-Id: Ia49e15bd6515e1db1eb3b09b88ba666659601316
Reviewed-on: https://go-review.googlesource.com/c/go/+/395535
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-17 21:28:43 +00:00
Rob Pike
668041ef66 fmt: add Append, Appendln, Appendf
These are straightforward variants of the existing Sprintf etc.,
but append the resulting bytes to a provided buffer rather than
returning a string.

Internally, there is potentially some allocation because the package
uses a pool of buffers to build its output. We make no attempt to
override that, so the result is first printed into the pool and
then copied to the output. Since it is a managed pool, asymptotically
there should be no extra allocation.

Fixes #47579

RELNOTE=yes

Change-Id: Icef797f9b6f0c84d03e7035d95c06cdb819e2649
Reviewed-on: https://go-review.googlesource.com/c/go/+/406177
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-17 18:55:46 +00:00
hopehook
41b9d8c75e time: add Time.ZoneBounds
The method Location.lookup returns the "start" and "end" times bracketing seconds when that zone is in effect.

This CL does these things:

1. Exported the "start" and "end" times as time.Time form
2. Keep the "Location" of the returned times be the same as underlying time

Fixes #50062.

Change-Id: I88888a100d0fc68f4984a85c75a85a83aa3e5d80
Reviewed-on: https://go-review.googlesource.com/c/go/+/405374
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-17 03:26:28 +00:00
hopehook
3474cd4eee encoding/csv: add Reader.InputOffset method
Fixes #43401.

Change-Id: I2498e77e41d845130d95012bc8623bfb29c0dda1
Reviewed-on: https://go-review.googlesource.com/c/go/+/405675
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-05-14 04:25:13 +00:00
Carl Johnson
fd6ef06296 io: add an Err field to LimitedReader
Fixes #51115

Change-Id: I3c5296e4adc71c1c1b1808a45abd4801ae43465a
GitHub-Last-Rev: 4c197acd51
GitHub-Pull-Request: golang/go#51990
Reviewed-on: https://go-review.googlesource.com/c/go/+/396215
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
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: Ian Lance Taylor <iant@google.com>
2022-05-04 20:06:32 +00:00
Russ Cox
ffe48e00ad sync/atomic: add typed atomic values
These implementations will inline to the lower-level primitives,
but they hide the underlying values so that all accesses are
forced to use the atomic APIs. They also allow the use of shorter
names (methods instead of functions) at call sites, making code
more readable.

Pointer[T] also avoids conversions using unsafe.Pointer at call sites.

Discussed on #47141.
See also https://research.swtch.com/gomm for background.

Fixes #50860.

Change-Id: I0b178ee0c7747fa8985f8e48cd7b01063feb7dcc
Reviewed-on: https://go-review.googlesource.com/c/go/+/381317
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-04 18:05:18 +00:00
Michael Anthony Knyszek
f01c20bf2b runtime/debug: export SetMemoryLimit
This change also adds an end-to-end test for SetMemoryLimit as a
testprog.

Fixes #48409.

Change-Id: I102d64acf0f36a43ee17b7029e8dfdd1ee5f057d
Reviewed-on: https://go-review.googlesource.com/c/go/+/397018
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-03 15:14:09 +00:00
Russ Cox
349cc83389 os/exec: return error when PATH lookup would use current directory
CL 381374 was reverted because x/sys/execabs broke.

This CL reapplies CL 381374, but adding a lookPathErr error
field back, for execabs to manipulate with reflect.
That field will just be a bit of scar tissue in this package forever,
to keep old code working with new toolchains.

CL 403256 fixes x/sys/execabs's test to be ready for the change.
Older versions of x/sys/execabs will keep working
(that is, will keep rejecting what they should reject),
but they will return a slightly different error from LookPath
without that CL, and the test fails because of the different
error text.

For #43724.

This reverts commit f2b674756b.

Change-Id: Iee55f8cd9939e1bd31e5cbdada50681cdc505117
Reviewed-on: https://go-review.googlesource.com/c/go/+/403274
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-02 14:54:05 +00:00
Bryan Mills
f2b674756b Revert "os/exec: return error when PATH lookup would use current directory"
This reverts CL 381374.

Reason for revert: broke tests for x/sys/execabs.

Updates #43724.
Updates #43947.

Change-Id: I9eb3adb5728dead66dbd20f6afe1e7a77e2a26f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/403058
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-04-29 23:04:17 +00:00
Russ Cox
3ce203db80 os/exec: return error when PATH lookup would use current directory
Following discussion on #43724, change os/exec to take the
approach of golang.org/x/sys/execabs, refusing to respect
path entries mentioning relative paths by default.

Code that insists on being able to find executables in relative
directories in the path will need to add a couple lines to override the error.

See the updated package docs in exec.go for more details.

Fixes #43724.
Fixes #43947.

Change-Id: I73c1214f322b60b4167a23e956e933d50470fe13
Reviewed-on: https://go-review.googlesource.com/c/go/+/381374
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-04-29 20:16:31 +00:00
Carl Johnson
a5d61be040 net/http: add MaxBytesError
Fixes #30715

Change-Id: Ia3712d248b6dc86abef71ccea6e705a571933d53
GitHub-Last-Rev: 6ae68402a5
GitHub-Pull-Request: golang/go#49359
Reviewed-on: https://go-review.googlesource.com/c/go/+/361397
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: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-25 23:36:50 +00:00
Ian Lance Taylor
0bf545e51f regexp/syntax: rename ErrInvalidDepth to ErrNestingDepth
The proposal accepted the name ErrNestingDepth.

For #51684

Change-Id: I702365f19e5e1889dbcc3c971eecff68e0b08727
Reviewed-on: https://go-review.googlesource.com/c/go/+/401854
Run-TryBot: Ian Lance Taylor <iant@golang.org>
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>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-04-22 22:35:03 +00:00
Ian Lance Taylor
575fd8817a regexp: change ErrInvalidDepth message to match proposal
Also update the file in $GOROOT/api/next to use proposal number.

For #51684

Change-Id: I28bfa6bc1cee98a17b13da196d41cda34d968bb0
Reviewed-on: https://go-review.googlesource.com/c/go/+/401076
Reviewed-by: Rob Pike <r@golang.org>
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>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-04-22 00:10:17 +00:00
Bryan C. Mills
b34838913d os/exec: set PWD implicitly if Dir is non-empty and Env is nil
Fixes #50599.

Change-Id: I4e5dbb3972cdf21ede049567bfb98f2c992c5849
Reviewed-on: https://go-review.googlesource.com/c/go/+/401340
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-04-21 17:37:05 +00:00
Joe Tsai
35a92f92bd encoding/binary: add AppendVarint AppendUvarint
This adds a straight-forward implementation of the functionality.
A more performant version could be added that unrolls the loop
as is done in google.golang.org/protobuf/encoding/protowire,
but usages that demand high performance can use that package instead.

Fixes #51644

Change-Id: I9d3b615a60cdff47e5200e7e5d2276adf4c93783
Reviewed-on: https://go-review.googlesource.com/c/go/+/400176
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-15 01:19:37 +00:00
Roland Shoemaker
9298f604f4 crypto/x509: add CertPool.Clone
Export the previously private method copy as Clone.

Fixes #35044

Change-Id: I5403d6a3b9f344c980c1c89a6823e1a49dcda26b
Reviewed-on: https://go-review.googlesource.com/c/go/+/400175
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-13 19:04:59 +00:00
Russ Cox
27b7b1fa19 go/doc: use go/doc/comment
[This CL is part of a sequence implementing the proposal #51082.
The design doc is at https://go.dev/s/godocfmt-design.]

Use go/doc/comment to implement the existing go/doc comment APIs,
as well as adding new APIs more tailored to the new world.

For #51082.

Change-Id: I05b97ecedbf7cf7b8dede7ace6736ed6d89204a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/384265
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-11 16:31:52 +00:00
Russ Cox
6eceabf119 go/doc/comment: parse and print headings
[This CL is part of a sequence implementing the proposal #51082.
The design doc is at https://go.dev/s/godocfmt-design.]

Implement both old-style and new-style headings, like:

	Text here.

	Old Style Heading

	More text here.

	# New Style Heading

	More text here.

For #51082.

Change-Id: I0d735782d0d345794fc2d4e1bdaa0251b8d4bba2
Reviewed-on: https://go-review.googlesource.com/c/go/+/397284
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2022-04-11 16:31:46 +00:00
Russ Cox
910a33a0ee go/doc/comment: parse and print doc links
[This CL is part of a sequence implementing the proposal #51082.
The design doc is at https://go.dev/s/godocfmt-design.]

Implement parsing and printing of documentation links,
like [math.Sqrt] or [*golang.org/x/text/runes.Set].

For #51082.

Change-Id: I1cc73afbac1c6568773f921ce4b73e52f17acef6
Reviewed-on: https://go-review.googlesource.com/c/go/+/397281
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-11 16:31:42 +00:00