Skip to content
Snippets Groups Projects
Commit 817d7bdc authored by Carlos Amedee's avatar Carlos Amedee
Browse files

[release-branch.go1.24] all: merge master (91180600) into release-branch.go1.24

Merge List:

+ 2024-12-12 91180600 builtin: document clear is a no-op if its argument's value is nil
+ 2024-12-11 077d5190 internal/poll: in SendFile treat ENOTSUP like EOPNOTSUPP
+ 2024-12-11 fafd4477 cmd/cgo: use full prototype for main in C code

Change-Id: I4c4941eff4a1e842920eb9be47d28351af0e4c36
parents 14bb1e11 91180600
No related branches found
No related tags found
No related merge requests found
...@@ -247,7 +247,7 @@ func imag(c ComplexType) FloatType ...@@ -247,7 +247,7 @@ func imag(c ComplexType) FloatType
// to the zero value of the respective element type. If the argument // to the zero value of the respective element type. If the argument
// type is a type parameter, the type parameter's type set must // type is a type parameter, the type parameter's type set must
// contain only map or slice types, and clear performs the operation // contain only map or slice types, and clear performs the operation
// implied by the type argument. // implied by the type argument. If t is nil, clear is a no-op.
func clear[T ~[]Type | ~map[Type]Type1](t T) func clear[T ~[]Type | ~map[Type]Type1](t T)
// The close built-in function closes a channel, which must be either // The close built-in function closes a channel, which must be either
......
...@@ -796,7 +796,7 @@ Instead, the build process generates an object file using dynamic ...@@ -796,7 +796,7 @@ Instead, the build process generates an object file using dynamic
linkage to the desired libraries. The main function is provided by linkage to the desired libraries. The main function is provided by
_cgo_main.c: _cgo_main.c:
int main() { return 0; } int main(int argc, char **argv) { return 0; }
void crosscall2(void(*fn)(void*), void *a, int c, uintptr_t ctxt) { } void crosscall2(void(*fn)(void*), void *a, int c, uintptr_t ctxt) { }
uintptr_t _cgo_wait_runtime_init_done(void) { return 0; } uintptr_t _cgo_wait_runtime_init_done(void) { return 0; }
void _cgo_release_context(uintptr_t ctxt) { } void _cgo_release_context(uintptr_t ctxt) { }
......
...@@ -59,7 +59,7 @@ func (p *Package) writeDefs() { ...@@ -59,7 +59,7 @@ func (p *Package) writeDefs() {
// Write C main file for using gcc to resolve imports. // Write C main file for using gcc to resolve imports.
fmt.Fprintf(fm, "#include <stddef.h>\n") // For size_t below. fmt.Fprintf(fm, "#include <stddef.h>\n") // For size_t below.
fmt.Fprintf(fm, "int main() { return 0; }\n") fmt.Fprintf(fm, "int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) { return 0; }\n")
if *importRuntimeCgo { if *importRuntimeCgo {
fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*) __attribute__((unused)), void *a __attribute__((unused)), int c __attribute__((unused)), size_t ctxt __attribute__((unused))) { }\n") fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*) __attribute__((unused)), void *a __attribute__((unused)), int c __attribute__((unused)), size_t ctxt __attribute__((unused))) { }\n")
fmt.Fprintf(fm, "size_t _cgo_wait_runtime_init_done(void) { return 0; }\n") fmt.Fprintf(fm, "size_t _cgo_wait_runtime_init_done(void) { return 0; }\n")
......
...@@ -110,12 +110,20 @@ func sendFile(dstFD *FD, src int, offset *int64, size int64) (written int64, err ...@@ -110,12 +110,20 @@ func sendFile(dstFD *FD, src int, offset *int64, size int64) (written int64, err
// Retry. // Retry.
case syscall.ENOSYS, syscall.EOPNOTSUPP, syscall.EINVAL: case syscall.ENOSYS, syscall.EOPNOTSUPP, syscall.EINVAL:
// ENOSYS indicates no kernel support for sendfile. // ENOSYS indicates no kernel support for sendfile.
// EINVAL indicates a FD type which does not support sendfile. // EINVAL indicates a FD type that does not support sendfile.
// //
// On Linux, copy_file_range can return EOPNOTSUPP when copying // On Linux, copy_file_range can return EOPNOTSUPP when copying
// to a NFS file (issue #40731); check for it here just in case. // to a NFS file (issue #40731); check for it here just in case.
return written, err, written > 0 return written, err, written > 0
default: default:
// We want to handle ENOTSUP like EOPNOTSUPP.
// It's a pain to put it as a switch case
// because on Linux systems ENOTSUP == EOPNOTSUPP,
// so the compiler complains about a duplicate case.
if err == syscall.ENOTSUP {
return written, err, written > 0
}
// Not a retryable error. // Not a retryable error.
return written, err, true return written, err, true
} }
......
// Copyright 2024 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.
//go:build unix
package net
import (
"internal/testpty"
"io"
"os"
"sync"
"syscall"
"testing"
)
// Issue 70763: test that we don't fail on sendfile from a tty.
func TestCopyFromTTY(t *testing.T) {
pty, ttyName, err := testpty.Open()
if err != nil {
t.Skipf("skipping test because pty open failed: %v", err)
}
defer pty.Close()
// Use syscall.Open so that the tty is blocking.
ttyFD, err := syscall.Open(ttyName, syscall.O_RDWR, 0)
if err != nil {
t.Skipf("skipping test because tty open failed: %v", err)
}
defer syscall.Close(ttyFD)
tty := os.NewFile(uintptr(ttyFD), "tty")
defer tty.Close()
ln := newLocalListener(t, "tcp")
defer ln.Close()
ch := make(chan bool)
const data = "data\n"
var wg sync.WaitGroup
defer wg.Wait()
wg.Add(1)
go func() {
defer wg.Done()
conn, err := ln.Accept()
if err != nil {
t.Error(err)
return
}
defer conn.Close()
buf := make([]byte, len(data))
if _, err := io.ReadFull(conn, buf); err != nil {
t.Error(err)
}
ch <- true
}()
conn, err := Dial("tcp", ln.Addr().String())
if err != nil {
t.Fatal(err)
}
defer conn.Close()
wg.Add(1)
go func() {
defer wg.Done()
if _, err := pty.Write([]byte(data)); err != nil {
t.Error(err)
}
<-ch
if err := pty.Close(); err != nil {
t.Error(err)
}
}()
lr := io.LimitReader(tty, int64(len(data)))
if _, err := io.Copy(conn, lr); err != nil {
t.Error(err)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment