mirror of
https://github.com/apple/swift.git
synced 2026-11-01 23:11:50 +01:00
In Swift 6 mode these were diagnosed as shared mutable global state (#75601). Mark them nonisolated(unsafe) across the libc overlays. Glibc/Musl/Android/WASI define them as computed vars backed by the _swift_stdlib_std* shims; Platform.swift covers OpenBSD, FreeBSD/PS4, and Windows. They are OpaquePointer where FILE is opaque (Musl, WASI, Android, OpenBSD) and UnsafeMutablePointer<FILE> elsewhere. Adds the StdioSendable regression test.
54 lines
1.5 KiB
Swift
54 lines
1.5 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2026 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// RUN: %target-swift-frontend -swift-version 6 -emit-sil -o /dev/null -verify %s
|
|
// REQUIRES: concurrency
|
|
// REQUIRES: OS=linux-gnu || OS=linux-musl || OS=linux-android || OS=linux-androideabi || OS=wasip1 || OS=openbsd || OS=freebsd
|
|
|
|
// Regression test: stdin/stdout/stderr must be usable from concurrent contexts
|
|
// on Linux, Android, WASI, OpenBSD, and FreeBSD. They are computed vars marked
|
|
// nonisolated(unsafe): get-only on Linux/Android/WASI/OpenBSD, and get/set on
|
|
// FreeBSD. Either way they must not trip "global shared mutable state" errors in
|
|
// Swift 6 mode.
|
|
|
|
#if canImport(Glibc)
|
|
import Glibc
|
|
#elseif canImport(Musl)
|
|
import Musl
|
|
#elseif canImport(Android)
|
|
import Android
|
|
#elseif canImport(WASILibc)
|
|
import WASILibc
|
|
#else
|
|
#error("Unsupported platform")
|
|
#endif
|
|
|
|
func useFromAsyncFunction() async {
|
|
_ = stdin
|
|
_ = stdout
|
|
_ = stderr
|
|
}
|
|
|
|
actor StdioConsumer {
|
|
func use() {
|
|
_ = stdin
|
|
_ = stdout
|
|
_ = stderr
|
|
}
|
|
}
|
|
|
|
nonisolated func useFromNonisolatedContext() {
|
|
_ = stdin
|
|
_ = stdout
|
|
_ = stderr
|
|
}
|