mirror of
https://github.com/apple/swift-system
synced 2026-11-26 04:57:54 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94090e1c5c | ||
|
|
b6a7776360 | ||
|
|
0ea6743c17 | ||
|
|
086219bf62 | ||
|
|
11d9d4a78e | ||
|
|
0c11feadd4 | ||
|
|
2410aed341 | ||
|
|
9ec41a667c | ||
|
|
9226c72b3a | ||
|
|
d9d138a88e | ||
|
|
13ad3fe4ac | ||
|
|
2610d66a52 | ||
|
|
e0d9cb0638 | ||
|
|
c4fef8b59a | ||
|
|
f97a80426c | ||
|
|
e5198c2b2d | ||
|
|
9a1530813e | ||
|
|
b63d24d465 | ||
|
|
a717516d69 | ||
|
|
d89ca1d511 | ||
|
|
d32abd8c6e | ||
|
|
d75acaac3a | ||
|
|
5fedb102b5 | ||
|
|
960067d31a | ||
|
|
0bb855ac35 | ||
|
|
3f68d42246 | ||
|
|
c72c758953 | ||
|
|
a067a0751a | ||
|
|
e1191b2ba5 | ||
|
|
c7eaf63462 | ||
|
|
4f5b5fb40d | ||
|
|
5059730d24 | ||
|
|
8de80270cb |
No files matched your search
@@ -9,7 +9,38 @@ jobs:
|
|||||||
name: Test
|
name: Test
|
||||||
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
|
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
|
||||||
with:
|
with:
|
||||||
linux_exclude_swift_versions: '[{"swift_version": "5.8"}]'
|
linux_os_versions: '["jammy", "focal"]'
|
||||||
|
enable_macos_checks: true
|
||||||
|
# FIXME: https://github.com/swiftlang/github-workflows/pull/140
|
||||||
|
# Xcode 16.0 and 16.1 are not actually available
|
||||||
|
macos_exclude_xcode_versions: |
|
||||||
|
[
|
||||||
|
{"xcode_version": "16.0"},
|
||||||
|
{"xcode_version": "16.1"},
|
||||||
|
]
|
||||||
|
swift_flags: "-Xbuild-tools-swiftc -DSYSTEM_CI"
|
||||||
|
enable_linux_static_sdk_build: true
|
||||||
|
enable_wasm_sdk_build: true
|
||||||
|
|
||||||
|
build-abi-stable:
|
||||||
|
name: Build ABI Stable
|
||||||
|
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
|
||||||
|
with:
|
||||||
|
enable_linux_checks: false
|
||||||
|
enable_macos_checks: true
|
||||||
|
enable_windows_checks: false
|
||||||
|
# Only build
|
||||||
|
macos_build_command: "xcrun swift build --build-tests"
|
||||||
|
# FIXME: https://github.com/swiftlang/github-workflows/pull/140
|
||||||
|
# Xcode 16.0 and 16.1 are not actually available
|
||||||
|
macos_exclude_xcode_versions: |
|
||||||
|
[
|
||||||
|
{"xcode_version": "16.0"},
|
||||||
|
{"xcode_version": "16.1"},
|
||||||
|
]
|
||||||
|
# Enable availability to match ABI stable verion of system.
|
||||||
|
swift_flags: "-Xbuild-tools-swiftc -DSYSTEM_CI -Xbuild-tools-swiftc -DSYSTEM_ABI_STABLE"
|
||||||
|
|
||||||
soundness:
|
soundness:
|
||||||
name: Soundness
|
name: Soundness
|
||||||
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
|
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
|
||||||
|
|||||||
+81
-3
@@ -12,11 +12,71 @@
|
|||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let cSettings: [CSetting] = [
|
struct Available {
|
||||||
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
|
var name: String
|
||||||
|
var version: String
|
||||||
|
var osAvailability: String
|
||||||
|
var sourceAvailability: String
|
||||||
|
|
||||||
|
init(
|
||||||
|
_ version: String,
|
||||||
|
_ osAvailability: String
|
||||||
|
) {
|
||||||
|
self.name = "System"
|
||||||
|
self.version = version
|
||||||
|
self.osAvailability = osAvailability
|
||||||
|
self.sourceAvailability = "macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, visionOS 1.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
var swiftSetting: SwiftSetting {
|
||||||
|
#if SYSTEM_ABI_STABLE
|
||||||
|
// Use availability matching Darwin API.
|
||||||
|
let availability = self.osAvailability
|
||||||
|
#else
|
||||||
|
// Use availability matching SwiftPM default.
|
||||||
|
let availability = self.sourceAvailability
|
||||||
|
#endif
|
||||||
|
return .enableExperimentalFeature(
|
||||||
|
"AvailabilityMacro=\(self.name) \(version):\(availability)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let availability: [Available] = [
|
||||||
|
Available("0.0.1", "macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0"),
|
||||||
|
|
||||||
|
Available("0.0.2", "macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0"),
|
||||||
|
|
||||||
|
Available("0.0.3", "macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4"),
|
||||||
|
Available("1.1.0", "macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4"),
|
||||||
|
|
||||||
|
Available("1.1.1", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
|
||||||
|
Available("1.2.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
|
||||||
|
|
||||||
|
Available("1.2.1", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
|
||||||
|
Available("1.3.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
|
||||||
|
|
||||||
|
Available("1.3.1", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.0"),
|
||||||
|
Available("1.3.2", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.0"),
|
||||||
|
Available("1.4.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.0"),
|
||||||
|
|
||||||
|
Available("1.4.1", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
|
||||||
|
Available("1.4.2", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
|
||||||
|
Available("1.5.0", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
|
||||||
|
Available("1.6.0", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
|
||||||
|
Available("1.6.1", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
|
||||||
]
|
]
|
||||||
|
|
||||||
let swiftSettings: [SwiftSetting] = [
|
let swiftSettingsAvailability = availability.map(\.swiftSetting)
|
||||||
|
|
||||||
|
#if SYSTEM_CI
|
||||||
|
let swiftSettingsCI: [SwiftSetting] = [
|
||||||
|
.unsafeFlags(["-require-explicit-availability=error"]),
|
||||||
|
]
|
||||||
|
#else
|
||||||
|
let swiftSettingsCI: [SwiftSetting] = []
|
||||||
|
#endif
|
||||||
|
|
||||||
|
let swiftSettings = swiftSettingsAvailability + swiftSettingsCI + [
|
||||||
.define(
|
.define(
|
||||||
"SYSTEM_PACKAGE_DARWIN",
|
"SYSTEM_PACKAGE_DARWIN",
|
||||||
.when(platforms: [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .visionOS])),
|
.when(platforms: [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .visionOS])),
|
||||||
@@ -25,6 +85,22 @@ let swiftSettings: [SwiftSetting] = [
|
|||||||
.enableExperimentalFeature("Lifetimes"),
|
.enableExperimentalFeature("Lifetimes"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
let cSettings: [CSetting] = [
|
||||||
|
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
|
||||||
|
]
|
||||||
|
|
||||||
|
#if SYSTEM_ABI_STABLE
|
||||||
|
let platforms: [SupportedPlatform] = [
|
||||||
|
.macOS("26"),
|
||||||
|
.iOS("26"),
|
||||||
|
.watchOS("26"),
|
||||||
|
.tvOS("26"),
|
||||||
|
.visionOS("26"),
|
||||||
|
]
|
||||||
|
#else
|
||||||
|
let platforms: [SupportedPlatform]? = nil
|
||||||
|
#endif
|
||||||
|
|
||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
let filesToExclude = ["CMakeLists.txt"]
|
let filesToExclude = ["CMakeLists.txt"]
|
||||||
#else
|
#else
|
||||||
@@ -39,6 +115,7 @@ let testsToExclude = ["IORequestTests.swift", "IORingTests.swift"]
|
|||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "swift-system",
|
name: "swift-system",
|
||||||
|
platforms: platforms,
|
||||||
products: [
|
products: [
|
||||||
.library(name: "SystemPackage", targets: ["SystemPackage"]),
|
.library(name: "SystemPackage", targets: ["SystemPackage"]),
|
||||||
],
|
],
|
||||||
@@ -63,3 +140,4 @@ let package = Package(
|
|||||||
cSettings: cSettings,
|
cSettings: cSettings,
|
||||||
swiftSettings: swiftSettings),
|
swiftSettings: swiftSettings),
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ To use the `SystemPackage` library in a SwiftPM project,
|
|||||||
add the following line to the dependencies in your `Package.swift` file:
|
add the following line to the dependencies in your `Package.swift` file:
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
.package(url: "https://github.com/apple/swift-system", from: "1.4.0"),
|
.package(url: "https://github.com/apple/swift-system", from: "1.6.1"),
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, include `"SystemPackage"` as a dependency for your executable target:
|
Finally, include `"SystemPackage"` as a dependency for your executable target:
|
||||||
@@ -41,7 +41,7 @@ Finally, include `"SystemPackage"` as a dependency for your executable target:
|
|||||||
let package = Package(
|
let package = Package(
|
||||||
// name, platforms, products, etc.
|
// name, platforms, products, etc.
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/apple/swift-system", from: "1.4.0"),
|
.package(url: "https://github.com/apple/swift-system", from: "1.6.1"),
|
||||||
// other dependencies
|
// other dependencies
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
@@ -87,7 +87,7 @@ The following table maps existing package releases to their minimum required Swi
|
|||||||
| Package version | Swift version | Xcode release |
|
| Package version | Swift version | Xcode release |
|
||||||
| ----------------------- | --------------- | ------------- |
|
| ----------------------- | --------------- | ------------- |
|
||||||
| swift-system 1.3.x | >= Swift 5.8 | >= Xcode 14.3 |
|
| swift-system 1.3.x | >= Swift 5.8 | >= Xcode 14.3 |
|
||||||
| swift-system 1.4.x | >= Swift 5.9 | >= Xcode 15.0 |
|
| swift-system 1.4.x through 1.6.x | >= Swift 5.9 | >= Xcode 15.0 |
|
||||||
|
|
||||||
We'd like this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate. Accordingly, from time to time, new versions of this package require clients to upgrade to a more recent Swift toolchain release. (This allows the package to make use of new language/stdlib features, build on compiler bug fixes, and adopt new package manager functionality as soon as they are available.) Patch (i.e., bugfix) releases will not increase the required toolchain version, but any minor (i.e., new feature) release may do so.
|
We'd like this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate. Accordingly, from time to time, new versions of this package require clients to upgrade to a more recent Swift toolchain release. (This allows the package to make use of new language/stdlib features, build on compiler bug fixes, and adopt new package manager functionality as soon as they are available.) Patch (i.e., bugfix) releases will not increase the required toolchain version, but any minor (i.e., new feature) release may do so.
|
||||||
|
|
||||||
@@ -105,11 +105,13 @@ Before contributing, please read [CONTRIBUTING.md](CONTRIBUTING.md).
|
|||||||
|
|
||||||
We maintain separate branches for each active minor version of the package:
|
We maintain separate branches for each active minor version of the package:
|
||||||
|
|
||||||
| Package version | Branch |
|
| Package version | Branch |
|
||||||
| ----------------------- | ----------- |
|
| ----------------------- | ----------- |
|
||||||
| swift-system 1.3.x | release/1.3 |
|
| swift-system 1.3.x | release/1.3 |
|
||||||
| swift-system 1.4.x (unreleased) | release/1.4 |
|
| swift-system 1.4.x | release/1.4 |
|
||||||
| swift-system 1.5.x (unreleased) | main |
|
| swift-system 1.5.x | release/1.5 |
|
||||||
|
| swift-system 1.6.x | release/1.6 |
|
||||||
|
| swift-system 1.7.x (unreleased) | main |
|
||||||
|
|
||||||
Changes must land on the branch corresponding to the earliest release that they will need to ship on. They are periodically propagated to subsequent branches, in the following direction:
|
Changes must land on the branch corresponding to the earliest release that they will need to ship on. They are periodically propagated to subsequent branches, in the following direction:
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
This source file is part of the Swift System open source project
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
Copyright (c) 2024 Apple Inc. and the Swift System project authors
|
Copyright (c) 2024 - 2025 Apple Inc. and the Swift System project authors
|
||||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
@@ -11,8 +11,10 @@
|
|||||||
|
|
||||||
#if __wasi__
|
#if __wasi__
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <limits.h> // For NAME_MAX
|
||||||
|
|
||||||
// wasi-libc defines the following constants in a way that Clang Importer can't
|
// wasi-libc defines the following constants in a way that Clang Importer can't
|
||||||
// understand, so we need to expose them manually.
|
// understand, so we need to expose them manually.
|
||||||
@@ -28,4 +30,37 @@ static inline int32_t _getConst_O_WRONLY(void) { return O_WRONLY; }
|
|||||||
static inline int32_t _getConst_EWOULDBLOCK(void) { return EWOULDBLOCK; }
|
static inline int32_t _getConst_EWOULDBLOCK(void) { return EWOULDBLOCK; }
|
||||||
static inline int32_t _getConst_EOPNOTSUPP(void) { return EOPNOTSUPP; }
|
static inline int32_t _getConst_EOPNOTSUPP(void) { return EOPNOTSUPP; }
|
||||||
|
|
||||||
|
static inline uint8_t _getConst_DT_DIR(void) { return DT_DIR; }
|
||||||
|
|
||||||
|
// Modified dirent struct that can be imported to Swift
|
||||||
|
struct _system_dirent {
|
||||||
|
ino_t d_ino;
|
||||||
|
unsigned char d_type;
|
||||||
|
// char d_name[] cannot be imported to Swift
|
||||||
|
char d_name[NAME_MAX + 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert WASI dirent with d_name[] to _system_dirent
|
||||||
|
static inline
|
||||||
|
struct _system_dirent *
|
||||||
|
_system_dirent_from_wasi_dirent(const struct dirent *wasi_dirent) {
|
||||||
|
|
||||||
|
// Match readdir behavior and use thread-local storage for the converted dirent
|
||||||
|
static __thread struct _system_dirent _converted_dirent;
|
||||||
|
|
||||||
|
if (wasi_dirent == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&_converted_dirent, 0, sizeof(struct _system_dirent));
|
||||||
|
|
||||||
|
_converted_dirent.d_ino = wasi_dirent->d_ino;
|
||||||
|
_converted_dirent.d_type = wasi_dirent->d_type;
|
||||||
|
|
||||||
|
strncpy(_converted_dirent.d_name, wasi_dirent->d_name, NAME_MAX);
|
||||||
|
_converted_dirent.d_name[NAME_MAX] = '\0';
|
||||||
|
|
||||||
|
return &_converted_dirent;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,10 +1,195 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#define __SWIFT_IORING_SQE_FALLBACK_STRUCT { \
|
||||||
|
__u8 opcode; \
|
||||||
|
__u8 flags; \
|
||||||
|
__u16 ioprio; \
|
||||||
|
__s32 fd; \
|
||||||
|
union { \
|
||||||
|
__u64 off; \
|
||||||
|
__u64 addr2; \
|
||||||
|
struct { \
|
||||||
|
__u32 cmd_op; \
|
||||||
|
__u32 __pad1; \
|
||||||
|
}; \
|
||||||
|
}; \
|
||||||
|
union { \
|
||||||
|
__u64 addr; \
|
||||||
|
__u64 splice_off_in; \
|
||||||
|
struct { \
|
||||||
|
__u32 level; \
|
||||||
|
__u32 optname; \
|
||||||
|
}; \
|
||||||
|
}; \
|
||||||
|
__u32 len; \
|
||||||
|
union { \
|
||||||
|
__kernel_rwf_t rw_flags; \
|
||||||
|
__u32 fsync_flags; \
|
||||||
|
__u16 poll_events; \
|
||||||
|
__u32 poll32_events; \
|
||||||
|
__u32 sync_range_flags; \
|
||||||
|
__u32 msg_flags; \
|
||||||
|
__u32 timeout_flags; \
|
||||||
|
__u32 accept_flags; \
|
||||||
|
__u32 cancel_flags; \
|
||||||
|
__u32 open_flags; \
|
||||||
|
__u32 statx_flags; \
|
||||||
|
__u32 fadvise_advice; \
|
||||||
|
__u32 splice_flags; \
|
||||||
|
__u32 rename_flags; \
|
||||||
|
__u32 unlink_flags; \
|
||||||
|
__u32 hardlink_flags; \
|
||||||
|
__u32 xattr_flags; \
|
||||||
|
__u32 msg_ring_flags; \
|
||||||
|
__u32 uring_cmd_flags; \
|
||||||
|
__u32 waitid_flags; \
|
||||||
|
__u32 futex_flags; \
|
||||||
|
__u32 install_fd_flags; \
|
||||||
|
__u32 nop_flags; \
|
||||||
|
}; \
|
||||||
|
__u64 user_data; \
|
||||||
|
union { \
|
||||||
|
__u16 buf_index; \
|
||||||
|
__u16 buf_group; \
|
||||||
|
} __attribute__((packed)); \
|
||||||
|
__u16 personality; \
|
||||||
|
union { \
|
||||||
|
__s32 splice_fd_in; \
|
||||||
|
__u32 file_index; \
|
||||||
|
__u32 optlen; \
|
||||||
|
struct { \
|
||||||
|
__u16 addr_len; \
|
||||||
|
__u16 __pad3[1]; \
|
||||||
|
}; \
|
||||||
|
}; \
|
||||||
|
union { \
|
||||||
|
struct { \
|
||||||
|
__u64 addr3; \
|
||||||
|
__u64 __pad2[1]; \
|
||||||
|
}; \
|
||||||
|
__u64 optval; \
|
||||||
|
__u8 cmd[0]; \
|
||||||
|
}; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __has_include(<linux/io_uring.h>)
|
||||||
#include <linux/io_uring.h>
|
#include <linux/io_uring.h>
|
||||||
|
|
||||||
|
#ifdef IORING_TIMEOUT_BOOTTIME
|
||||||
|
// Kernel version >= 5.15, io_uring_sqe has file_index
|
||||||
|
// and all current Swift operations are supported.
|
||||||
|
#define __SWIFT_IORING_SUPPORTED true
|
||||||
|
typedef struct io_uring_sqe swift_io_uring_sqe;
|
||||||
|
#else
|
||||||
|
// io_uring_sqe is missing properties that IORequest expects.
|
||||||
|
// This configuration is not supported for now.
|
||||||
|
//
|
||||||
|
// Define a fallback struct to avoid build errors, but IORing
|
||||||
|
// will throw ENOTSUP on initialization.
|
||||||
|
#define __SWIFT_IORING_SUPPORTED false
|
||||||
|
typedef struct __SWIFT_IORING_SQE_FALLBACK_STRUCT swift_io_uring_sqe;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// We can define more specific availability later
|
||||||
|
|
||||||
|
#ifdef IORING_FEAT_RW_CUR_POS
|
||||||
|
// Kernel version >= 5.6, io_uring_sqe has open_flags
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IORING_FEAT_NODROP
|
||||||
|
// Kernel version >= 5.5, io_uring_sqe has cancel_flags
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
// Minimal fallback definitions when linux/io_uring.h is not available (e.g. static SDK)
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define __SWIFT_IORING_SUPPORTED false
|
||||||
|
|
||||||
|
#define IORING_OFF_SQ_RING 0ULL
|
||||||
|
#define IORING_OFF_CQ_RING 0x8000000ULL
|
||||||
|
#define IORING_OFF_SQES 0x10000000ULL
|
||||||
|
|
||||||
|
#define IORING_ENTER_GETEVENTS (1U << 0)
|
||||||
|
|
||||||
|
#define IORING_FEAT_SINGLE_MMAP (1U << 0)
|
||||||
|
#define IORING_FEAT_NODROP (1U << 1)
|
||||||
|
#define IORING_FEAT_SUBMIT_STABLE (1U << 2)
|
||||||
|
#define IORING_FEAT_RW_CUR_POS (1U << 3)
|
||||||
|
#define IORING_FEAT_CUR_PERSONALITY (1U << 4)
|
||||||
|
#define IORING_FEAT_FAST_POLL (1U << 5)
|
||||||
|
#define IORING_FEAT_POLL_32BITS (1U << 6)
|
||||||
|
#define IORING_FEAT_SQPOLL_NONFIXED (1U << 7)
|
||||||
|
#define IORING_FEAT_EXT_ARG (1U << 8)
|
||||||
|
#define IORING_FEAT_NATIVE_WORKERS (1U << 9)
|
||||||
|
#define IORING_FEAT_RSRC_TAGS (1U << 10)
|
||||||
|
#define IORING_FEAT_CQE_SKIP (1U << 11)
|
||||||
|
#define IORING_FEAT_LINKED_FILE (1U << 12)
|
||||||
|
#define IORING_FEAT_REG_REG_RING (1U << 13)
|
||||||
|
#define IORING_FEAT_RECVSEND_BUNDLE (1U << 14)
|
||||||
|
#define IORING_FEAT_MIN_TIMEOUT (1U << 15)
|
||||||
|
#define IORING_FEAT_RW_ATTR (1U << 16)
|
||||||
|
#define IORING_FEAT_NO_IOWAIT (1U << 17)
|
||||||
|
|
||||||
|
typedef uint8_t __u8;
|
||||||
|
typedef uint16_t __u16;
|
||||||
|
typedef uint32_t __u32;
|
||||||
|
typedef uint64_t __u64;
|
||||||
|
typedef int32_t __s32;
|
||||||
|
|
||||||
|
#ifndef __kernel_rwf_t
|
||||||
|
typedef int __kernel_rwf_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct __SWIFT_IORING_SQE_FALLBACK_STRUCT swift_io_uring_sqe;
|
||||||
|
|
||||||
|
struct io_uring_cqe {
|
||||||
|
__u64 user_data;
|
||||||
|
__s32 res;
|
||||||
|
__u32 flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct io_sqring_offsets {
|
||||||
|
__u32 head;
|
||||||
|
__u32 tail;
|
||||||
|
__u32 ring_mask;
|
||||||
|
__u32 ring_entries;
|
||||||
|
__u32 flags;
|
||||||
|
__u32 dropped;
|
||||||
|
__u32 array;
|
||||||
|
__u32 resv1;
|
||||||
|
__u64 user_addr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct io_cqring_offsets {
|
||||||
|
__u32 head;
|
||||||
|
__u32 tail;
|
||||||
|
__u32 ring_mask;
|
||||||
|
__u32 ring_entries;
|
||||||
|
__u32 overflow;
|
||||||
|
__u32 cqes;
|
||||||
|
__u32 flags;
|
||||||
|
__u32 resv1;
|
||||||
|
__u64 user_addr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct io_uring_params {
|
||||||
|
__u32 sq_entries;
|
||||||
|
__u32 cq_entries;
|
||||||
|
__u32 flags;
|
||||||
|
__u32 sq_thread_cpu;
|
||||||
|
__u32 sq_thread_idle;
|
||||||
|
__u32 features;
|
||||||
|
__u32 wq_fd;
|
||||||
|
__u32 resv[3];
|
||||||
|
struct io_sqring_offsets sq_off;
|
||||||
|
struct io_cqring_offsets cq_off;
|
||||||
|
};
|
||||||
|
#endif // __has_include(<linux/io_uring.h>)
|
||||||
|
|
||||||
#ifndef SWIFT_IORING_C_WRAPPER
|
#ifndef SWIFT_IORING_C_WRAPPER
|
||||||
#define SWIFT_IORING_C_WRAPPER
|
#define SWIFT_IORING_C_WRAPPER
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
/// An error number used by system calls to communicate what kind of error
|
/// An error number used by system calls to communicate what kind of error
|
||||||
/// occurred.
|
/// occurred.
|
||||||
@frozen
|
@frozen
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
public struct Errno: RawRepresentable, Error, Hashable {
|
||||||
/// The raw C error number.
|
/// The raw C error number.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public let rawValue: CInt
|
public let rawValue: CInt
|
||||||
@@ -1391,7 +1391,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constants defined in header but not man page
|
// Constants defined in header but not man page
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension Errno {
|
extension Errno {
|
||||||
/// Operation would block.
|
/// Operation would block.
|
||||||
///
|
///
|
||||||
@@ -1520,7 +1520,7 @@ extension Errno {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension Errno {
|
extension Errno {
|
||||||
// TODO: We want to provide safe access to `errno`, but we need a
|
// TODO: We want to provide safe access to `errno`, but we need a
|
||||||
// release-barrier to do so.
|
// release-barrier to do so.
|
||||||
@@ -1535,14 +1535,14 @@ extension Errno {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use "hidden" entry points for `NSError` bridging
|
// Use "hidden" entry points for `NSError` bridging
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension Errno {
|
extension Errno {
|
||||||
public var _code: Int { Int(rawValue) }
|
public var _code: Int { Int(rawValue) }
|
||||||
|
|
||||||
public var _domain: String { "NSPOSIXErrorDomain" }
|
public var _domain: String { "NSPOSIXErrorDomain" }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension Errno: CustomStringConvertible, CustomDebugStringConvertible {
|
extension Errno: CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
/// A textual representation of the most recent error
|
/// A textual representation of the most recent error
|
||||||
/// returned by a system call.
|
/// returned by a system call.
|
||||||
@@ -1562,7 +1562,9 @@ extension Errno: CustomStringConvertible, CustomDebugStringConvertible {
|
|||||||
public var debugDescription: String { self.description }
|
public var debugDescription: String { self.description }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
#if !$Embedded
|
||||||
|
|
||||||
|
@available(System 0.0.1, *)
|
||||||
extension Errno {
|
extension Errno {
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public static func ~=(_ lhs: Errno, _ rhs: Error) -> Bool {
|
public static func ~=(_ lhs: Errno, _ rhs: Error) -> Bool {
|
||||||
@@ -1571,3 +1573,13 @@ extension Errno {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(System 0.0.1, *)
|
||||||
|
extension Errno: Codable {}
|
||||||
|
|
||||||
|
public typealias SystemError = any Error
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
public typealias SystemError = Errno
|
||||||
|
|
||||||
|
#endif // !$Embedded
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
/// of `FileDescriptor` values,
|
/// of `FileDescriptor` values,
|
||||||
/// in the same way as you manage a raw C file handle.
|
/// in the same way as you manage a raw C file handle.
|
||||||
@frozen
|
@frozen
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
public struct FileDescriptor: RawRepresentable, Hashable, Codable {
|
public struct FileDescriptor: RawRepresentable, Hashable {
|
||||||
/// The raw C file handle.
|
/// The raw C file handle.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public let rawValue: CInt
|
public let rawValue: CInt
|
||||||
@@ -26,7 +26,7 @@ public struct FileDescriptor: RawRepresentable, Hashable, Codable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Standard file descriptors.
|
// Standard file descriptors.
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// The standard input file descriptor, with a numeric value of 0.
|
/// The standard input file descriptor, with a numeric value of 0.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
@@ -41,12 +41,12 @@ extension FileDescriptor {
|
|||||||
public static var standardError: FileDescriptor { .init(rawValue: 2) }
|
public static var standardError: FileDescriptor { .init(rawValue: 2) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// The desired read and write access for a newly opened file.
|
/// The desired read and write access for a newly opened file.
|
||||||
@frozen
|
@frozen
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
public struct AccessMode: RawRepresentable, Sendable, Hashable, Codable {
|
public struct AccessMode: RawRepresentable, Sendable, Hashable {
|
||||||
/// The raw C access mode.
|
/// The raw C access mode.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public var rawValue: CInt
|
public var rawValue: CInt
|
||||||
@@ -88,8 +88,8 @@ extension FileDescriptor {
|
|||||||
|
|
||||||
/// Options that specify behavior for a newly-opened file.
|
/// Options that specify behavior for a newly-opened file.
|
||||||
@frozen
|
@frozen
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
public struct OpenOptions: OptionSet, Sendable, Hashable, Codable {
|
public struct OpenOptions: OptionSet, Sendable, Hashable {
|
||||||
/// The raw C options.
|
/// The raw C options.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public var rawValue: CInt
|
public var rawValue: CInt
|
||||||
@@ -326,8 +326,8 @@ extension FileDescriptor {
|
|||||||
|
|
||||||
/// Options for specifying what a file descriptor's offset is relative to.
|
/// Options for specifying what a file descriptor's offset is relative to.
|
||||||
@frozen
|
@frozen
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
public struct SeekOrigin: RawRepresentable, Sendable, Hashable, Codable {
|
public struct SeekOrigin: RawRepresentable, Sendable, Hashable {
|
||||||
/// The raw C value.
|
/// The raw C value.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public var rawValue: CInt
|
public var rawValue: CInt
|
||||||
@@ -402,7 +402,23 @@ extension FileDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
#if !$Embedded
|
||||||
|
|
||||||
|
@available(System 0.0.1, *)
|
||||||
|
extension FileDescriptor: Codable {}
|
||||||
|
|
||||||
|
@available(System 0.0.1, *)
|
||||||
|
extension FileDescriptor.AccessMode: Codable {}
|
||||||
|
|
||||||
|
@available(System 0.0.1, *)
|
||||||
|
extension FileDescriptor.OpenOptions: Codable {}
|
||||||
|
|
||||||
|
@available(System 0.0.1, *)
|
||||||
|
extension FileDescriptor.SeekOrigin: Codable {}
|
||||||
|
|
||||||
|
#endif // !$Embedded
|
||||||
|
|
||||||
|
@available(System 0.0.1, *)
|
||||||
extension FileDescriptor.AccessMode
|
extension FileDescriptor.AccessMode
|
||||||
: CustomStringConvertible, CustomDebugStringConvertible
|
: CustomStringConvertible, CustomDebugStringConvertible
|
||||||
{
|
{
|
||||||
@@ -421,7 +437,7 @@ extension FileDescriptor.AccessMode
|
|||||||
public var debugDescription: String { self.description }
|
public var debugDescription: String { self.description }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FileDescriptor.SeekOrigin
|
extension FileDescriptor.SeekOrigin
|
||||||
: CustomStringConvertible, CustomDebugStringConvertible
|
: CustomStringConvertible, CustomDebugStringConvertible
|
||||||
{
|
{
|
||||||
@@ -444,7 +460,7 @@ extension FileDescriptor.SeekOrigin
|
|||||||
public var debugDescription: String { self.description }
|
public var debugDescription: String { self.description }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FileDescriptor.OpenOptions
|
extension FileDescriptor.OpenOptions
|
||||||
: CustomStringConvertible, CustomDebugStringConvertible
|
: CustomStringConvertible, CustomDebugStringConvertible
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// Runs a closure and then closes the file descriptor, even if an error occurs.
|
/// Runs a closure and then closes the file descriptor, even if an error occurs.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
This source file is part of the Swift System open source project
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
Copyright (c) 2020 - 2024 Apple Inc. and the Swift System project authors
|
Copyright (c) 2020 - 2025 Apple Inc. and the Swift System project authors
|
||||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// Opens or creates a file for reading or writing.
|
/// Opens or creates a file for reading or writing.
|
||||||
///
|
///
|
||||||
@@ -30,24 +30,24 @@ extension FileDescriptor {
|
|||||||
options: FileDescriptor.OpenOptions = FileDescriptor.OpenOptions(),
|
options: FileDescriptor.OpenOptions = FileDescriptor.OpenOptions(),
|
||||||
permissions: FilePermissions? = nil,
|
permissions: FilePermissions? = nil,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> FileDescriptor {
|
) throws(SystemError) -> FileDescriptor {
|
||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
return try path.withCString {
|
return try path.withCString { (cString) throws(SystemError) in
|
||||||
try FileDescriptor.open(
|
try FileDescriptor.open(
|
||||||
$0, mode, options: options, permissions: permissions, retryOnInterrupt: retryOnInterrupt)
|
cString, mode, options: options, permissions: permissions, retryOnInterrupt: retryOnInterrupt)
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return try path.withPlatformString {
|
return try path.withPlatformString { (platformString) throws(SystemError) in
|
||||||
try FileDescriptor.open(
|
try FileDescriptor.open(
|
||||||
$0, mode, options: options, permissions: permissions, retryOnInterrupt: retryOnInterrupt)
|
platformString, mode, options: options, permissions: permissions, retryOnInterrupt: retryOnInterrupt)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
// On Darwin, `CInterop.PlatformChar` is less available than
|
// On Darwin, `CInterop.PlatformChar` is less available than
|
||||||
// `FileDescriptor.open`, so we need to use `CChar` instead.
|
// `FileDescriptor.open`, so we need to use `CChar` instead.
|
||||||
|
|
||||||
/// Opens or creates a file for reading or writing.
|
/// Opens or creates a file for reading or writing.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
@@ -69,7 +69,7 @@ extension FileDescriptor {
|
|||||||
options: FileDescriptor.OpenOptions = FileDescriptor.OpenOptions(),
|
options: FileDescriptor.OpenOptions = FileDescriptor.OpenOptions(),
|
||||||
permissions: FilePermissions? = nil,
|
permissions: FilePermissions? = nil,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> FileDescriptor {
|
) throws(SystemError) -> FileDescriptor {
|
||||||
try FileDescriptor._open(
|
try FileDescriptor._open(
|
||||||
path, mode, options: options, permissions: permissions, retryOnInterrupt: retryOnInterrupt
|
path, mode, options: options, permissions: permissions, retryOnInterrupt: retryOnInterrupt
|
||||||
).get()
|
).get()
|
||||||
@@ -116,7 +116,7 @@ extension FileDescriptor {
|
|||||||
options: FileDescriptor.OpenOptions = FileDescriptor.OpenOptions(),
|
options: FileDescriptor.OpenOptions = FileDescriptor.OpenOptions(),
|
||||||
permissions: FilePermissions? = nil,
|
permissions: FilePermissions? = nil,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> FileDescriptor {
|
) throws(SystemError) -> FileDescriptor {
|
||||||
try FileDescriptor._open(
|
try FileDescriptor._open(
|
||||||
path, mode, options: options, permissions: permissions, retryOnInterrupt: retryOnInterrupt
|
path, mode, options: options, permissions: permissions, retryOnInterrupt: retryOnInterrupt
|
||||||
).get()
|
).get()
|
||||||
@@ -149,7 +149,7 @@ extension FileDescriptor {
|
|||||||
///
|
///
|
||||||
/// The corresponding C function is `close`.
|
/// The corresponding C function is `close`.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public func close() throws { try _close().get() }
|
public func close() throws(SystemError) { try _close().get() }
|
||||||
|
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
internal func _close() -> Result<(), Errno> {
|
internal func _close() -> Result<(), Errno> {
|
||||||
@@ -169,7 +169,7 @@ extension FileDescriptor {
|
|||||||
@discardableResult
|
@discardableResult
|
||||||
public func seek(
|
public func seek(
|
||||||
offset: Int64, from whence: FileDescriptor.SeekOrigin
|
offset: Int64, from whence: FileDescriptor.SeekOrigin
|
||||||
) throws -> Int64 {
|
) throws(SystemError) -> Int64 {
|
||||||
try _seek(offset: offset, from: whence).get()
|
try _seek(offset: offset, from: whence).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ extension FileDescriptor {
|
|||||||
@available(*, unavailable, renamed: "seek")
|
@available(*, unavailable, renamed: "seek")
|
||||||
public func lseek(
|
public func lseek(
|
||||||
offset: Int64, from whence: FileDescriptor.SeekOrigin
|
offset: Int64, from whence: FileDescriptor.SeekOrigin
|
||||||
) throws -> Int64 {
|
) throws(SystemError) -> Int64 {
|
||||||
try seek(offset: offset, from: whence)
|
try seek(offset: offset, from: whence)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ extension FileDescriptor {
|
|||||||
public func read(
|
public func read(
|
||||||
into buffer: UnsafeMutableRawBufferPointer,
|
into buffer: UnsafeMutableRawBufferPointer,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> Int {
|
) throws(SystemError) -> Int {
|
||||||
try _read(into: buffer, retryOnInterrupt: retryOnInterrupt).get()
|
try _read(into: buffer, retryOnInterrupt: retryOnInterrupt).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ extension FileDescriptor {
|
|||||||
internal func _read(
|
internal func _read(
|
||||||
into buffer: UnsafeMutableRawBufferPointer,
|
into buffer: UnsafeMutableRawBufferPointer,
|
||||||
retryOnInterrupt: Bool
|
retryOnInterrupt: Bool
|
||||||
) throws -> Result<Int, Errno> {
|
) throws(SystemError) -> Result<Int, Errno> {
|
||||||
valueOrErrno(retryOnInterrupt: retryOnInterrupt) {
|
valueOrErrno(retryOnInterrupt: retryOnInterrupt) {
|
||||||
system_read(self.rawValue, buffer.baseAddress, buffer.count)
|
system_read(self.rawValue, buffer.baseAddress, buffer.count)
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ extension FileDescriptor {
|
|||||||
fromAbsoluteOffset offset: Int64,
|
fromAbsoluteOffset offset: Int64,
|
||||||
into buffer: UnsafeMutableRawBufferPointer,
|
into buffer: UnsafeMutableRawBufferPointer,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> Int {
|
) throws(SystemError) -> Int {
|
||||||
try _read(
|
try _read(
|
||||||
fromAbsoluteOffset: offset,
|
fromAbsoluteOffset: offset,
|
||||||
into: buffer,
|
into: buffer,
|
||||||
@@ -276,7 +276,7 @@ extension FileDescriptor {
|
|||||||
fromAbsoluteOffset offset: Int64,
|
fromAbsoluteOffset offset: Int64,
|
||||||
into buffer: UnsafeMutableRawBufferPointer,
|
into buffer: UnsafeMutableRawBufferPointer,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> Int {
|
) throws(SystemError) -> Int {
|
||||||
try read(
|
try read(
|
||||||
fromAbsoluteOffset: offset,
|
fromAbsoluteOffset: offset,
|
||||||
into: buffer,
|
into: buffer,
|
||||||
@@ -303,7 +303,7 @@ extension FileDescriptor {
|
|||||||
public func write(
|
public func write(
|
||||||
_ buffer: UnsafeRawBufferPointer,
|
_ buffer: UnsafeRawBufferPointer,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> Int {
|
) throws(SystemError) -> Int {
|
||||||
try _write(buffer, retryOnInterrupt: retryOnInterrupt).get()
|
try _write(buffer, retryOnInterrupt: retryOnInterrupt).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ extension FileDescriptor {
|
|||||||
toAbsoluteOffset offset: Int64,
|
toAbsoluteOffset offset: Int64,
|
||||||
_ buffer: UnsafeRawBufferPointer,
|
_ buffer: UnsafeRawBufferPointer,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> Int {
|
) throws(SystemError) -> Int {
|
||||||
try _write(toAbsoluteOffset: offset, buffer, retryOnInterrupt: retryOnInterrupt).get()
|
try _write(toAbsoluteOffset: offset, buffer, retryOnInterrupt: retryOnInterrupt).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +359,7 @@ extension FileDescriptor {
|
|||||||
toAbsoluteOffset offset: Int64,
|
toAbsoluteOffset offset: Int64,
|
||||||
into buffer: UnsafeRawBufferPointer,
|
into buffer: UnsafeRawBufferPointer,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> Int {
|
) throws(SystemError) -> Int {
|
||||||
try write(
|
try write(
|
||||||
toAbsoluteOffset: offset,
|
toAbsoluteOffset: offset,
|
||||||
buffer,
|
buffer,
|
||||||
@@ -368,7 +368,7 @@ extension FileDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !os(WASI)
|
#if !os(WASI)
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// Duplicates this file descriptor and return the newly created copy.
|
/// Duplicates this file descriptor and return the newly created copy.
|
||||||
///
|
///
|
||||||
@@ -398,20 +398,20 @@ extension FileDescriptor {
|
|||||||
///
|
///
|
||||||
/// The corresponding C functions are `dup` and `dup2`.
|
/// The corresponding C functions are `dup` and `dup2`.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
public func duplicate(
|
public func duplicate(
|
||||||
as target: FileDescriptor? = nil,
|
as target: FileDescriptor? = nil,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws -> FileDescriptor {
|
) throws(SystemError) -> FileDescriptor {
|
||||||
try _duplicate(as: target, retryOnInterrupt: retryOnInterrupt).get()
|
try _duplicate(as: target, retryOnInterrupt: retryOnInterrupt).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
internal func _duplicate(
|
internal func _duplicate(
|
||||||
as target: FileDescriptor?,
|
as target: FileDescriptor?,
|
||||||
retryOnInterrupt: Bool
|
retryOnInterrupt: Bool
|
||||||
) throws -> Result<FileDescriptor, Errno> {
|
) throws(SystemError) -> Result<FileDescriptor, Errno> {
|
||||||
valueOrErrno(retryOnInterrupt: retryOnInterrupt) {
|
valueOrErrno(retryOnInterrupt: retryOnInterrupt) {
|
||||||
if let target = target {
|
if let target = target {
|
||||||
return system_dup2(self.rawValue, target.rawValue)
|
return system_dup2(self.rawValue, target.rawValue)
|
||||||
@@ -422,20 +422,20 @@ extension FileDescriptor {
|
|||||||
|
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
@available(*, unavailable, renamed: "duplicate")
|
@available(*, unavailable, renamed: "duplicate")
|
||||||
public func dup() throws -> FileDescriptor {
|
public func dup() throws(SystemError) -> FileDescriptor {
|
||||||
fatalError("Not implemented")
|
fatalError("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
@available(*, unavailable, renamed: "duplicate")
|
@available(*, unavailable, renamed: "duplicate")
|
||||||
public func dup2() throws -> FileDescriptor {
|
public func dup2() throws(SystemError) -> FileDescriptor {
|
||||||
fatalError("Not implemented")
|
fatalError("Not implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !os(WASI)
|
#if !os(WASI)
|
||||||
@available(/*System 1.1.0: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4*/iOS 8, *)
|
@available(System 1.1.0, *)
|
||||||
extension FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// Creates a unidirectional data channel, which can be used for interprocess communication.
|
/// Creates a unidirectional data channel, which can be used for interprocess communication.
|
||||||
///
|
///
|
||||||
@@ -443,12 +443,12 @@ extension FileDescriptor {
|
|||||||
///
|
///
|
||||||
/// The corresponding C function is `pipe`.
|
/// The corresponding C function is `pipe`.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
@available(/*System 1.1.0: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4*/iOS 8, *)
|
@available(System 1.1.0, *)
|
||||||
public static func pipe() throws -> (readEnd: FileDescriptor, writeEnd: FileDescriptor) {
|
public static func pipe() throws(SystemError) -> (readEnd: FileDescriptor, writeEnd: FileDescriptor) {
|
||||||
try _pipe().get()
|
try _pipe().get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 1.1.0: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4*/iOS 8, *)
|
@available(System 1.1.0, *)
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
internal static func _pipe() -> Result<(readEnd: FileDescriptor, writeEnd: FileDescriptor), Errno> {
|
internal static func _pipe() -> Result<(readEnd: FileDescriptor, writeEnd: FileDescriptor), Errno> {
|
||||||
var fds: (Int32, Int32) = (-1, -1)
|
var fds: (Int32, Int32) = (-1, -1)
|
||||||
@@ -463,7 +463,7 @@ extension FileDescriptor {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.2.0, *)
|
||||||
extension FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// Truncates or extends the file referenced by this file descriptor.
|
/// Truncates or extends the file referenced by this file descriptor.
|
||||||
///
|
///
|
||||||
@@ -485,19 +485,19 @@ extension FileDescriptor {
|
|||||||
/// associated with the file.
|
/// associated with the file.
|
||||||
///
|
///
|
||||||
/// The corresponding C function is `ftruncate`.
|
/// The corresponding C function is `ftruncate`.
|
||||||
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.2.0, *)
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public func resize(
|
public func resize(
|
||||||
to newSize: Int64,
|
to newSize: Int64,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
) throws {
|
) throws(SystemError) {
|
||||||
try _resize(
|
try _resize(
|
||||||
to: newSize,
|
to: newSize,
|
||||||
retryOnInterrupt: retryOnInterrupt
|
retryOnInterrupt: retryOnInterrupt
|
||||||
).get()
|
).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.2.0, *)
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
internal func _resize(
|
internal func _resize(
|
||||||
to newSize: Int64,
|
to newSize: Int64,
|
||||||
@@ -509,6 +509,7 @@ extension FileDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !os(WASI) // WASI has no umask
|
||||||
extension FilePermissions {
|
extension FilePermissions {
|
||||||
/// The file creation permission mask (aka "umask").
|
/// The file creation permission mask (aka "umask").
|
||||||
///
|
///
|
||||||
@@ -536,7 +537,7 @@ extension FilePermissions {
|
|||||||
/// afterwards, because of the way reading the creation mask works.
|
/// afterwards, because of the way reading the creation mask works.
|
||||||
internal static func withCreationMask<R>(
|
internal static func withCreationMask<R>(
|
||||||
_ permissions: FilePermissions,
|
_ permissions: FilePermissions,
|
||||||
body: () throws -> R
|
body: () throws(SystemError) -> R
|
||||||
) rethrows -> R {
|
) rethrows -> R {
|
||||||
let oldMask = _umask(permissions.rawValue)
|
let oldMask = _umask(permissions.rawValue)
|
||||||
defer {
|
defer {
|
||||||
@@ -549,3 +550,4 @@ extension FilePermissions {
|
|||||||
return system_umask(mode)
|
return system_umask(mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
/// However, the rules for path equivalence
|
/// However, the rules for path equivalence
|
||||||
/// are file-system–specific and have additional considerations
|
/// are file-system–specific and have additional considerations
|
||||||
/// like case insensitivity, Unicode normalization, and symbolic links.
|
/// like case insensitivity, Unicode normalization, and symbolic links.
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
public struct FilePath: Sendable {
|
public struct FilePath: Sendable {
|
||||||
// TODO(docs): Section on all the new syntactic operations, lexical normalization, decomposition,
|
// TODO(docs): Section on all the new syntactic operations, lexical normalization, decomposition,
|
||||||
// components, etc.
|
// components, etc.
|
||||||
@@ -59,16 +59,18 @@ public struct FilePath: Sendable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// The length of the file path, excluding the null terminator.
|
/// The length of the file path, excluding the null terminator.
|
||||||
public var length: Int { _storage.length }
|
public var length: Int { _storage.length }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath: Hashable {}
|
extension FilePath: Hashable {}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
#if !$Embedded
|
||||||
|
|
||||||
|
@available(System 0.0.1, *)
|
||||||
extension FilePath: Codable {
|
extension FilePath: Codable {
|
||||||
// Encoder is synthesized; it probably should have been explicit and used
|
// Encoder is synthesized; it probably should have been explicit and used
|
||||||
// a single-value container, but making that change now is somewhat risky.
|
// a single-value container, but making that change now is somewhat risky.
|
||||||
@@ -88,3 +90,5 @@ extension FilePath: Codable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // !$Embedded
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// MARK: - API
|
// MARK: - API
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// A bidirectional, range replaceable collection of the non-root components
|
/// A bidirectional, range replaceable collection of the non-root components
|
||||||
/// that make up a file path.
|
/// that make up a file path.
|
||||||
@@ -28,7 +28,7 @@ extension FilePath {
|
|||||||
///
|
///
|
||||||
/// path.components.removeAll { $0.kind == .currentDirectory }
|
/// path.components.removeAll { $0.kind == .currentDirectory }
|
||||||
/// // path is "/home/username/bin/scripts/tree"
|
/// // path is "/home/username/bin/scripts/tree"
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
public struct ComponentView: Sendable {
|
public struct ComponentView: Sendable {
|
||||||
internal var _path: FilePath
|
internal var _path: FilePath
|
||||||
internal var _start: SystemString.Index
|
internal var _start: SystemString.Index
|
||||||
@@ -64,11 +64,11 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.ComponentView: BidirectionalCollection {
|
extension FilePath.ComponentView: BidirectionalCollection {
|
||||||
public typealias Element = FilePath.Component
|
public typealias Element = FilePath.Component
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
public struct Index: Sendable, Comparable, Hashable {
|
public struct Index: Sendable, Comparable, Hashable {
|
||||||
internal typealias Storage = SystemString.Index
|
internal typealias Storage = SystemString.Index
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ extension FilePath.ComponentView: BidirectionalCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.ComponentView: RangeReplaceableCollection {
|
extension FilePath.ComponentView: RangeReplaceableCollection {
|
||||||
public init() {
|
public init() {
|
||||||
self.init(FilePath())
|
self.init(FilePath())
|
||||||
@@ -150,7 +150,7 @@ extension FilePath.ComponentView: RangeReplaceableCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Create a file path from a root and a collection of components.
|
/// Create a file path from a root and a collection of components.
|
||||||
public init<C: Collection>(
|
public init<C: Collection>(
|
||||||
@@ -179,7 +179,7 @@ extension FilePath {
|
|||||||
|
|
||||||
// MARK: - Internals
|
// MARK: - Internals
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.ComponentView: _PathSlice {
|
extension FilePath.ComponentView: _PathSlice {
|
||||||
internal var _range: Range<SystemString.Index> {
|
internal var _range: Range<SystemString.Index> {
|
||||||
_start ..< _path._storage.endIndex
|
_start ..< _path._storage.endIndex
|
||||||
@@ -192,7 +192,7 @@ extension FilePath.ComponentView: _PathSlice {
|
|||||||
|
|
||||||
// MARK: - Invariants
|
// MARK: - Invariants
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.ComponentView {
|
extension FilePath.ComponentView {
|
||||||
internal func _invariantCheck() {
|
internal func _invariantCheck() {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// MARK: - API
|
// MARK: - API
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Represents a root of a file path.
|
/// Represents a root of a file path.
|
||||||
///
|
///
|
||||||
@@ -28,7 +28,7 @@ extension FilePath {
|
|||||||
/// * `\\server\share\`
|
/// * `\\server\share\`
|
||||||
/// * `\\?\UNC\server\share\`
|
/// * `\\?\UNC\server\share\`
|
||||||
/// * `\\?\Volume{12345678-abcd-1111-2222-123445789abc}\`
|
/// * `\\?\Volume{12345678-abcd-1111-2222-123445789abc}\`
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
public struct Root: Sendable {
|
public struct Root: Sendable {
|
||||||
internal var _path: FilePath
|
internal var _path: FilePath
|
||||||
internal var _rootEnd: SystemString.Index
|
internal var _rootEnd: SystemString.Index
|
||||||
@@ -55,7 +55,7 @@ extension FilePath {
|
|||||||
/// file.kind == .regular // true
|
/// file.kind == .regular // true
|
||||||
/// file.extension // "txt"
|
/// file.extension // "txt"
|
||||||
/// path.append(file) // path is "/tmp/foo.txt"
|
/// path.append(file) // path is "/tmp/foo.txt"
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
public struct Component: Sendable {
|
public struct Component: Sendable {
|
||||||
internal var _path: FilePath
|
internal var _path: FilePath
|
||||||
internal var _range: Range<SystemString.Index>
|
internal var _range: Range<SystemString.Index>
|
||||||
@@ -74,13 +74,13 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
|
|
||||||
/// Whether a component is a regular file or directory name, or a special
|
/// Whether a component is a regular file or directory name, or a special
|
||||||
/// directory `.` or `..`
|
/// directory `.` or `..`
|
||||||
@frozen
|
@frozen
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
public enum Kind: Sendable {
|
public enum Kind: Sendable {
|
||||||
/// The special directory `.`, representing the current directory.
|
/// The special directory `.`, representing the current directory.
|
||||||
case currentDirectory
|
case currentDirectory
|
||||||
@@ -100,7 +100,7 @@ extension FilePath.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Root {
|
extension FilePath.Root {
|
||||||
// TODO: Windows analysis APIs
|
// TODO: Windows analysis APIs
|
||||||
}
|
}
|
||||||
@@ -128,6 +128,8 @@ extension SystemString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !$Embedded
|
||||||
|
|
||||||
// Unifying protocol for common functionality between roots, components,
|
// Unifying protocol for common functionality between roots, components,
|
||||||
// and views onto SystemString and FilePath.
|
// and views onto SystemString and FilePath.
|
||||||
internal protocol _StrSlice: _PlatformStringable, Hashable, Codable {
|
internal protocol _StrSlice: _PlatformStringable, Hashable, Codable {
|
||||||
@@ -138,6 +140,20 @@ internal protocol _StrSlice: _PlatformStringable, Hashable, Codable {
|
|||||||
|
|
||||||
func _invariantCheck()
|
func _invariantCheck()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
internal protocol _StrSlice: _PlatformStringable, Hashable {
|
||||||
|
var _storage: SystemString { get }
|
||||||
|
var _range: Range<SystemString.Index> { get }
|
||||||
|
|
||||||
|
init?(_ str: SystemString)
|
||||||
|
|
||||||
|
func _invariantCheck()
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !$Embedded
|
||||||
|
|
||||||
extension _StrSlice {
|
extension _StrSlice {
|
||||||
internal var _slice: Slice<SystemString> {
|
internal var _slice: Slice<SystemString> {
|
||||||
Slice(base: _storage, bounds: _range)
|
Slice(base: _storage, bounds: _range)
|
||||||
@@ -186,17 +202,17 @@ extension _PathSlice {
|
|||||||
internal var _storage: SystemString { _path._storage }
|
internal var _storage: SystemString { _path._storage }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component: _PathSlice {
|
extension FilePath.Component: _PathSlice {
|
||||||
}
|
}
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Root: _PathSlice {
|
extension FilePath.Root: _PathSlice {
|
||||||
internal var _range: Range<SystemString.Index> {
|
internal var _range: Range<SystemString.Index> {
|
||||||
(..<_rootEnd).relative(to: _path._storage)
|
(..<_rootEnd).relative(to: _path._storage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath: _PlatformStringable {
|
extension FilePath: _PlatformStringable {
|
||||||
func _withPlatformString<Result>(_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result) rethrows -> Result {
|
func _withPlatformString<Result>(_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result) rethrows -> Result {
|
||||||
try _storage.withPlatformString(body)
|
try _storage.withPlatformString(body)
|
||||||
@@ -208,7 +224,7 @@ extension FilePath: _PlatformStringable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
// The index of the `.` denoting an extension
|
// The index of the `.` denoting an extension
|
||||||
internal func _extensionIndex() -> SystemString.Index? {
|
internal func _extensionIndex() -> SystemString.Index? {
|
||||||
@@ -237,7 +253,7 @@ internal func _makeExtension(_ ext: String) -> SystemString {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
internal init?(_ str: SystemString) {
|
internal init?(_ str: SystemString) {
|
||||||
// FIXME: explicit null root? Or something else?
|
// FIXME: explicit null root? Or something else?
|
||||||
@@ -250,7 +266,7 @@ extension FilePath.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Root {
|
extension FilePath.Root {
|
||||||
internal init?(_ str: SystemString) {
|
internal init?(_ str: SystemString) {
|
||||||
// FIXME: explicit null root? Or something else?
|
// FIXME: explicit null root? Or something else?
|
||||||
@@ -265,7 +281,7 @@ extension FilePath.Root {
|
|||||||
|
|
||||||
// MARK: - Invariants
|
// MARK: - Invariants
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
// TODO: ensure this all gets easily optimized away in release...
|
// TODO: ensure this all gets easily optimized away in release...
|
||||||
internal func _invariantCheck() {
|
internal func _invariantCheck() {
|
||||||
@@ -278,7 +294,7 @@ extension FilePath.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Root {
|
extension FilePath.Root {
|
||||||
internal func _invariantCheck() {
|
internal func _invariantCheck() {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ extension SystemString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
internal mutating func _removeTrailingSeparator() {
|
internal mutating func _removeTrailingSeparator() {
|
||||||
_storage._removeTrailingSeparator()
|
_storage._removeTrailingSeparator()
|
||||||
@@ -197,7 +197,7 @@ extension SystemString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
internal var _relativeStart: SystemString.Index {
|
internal var _relativeStart: SystemString.Index {
|
||||||
_storage._relativePathStart
|
_storage._relativePathStart
|
||||||
@@ -209,7 +209,7 @@ extension FilePath {
|
|||||||
|
|
||||||
// Parse separators
|
// Parse separators
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
internal typealias _Index = SystemString.Index
|
internal typealias _Index = SystemString.Index
|
||||||
|
|
||||||
@@ -273,7 +273,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.ComponentView {
|
extension FilePath.ComponentView {
|
||||||
// TODO: Store this...
|
// TODO: Store this...
|
||||||
internal var _relativeStart: SystemString.Index {
|
internal var _relativeStart: SystemString.Index {
|
||||||
@@ -298,7 +298,7 @@ extension SystemString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Root {
|
extension FilePath.Root {
|
||||||
// Asserting self is a root, returns whether this is an
|
// Asserting self is a root, returns whether this is an
|
||||||
// absolute root.
|
// absolute root.
|
||||||
@@ -323,7 +323,7 @@ extension FilePath.Root {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
internal var _portableDescription: String {
|
internal var _portableDescription: String {
|
||||||
guard _windowsPaths else { return description }
|
guard _windowsPaths else { return description }
|
||||||
@@ -345,7 +345,7 @@ internal var _windowsPaths: Bool {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
// Whether we should add a separator when doing an append
|
// Whether we should add a separator when doing an append
|
||||||
internal var _needsSeparatorForAppend: Bool {
|
internal var _needsSeparatorForAppend: Bool {
|
||||||
@@ -373,7 +373,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Invariants
|
// MARK: - Invariants
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
internal func _invariantsSatisfied() -> Bool {
|
internal func _invariantsSatisfied() -> Bool {
|
||||||
var normal = self
|
var normal = self
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// MARK: - Platform string
|
// MARK: - Platform string
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Creates a file path by copying bytes from a null-terminated platform
|
/// Creates a file path by copying bytes from a null-terminated platform
|
||||||
/// string.
|
/// string.
|
||||||
@@ -64,7 +64,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
// Note: This function should have been opaque, but it shipped as
|
// Note: This function should have been opaque, but it shipped as
|
||||||
// `@_alwaysEmitIntoClient` in macOS 12/iOS 15, and now it is stuck
|
// `@_alwaysEmitIntoClient` in macOS 12/iOS 15, and now it is stuck
|
||||||
// this way forever. (Or until the language provides a way for us
|
// this way forever. (Or until the language provides a way for us
|
||||||
// to declare separate availability for a function's exported symbol
|
// to declare separate availability for a function's exported symbol
|
||||||
@@ -84,7 +84,7 @@ extension FilePath {
|
|||||||
/// Don't try to store the pointer for later use.
|
/// Don't try to store the pointer for later use.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public func withPlatformString<Result>(
|
public func withPlatformString<Result>(
|
||||||
_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result
|
_ body: (UnsafePointer<CInterop.PlatformChar>) throws(SystemError) -> Result
|
||||||
) rethrows -> Result {
|
) rethrows -> Result {
|
||||||
return try withCString(body)
|
return try withCString(body)
|
||||||
}
|
}
|
||||||
@@ -102,14 +102,14 @@ extension FilePath {
|
|||||||
/// only during the execution of this method.
|
/// only during the execution of this method.
|
||||||
/// Don't try to store the pointer for later use.
|
/// Don't try to store the pointer for later use.
|
||||||
public func withPlatformString<Result>(
|
public func withPlatformString<Result>(
|
||||||
_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result
|
_ body: (UnsafePointer<CInterop.PlatformChar>) throws(SystemError) -> Result
|
||||||
) rethrows -> Result {
|
) rethrows -> Result {
|
||||||
return try _withPlatformString(body)
|
return try _withPlatformString(body)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
/// Creates a file path component by copying bytes from a null-terminated
|
/// Creates a file path component by copying bytes from a null-terminated
|
||||||
/// platform string.
|
/// platform string.
|
||||||
@@ -198,7 +198,7 @@ extension FilePath.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Root {
|
extension FilePath.Root {
|
||||||
/// Creates a file path root by copying bytes from a null-terminated platform
|
/// Creates a file path root by copying bytes from a null-terminated platform
|
||||||
/// string.
|
/// string.
|
||||||
@@ -287,7 +287,7 @@ extension FilePath.Root {
|
|||||||
|
|
||||||
// MARK: - String literals
|
// MARK: - String literals
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath: ExpressibleByStringLiteral {
|
extension FilePath: ExpressibleByStringLiteral {
|
||||||
/// Creates a file path from a string literal.
|
/// Creates a file path from a string literal.
|
||||||
///
|
///
|
||||||
@@ -306,7 +306,7 @@ extension FilePath: ExpressibleByStringLiteral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component: ExpressibleByStringLiteral {
|
extension FilePath.Component: ExpressibleByStringLiteral {
|
||||||
/// Create a file path component from a string literal.
|
/// Create a file path component from a string literal.
|
||||||
///
|
///
|
||||||
@@ -331,7 +331,7 @@ extension FilePath.Component: ExpressibleByStringLiteral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Root: ExpressibleByStringLiteral {
|
extension FilePath.Root: ExpressibleByStringLiteral {
|
||||||
/// Create a file path root from a string literal.
|
/// Create a file path root from a string literal.
|
||||||
///
|
///
|
||||||
@@ -356,7 +356,7 @@ extension FilePath.Root: ExpressibleByStringLiteral {
|
|||||||
|
|
||||||
// MARK: - Printing and dumping
|
// MARK: - Printing and dumping
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath: CustomStringConvertible, CustomDebugStringConvertible {
|
extension FilePath: CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
/// A textual representation of the file path.
|
/// A textual representation of the file path.
|
||||||
///
|
///
|
||||||
@@ -372,7 +372,7 @@ extension FilePath: CustomStringConvertible, CustomDebugStringConvertible {
|
|||||||
public var debugDescription: String { description.debugDescription }
|
public var debugDescription: String { description.debugDescription }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component: CustomStringConvertible, CustomDebugStringConvertible {
|
extension FilePath.Component: CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
|
|
||||||
/// A textual representation of the path component.
|
/// A textual representation of the path component.
|
||||||
@@ -389,7 +389,7 @@ extension FilePath.Component: CustomStringConvertible, CustomDebugStringConverti
|
|||||||
public var debugDescription: String { description.debugDescription }
|
public var debugDescription: String { description.debugDescription }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Root: CustomStringConvertible, CustomDebugStringConvertible {
|
extension FilePath.Root: CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
|
|
||||||
/// A textual representation of the path root.
|
/// A textual representation of the path root.
|
||||||
@@ -409,7 +409,7 @@ extension FilePath.Root: CustomStringConvertible, CustomDebugStringConvertible {
|
|||||||
// MARK: - Convenience helpers
|
// MARK: - Convenience helpers
|
||||||
|
|
||||||
// Convenience helpers
|
// Convenience helpers
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Creates a string by interpreting the path’s content as UTF-8 on Unix
|
/// Creates a string by interpreting the path’s content as UTF-8 on Unix
|
||||||
/// and UTF-16 on Windows.
|
/// and UTF-16 on Windows.
|
||||||
@@ -420,7 +420,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
/// Creates a string by interpreting the component’s content as UTF-8 on Unix
|
/// Creates a string by interpreting the component’s content as UTF-8 on Unix
|
||||||
/// and UTF-16 on Windows.
|
/// and UTF-16 on Windows.
|
||||||
@@ -431,7 +431,7 @@ extension FilePath.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Root {
|
extension FilePath.Root {
|
||||||
/// On Unix, this returns `"/"`.
|
/// On Unix, this returns `"/"`.
|
||||||
///
|
///
|
||||||
@@ -445,7 +445,7 @@ extension FilePath.Root {
|
|||||||
|
|
||||||
// MARK: - Decoding and validating
|
// MARK: - Decoding and validating
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension String {
|
extension String {
|
||||||
/// Creates a string by interpreting the file path's content as UTF-8 on Unix
|
/// Creates a string by interpreting the file path's content as UTF-8 on Unix
|
||||||
/// and UTF-16 on Windows.
|
/// and UTF-16 on Windows.
|
||||||
@@ -475,7 +475,7 @@ extension String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension String {
|
extension String {
|
||||||
/// Creates a string by interpreting the path component's content as UTF-8 on
|
/// Creates a string by interpreting the path component's content as UTF-8 on
|
||||||
/// Unix and UTF-16 on Windows.
|
/// Unix and UTF-16 on Windows.
|
||||||
@@ -505,7 +505,7 @@ extension String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension String {
|
extension String {
|
||||||
/// On Unix, creates the string `"/"`
|
/// On Unix, creates the string `"/"`
|
||||||
///
|
///
|
||||||
@@ -558,7 +558,7 @@ extension String {
|
|||||||
|
|
||||||
// MARK: - Deprecations
|
// MARK: - Deprecations
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension String {
|
extension String {
|
||||||
@available(*, deprecated, renamed: "init(decoding:)")
|
@available(*, deprecated, renamed: "init(decoding:)")
|
||||||
public init(_ path: FilePath) { self.init(decoding: path) }
|
public init(_ path: FilePath) { self.init(decoding: path) }
|
||||||
@@ -568,7 +568,7 @@ extension String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// For backwards compatibility only. This initializer is equivalent to
|
/// For backwards compatibility only. This initializer is equivalent to
|
||||||
/// the preferred `FilePath(platformString:)`.
|
/// the preferred `FilePath(platformString:)`.
|
||||||
@@ -595,8 +595,8 @@ extension FilePath {
|
|||||||
/// For backwards compatibility only. This function is equivalent to
|
/// For backwards compatibility only. This function is equivalent to
|
||||||
/// the preferred `withPlatformString`.
|
/// the preferred `withPlatformString`.
|
||||||
public func withCString<Result>(
|
public func withCString<Result>(
|
||||||
_ body: (UnsafePointer<CChar>) throws -> Result
|
_ body: (UnsafePointer<CChar>) throws(SystemError) -> Result
|
||||||
) rethrows -> Result {
|
) throws(SystemError) -> Result {
|
||||||
return try _withPlatformString(body)
|
return try _withPlatformString(body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// MARK: - Query API
|
// MARK: - Query API
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Returns true if this path uniquely identifies the location of
|
/// Returns true if this path uniquely identifies the location of
|
||||||
/// a file without reference to an additional starting location.
|
/// a file without reference to an additional starting location.
|
||||||
@@ -99,7 +99,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Decompose a path
|
// MARK: - Decompose a path
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Returns the root of a path if there is one, otherwise `nil`.
|
/// Returns the root of a path if there is one, otherwise `nil`.
|
||||||
///
|
///
|
||||||
@@ -182,7 +182,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Returns the final component of the path.
|
/// Returns the final component of the path.
|
||||||
/// Returns `nil` if the path is empty or only contains a root.
|
/// Returns `nil` if the path is empty or only contains a root.
|
||||||
@@ -252,7 +252,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
/// The extension of this file or directory component.
|
/// The extension of this file or directory component.
|
||||||
///
|
///
|
||||||
@@ -283,7 +283,7 @@ extension FilePath.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
|
|
||||||
/// The extension of the file or directory last component.
|
/// The extension of the file or directory last component.
|
||||||
@@ -349,7 +349,7 @@ extension FilePath {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Whether the path is in lexical-normal form, that is `.` and `..`
|
/// Whether the path is in lexical-normal form, that is `.` and `..`
|
||||||
/// components have been collapsed lexically (i.e. without following
|
/// components have been collapsed lexically (i.e. without following
|
||||||
@@ -430,7 +430,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Modification and concatenation API
|
// Modification and concatenation API
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
// TODO(Windows docs): example with roots
|
// TODO(Windows docs): example with roots
|
||||||
/// If `prefix` is a prefix of `self`, removes it and returns `true`.
|
/// If `prefix` is a prefix of `self`, removes it and returns `true`.
|
||||||
@@ -583,7 +583,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK - Renamed
|
// MARK - Renamed
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
@available(*, unavailable, renamed: "removingLastComponent()")
|
@available(*, unavailable, renamed: "removingLastComponent()")
|
||||||
public var dirname: FilePath { removingLastComponent() }
|
public var dirname: FilePath { removingLastComponent() }
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
/// deletes the directory and all of its contents before returning.
|
/// deletes the directory and all of its contents before returning.
|
||||||
internal func withTemporaryFilePath<R>(
|
internal func withTemporaryFilePath<R>(
|
||||||
basename: FilePath.Component,
|
basename: FilePath.Component,
|
||||||
_ body: (FilePath) throws -> R
|
_ body: (FilePath) throws(SystemError) -> R
|
||||||
) throws -> R {
|
) throws(SystemError) -> R {
|
||||||
let temporaryDir = try createUniqueTemporaryDirectory(basename: basename)
|
let temporaryDir = try createUniqueTemporaryDirectory(basename: basename)
|
||||||
defer {
|
defer {
|
||||||
try? _recursiveRemove(at: temporaryDir)
|
try? _recursiveRemove(at: temporaryDir)
|
||||||
@@ -44,9 +44,9 @@ fileprivate let base64 = Array<UInt8>(
|
|||||||
///
|
///
|
||||||
/// This function will throw if there is an error, except if the error
|
/// This function will throw if there is an error, except if the error
|
||||||
/// is that the directory exists, in which case it returns `false`.
|
/// is that the directory exists, in which case it returns `false`.
|
||||||
fileprivate func makeLockedDownDirectory(at path: FilePath) throws -> Bool {
|
fileprivate func makeLockedDownDirectory(at path: FilePath) throws(SystemError) -> Bool {
|
||||||
return try path.withPlatformString {
|
return try path.withPlatformString { (platformString) throws(SystemError) in
|
||||||
if system_mkdir($0, 0o700) == 0 {
|
if system_mkdir(platformString, 0o700) == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
let err = system_errno
|
let err = system_errno
|
||||||
@@ -83,7 +83,7 @@ fileprivate func createRandomString(length: Int) -> String {
|
|||||||
/// string of characters.
|
/// string of characters.
|
||||||
fileprivate func createUniqueTemporaryDirectory(
|
fileprivate func createUniqueTemporaryDirectory(
|
||||||
basename: FilePath.Component
|
basename: FilePath.Component
|
||||||
) throws -> FilePath {
|
) throws(SystemError) -> FilePath {
|
||||||
var tempDir = try _getTemporaryDirectory()
|
var tempDir = try _getTemporaryDirectory()
|
||||||
tempDir.append(basename)
|
tempDir.append(basename)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
|
|
||||||
/// Get the path to the system temporary directory.
|
/// Get the path to the system temporary directory.
|
||||||
internal func _getTemporaryDirectory() throws -> FilePath {
|
internal func _getTemporaryDirectory() throws(SystemError) -> FilePath {
|
||||||
guard let tmp = system_getenv("TMPDIR") else {
|
guard let tmp = system_getenv("TMPDIR") else {
|
||||||
return "/tmp"
|
return "/tmp"
|
||||||
}
|
}
|
||||||
@@ -26,22 +26,22 @@ internal func _getTemporaryDirectory() throws -> FilePath {
|
|||||||
/// Removes a directory completely, including all of its contents.
|
/// Removes a directory completely, including all of its contents.
|
||||||
internal func _recursiveRemove(
|
internal func _recursiveRemove(
|
||||||
at path: FilePath
|
at path: FilePath
|
||||||
) throws {
|
) throws(SystemError) {
|
||||||
let dirfd = try FileDescriptor.open(path, .readOnly, options: .directory)
|
let dirfd = try FileDescriptor.open(path, .readOnly, options: .directory)
|
||||||
defer {
|
defer {
|
||||||
try? dirfd.close()
|
try? dirfd.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
let dot: (CInterop.PlatformChar, CInterop.PlatformChar) = (46, 0)
|
let dot: (CInterop.PlatformChar, CInterop.PlatformChar) = (46, 0)
|
||||||
try withUnsafeBytes(of: dot) {
|
try withUnsafeBytes(of: dot) { (bytes) throws(SystemError) in
|
||||||
try recursiveRemove(
|
try recursiveRemove(
|
||||||
in: dirfd.rawValue,
|
in: dirfd.rawValue,
|
||||||
name: $0.assumingMemoryBound(to: CInterop.PlatformChar.self).baseAddress!
|
name: bytes.assumingMemoryBound(to: CInterop.PlatformChar.self).baseAddress!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
try path.withPlatformString {
|
try path.withPlatformString { (platformString) throws(SystemError) in
|
||||||
if system_rmdir($0) != 0 {
|
if system_rmdir(platformString) != 0 {
|
||||||
throw Errno.current
|
throw Errno.current
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,8 +81,8 @@ fileprivate func impl_opendirat(
|
|||||||
fileprivate func forEachFile(
|
fileprivate func forEachFile(
|
||||||
in dirfd: CInt,
|
in dirfd: CInt,
|
||||||
subdir: UnsafePointer<CInterop.PlatformChar>,
|
subdir: UnsafePointer<CInterop.PlatformChar>,
|
||||||
_ body: (system_dirent) throws -> ()
|
_ body: (system_dirent) throws(SystemError) -> ()
|
||||||
) throws {
|
) throws(SystemError) {
|
||||||
guard let dir = impl_opendirat(dirfd, subdir) else {
|
guard let dir = impl_opendirat(dirfd, subdir) else {
|
||||||
throw Errno.current
|
throw Errno.current
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ fileprivate func forEachFile(
|
|||||||
fileprivate func recursiveRemove(
|
fileprivate func recursiveRemove(
|
||||||
in dirfd: CInt,
|
in dirfd: CInt,
|
||||||
name: UnsafePointer<CInterop.PlatformChar>
|
name: UnsafePointer<CInterop.PlatformChar>
|
||||||
) throws {
|
) throws(SystemError) {
|
||||||
// First, deal with subdirectories
|
// First, deal with subdirectories
|
||||||
try forEachFile(in: dirfd, subdir: name) { dirent in
|
try forEachFile(in: dirfd, subdir: name) { dirent in
|
||||||
if dirent.d_type == SYSTEM_DT_DIR {
|
if dirent.d_type == SYSTEM_DT_DIR {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
/// let perms = FilePermissions(rawValue: 0o644)
|
/// let perms = FilePermissions(rawValue: 0o644)
|
||||||
/// perms == [.ownerReadWrite, .groupRead, .otherRead] // true
|
/// perms == [.ownerReadWrite, .groupRead, .otherRead] // true
|
||||||
@frozen
|
@frozen
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
public struct FilePermissions: OptionSet, Sendable, Hashable, Codable {
|
public struct FilePermissions: OptionSet, Sendable, Hashable {
|
||||||
/// The raw C file permissions.
|
/// The raw C file permissions.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public let rawValue: CModeT
|
public let rawValue: CModeT
|
||||||
@@ -132,7 +132,7 @@ public struct FilePermissions: OptionSet, Sendable, Hashable, Codable {
|
|||||||
public static var saveText: FilePermissions { .init(rawValue: 0o1000) }
|
public static var saveText: FilePermissions { .init(rawValue: 0o1000) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
extension FilePermissions
|
extension FilePermissions
|
||||||
: CustomStringConvertible, CustomDebugStringConvertible
|
: CustomStringConvertible, CustomDebugStringConvertible
|
||||||
{
|
{
|
||||||
@@ -172,3 +172,8 @@ extension FilePermissions
|
|||||||
/// A textual representation of the file permissions, suitable for debugging.
|
/// A textual representation of the file permissions, suitable for debugging.
|
||||||
public var debugDescription: String { self.description }
|
public var debugDescription: String { self.description }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !$Embedded
|
||||||
|
@available(System 0.0.1, *)
|
||||||
|
extension FilePermissions: Codable {}
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#if compiler(>=6.2)
|
#if compiler(>=6.2) && $Lifetimes
|
||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
|
|
||||||
import CSystem
|
import CSystem
|
||||||
@@ -67,5 +67,5 @@ public extension IORing.Completion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // os(Linux)
|
||||||
#endif
|
#endif // compiler(>=6.2) && $Lifetimes
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#if compiler(>=6.2)
|
#if compiler(>=6.2) && $Lifetimes
|
||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
|
|
||||||
import CSystem
|
import CSystem
|
||||||
@@ -320,7 +320,7 @@ extension IORing.Request {
|
|||||||
* ASYNC_CANCEL flags.
|
* ASYNC_CANCEL flags.
|
||||||
*
|
*
|
||||||
* IORING_ASYNC_CANCEL_ALL Cancel all requests that match the given key
|
* IORING_ASYNC_CANCEL_ALL Cancel all requests that match the given key
|
||||||
* IORING_ASYNC_CANCEL_FD Key off 'fd' for cancelation rather than the
|
* IORING_ASYNC_CANCEL_FD Key off 'fd' for cancellation rather than the
|
||||||
* request 'user_data'
|
* request 'user_data'
|
||||||
* IORING_ASYNC_CANCEL_ANY Match any request
|
* IORING_ASYNC_CANCEL_ANY Match any request
|
||||||
* IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor
|
* IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor
|
||||||
@@ -493,5 +493,5 @@ extension IORing.Request {
|
|||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // os(Linux)
|
||||||
#endif
|
#endif // compiler(>=6.2) && $Lifetimes
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#if compiler(>=6.2)
|
#if compiler(>=6.2) && $Lifetimes
|
||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
|
|
||||||
import CSystem
|
import CSystem
|
||||||
@@ -10,6 +10,10 @@ import Musl
|
|||||||
#endif
|
#endif
|
||||||
import Synchronization
|
import Synchronization
|
||||||
|
|
||||||
|
private var ioringSupported: Bool {
|
||||||
|
__SWIFT_IORING_SUPPORTED != 0
|
||||||
|
}
|
||||||
|
|
||||||
//This was #defines in older headers, so we redeclare it to get a consistent import
|
//This was #defines in older headers, so we redeclare it to get a consistent import
|
||||||
internal enum RegistrationOps: UInt32 {
|
internal enum RegistrationOps: UInt32 {
|
||||||
case registerBuffers = 0
|
case registerBuffers = 0
|
||||||
@@ -72,7 +76,7 @@ extension UnsafeMutableRawBufferPointer {
|
|||||||
@inline(__always) @inlinable
|
@inline(__always) @inlinable
|
||||||
internal func _tryWriteRequest(
|
internal func _tryWriteRequest(
|
||||||
_ request: __owned RawIORequest, ring: inout SQRing,
|
_ request: __owned RawIORequest, ring: inout SQRing,
|
||||||
submissionQueueEntries: UnsafeMutableBufferPointer<io_uring_sqe>
|
submissionQueueEntries: UnsafeMutableBufferPointer<swift_io_uring_sqe>
|
||||||
)
|
)
|
||||||
-> Bool
|
-> Bool
|
||||||
{
|
{
|
||||||
@@ -151,9 +155,9 @@ internal func _flushQueue(ring: borrowing SQRing) -> UInt32 {
|
|||||||
|
|
||||||
@inlinable
|
@inlinable
|
||||||
internal func _getSubmissionEntry(
|
internal func _getSubmissionEntry(
|
||||||
ring: inout SQRing, submissionQueueEntries: UnsafeMutableBufferPointer<io_uring_sqe>
|
ring: inout SQRing, submissionQueueEntries: UnsafeMutableBufferPointer<swift_io_uring_sqe>
|
||||||
) -> UnsafeMutablePointer<
|
) -> UnsafeMutablePointer<
|
||||||
io_uring_sqe
|
swift_io_uring_sqe
|
||||||
>? {
|
>? {
|
||||||
let next = ring.userTail &+ 1 //this is expected to wrap
|
let next = ring.userTail &+ 1 //this is expected to wrap
|
||||||
|
|
||||||
@@ -196,7 +200,7 @@ private func setUpRing(
|
|||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.features & IORING_FEAT_NODROP == 0
|
if params.features & IORing.Features.nonDroppingCompletions.rawValue == 0
|
||||||
{
|
{
|
||||||
close(ringDescriptor)
|
close(ringDescriptor)
|
||||||
throw Errno.invalidArgument
|
throw Errno.invalidArgument
|
||||||
@@ -223,7 +227,7 @@ private func setUpRing(
|
|||||||
/* prot: */ PROT_READ | PROT_WRITE,
|
/* prot: */ PROT_READ | PROT_WRITE,
|
||||||
/* flags: */ MAP_SHARED | MAP_POPULATE,
|
/* flags: */ MAP_SHARED | MAP_POPULATE,
|
||||||
/* fd: */ ringDescriptor,
|
/* fd: */ ringDescriptor,
|
||||||
/* offset: */ __off_t(IORING_OFF_SQ_RING)
|
/* offset: */ off_t(IORING_OFF_SQ_RING)
|
||||||
)
|
)
|
||||||
|
|
||||||
if ringPtr == MAP_FAILED {
|
if ringPtr == MAP_FAILED {
|
||||||
@@ -238,7 +242,7 @@ private func setUpRing(
|
|||||||
/* prot: */ PROT_READ | PROT_WRITE,
|
/* prot: */ PROT_READ | PROT_WRITE,
|
||||||
/* flags: */ MAP_SHARED | MAP_POPULATE,
|
/* flags: */ MAP_SHARED | MAP_POPULATE,
|
||||||
/* fd: */ ringDescriptor,
|
/* fd: */ ringDescriptor,
|
||||||
/* offset: */ __off_t(IORING_OFF_SQ_RING)
|
/* offset: */ off_t(IORING_OFF_SQ_RING)
|
||||||
)
|
)
|
||||||
|
|
||||||
if sqPtr == MAP_FAILED {
|
if sqPtr == MAP_FAILED {
|
||||||
@@ -253,7 +257,7 @@ private func setUpRing(
|
|||||||
/* prot: */ PROT_READ | PROT_WRITE,
|
/* prot: */ PROT_READ | PROT_WRITE,
|
||||||
/* flags: */ MAP_SHARED | MAP_POPULATE,
|
/* flags: */ MAP_SHARED | MAP_POPULATE,
|
||||||
/* fd: */ ringDescriptor,
|
/* fd: */ ringDescriptor,
|
||||||
/* offset: */ __off_t(IORING_OFF_CQ_RING)
|
/* offset: */ off_t(IORING_OFF_CQ_RING)
|
||||||
)
|
)
|
||||||
|
|
||||||
if cqPtr == MAP_FAILED {
|
if cqPtr == MAP_FAILED {
|
||||||
@@ -266,11 +270,11 @@ private func setUpRing(
|
|||||||
// map the submission queue
|
// map the submission queue
|
||||||
let sqes = mmap(
|
let sqes = mmap(
|
||||||
/* addr: */ nil,
|
/* addr: */ nil,
|
||||||
/* len: */ Int(params.sq_entries) * MemoryLayout<io_uring_sqe>.size,
|
/* len: */ Int(params.sq_entries) * MemoryLayout<swift_io_uring_sqe>.size,
|
||||||
/* prot: */ PROT_READ | PROT_WRITE,
|
/* prot: */ PROT_READ | PROT_WRITE,
|
||||||
/* flags: */ MAP_SHARED | MAP_POPULATE,
|
/* flags: */ MAP_SHARED | MAP_POPULATE,
|
||||||
/* fd: */ ringDescriptor,
|
/* fd: */ ringDescriptor,
|
||||||
/* offset: */ __off_t(IORING_OFF_SQES)
|
/* offset: */ off_t(IORING_OFF_SQES)
|
||||||
)
|
)
|
||||||
|
|
||||||
if sqes == MAP_FAILED {
|
if sqes == MAP_FAILED {
|
||||||
@@ -307,7 +311,7 @@ public struct IORing: ~Copyable {
|
|||||||
|
|
||||||
@usableFromInline let completionRing: CQRing
|
@usableFromInline let completionRing: CQRing
|
||||||
|
|
||||||
@usableFromInline let submissionQueueEntries: UnsafeMutableBufferPointer<io_uring_sqe>
|
@usableFromInline let submissionQueueEntries: UnsafeMutableBufferPointer<swift_io_uring_sqe>
|
||||||
|
|
||||||
// kept around for unmap / cleanup. TODO: we can save a few words of memory by figuring out how to handle cleanup for non-IORING_FEAT_SINGLE_MMAP better
|
// kept around for unmap / cleanup. TODO: we can save a few words of memory by figuring out how to handle cleanup for non-IORING_FEAT_SINGLE_MMAP better
|
||||||
let ringSize: Int
|
let ringSize: Int
|
||||||
@@ -366,76 +370,90 @@ public struct IORing: ~Copyable {
|
|||||||
|
|
||||||
/// Initializes an IORing with enough space for `queueDepth` prepared requests and completed operations
|
/// Initializes an IORing with enough space for `queueDepth` prepared requests and completed operations
|
||||||
public init(queueDepth: UInt32, flags: SetupFlags = []) throws(Errno) {
|
public init(queueDepth: UInt32, flags: SetupFlags = []) throws(Errno) {
|
||||||
|
guard ioringSupported else {
|
||||||
|
throw Errno.notSupported
|
||||||
|
}
|
||||||
|
|
||||||
let (params, tmpRingDescriptor, tmpRingPtr, tmpRingSize, tmpSQPtr, tmpSQSize, tmpCQPtr, tmpCQSize, sqes) = try setUpRing(queueDepth: queueDepth, flags: flags)
|
let (params, tmpRingDescriptor, tmpRingPtr, tmpRingSize, tmpSQPtr, tmpSQSize, tmpCQPtr, tmpCQSize, sqes) = try setUpRing(queueDepth: queueDepth, flags: flags)
|
||||||
// All throws need to be before initializing ivars here to avoid
|
// All throws need to be before initializing ivars here to avoid
|
||||||
// "error: conditional initialization or destruction of noncopyable types is not supported;
|
// "error: conditional initialization or destruction of noncopyable types is not supported;
|
||||||
// this variable must be consistently in an initialized or uninitialized state through every code path"
|
// this variable must be consistently in an initialized or uninitialized state through every code path"
|
||||||
features = Features(rawValue: params.features)
|
|
||||||
ringDescriptor = tmpRingDescriptor
|
// Pre-compute values to avoid accessing partially initialized state
|
||||||
ringPtr = tmpRingPtr
|
let ringBasePtr = tmpRingPtr ?? tmpSQPtr!
|
||||||
ringSize = tmpRingSize
|
let completionBasePtr = tmpRingPtr ?? tmpCQPtr!
|
||||||
submissionRingPtr = tmpSQPtr
|
|
||||||
submissionRingSize = tmpSQSize
|
let submissionRing = SQRing(
|
||||||
completionRingPtr = tmpCQPtr
|
|
||||||
completionRingSize = tmpCQSize
|
|
||||||
|
|
||||||
_registeredFiles = []
|
|
||||||
_registeredBuffers = []
|
|
||||||
submissionRing = SQRing(
|
|
||||||
kernelHead: UnsafePointer<Atomic<UInt32>>(
|
kernelHead: UnsafePointer<Atomic<UInt32>>(
|
||||||
(ringPtr ?? submissionRingPtr!).advanced(by: params.sq_off.head)
|
ringBasePtr.advanced(by: params.sq_off.head)
|
||||||
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
||||||
),
|
),
|
||||||
kernelTail: UnsafePointer<Atomic<UInt32>>(
|
kernelTail: UnsafePointer<Atomic<UInt32>>(
|
||||||
(ringPtr ?? submissionRingPtr!).advanced(by: params.sq_off.tail)
|
ringBasePtr.advanced(by: params.sq_off.tail)
|
||||||
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
||||||
),
|
),
|
||||||
userTail: 0, // no requests yet
|
userTail: 0, // no requests yet
|
||||||
ringMask: (ringPtr ?? submissionRingPtr!).advanced(by: params.sq_off.ring_mask)
|
ringMask: ringBasePtr.advanced(by: params.sq_off.ring_mask)
|
||||||
.assumingMemoryBound(to: UInt32.self).pointee,
|
.assumingMemoryBound(to: UInt32.self).pointee,
|
||||||
flags: UnsafePointer<Atomic<UInt32>>(
|
flags: UnsafePointer<Atomic<UInt32>>(
|
||||||
(ringPtr ?? submissionRingPtr!).advanced(by: params.sq_off.flags)
|
ringBasePtr.advanced(by: params.sq_off.flags)
|
||||||
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
||||||
),
|
),
|
||||||
array: UnsafeMutableBufferPointer(
|
array: UnsafeMutableBufferPointer(
|
||||||
start: (ringPtr ?? submissionRingPtr!).advanced(by: params.sq_off.array)
|
start: ringBasePtr.advanced(by: params.sq_off.array)
|
||||||
.assumingMemoryBound(to: UInt32.self),
|
.assumingMemoryBound(to: UInt32.self),
|
||||||
count: Int(
|
count: Int(
|
||||||
(ringPtr ?? submissionRingPtr!).advanced(by: params.sq_off.ring_entries)
|
ringBasePtr.advanced(by: params.sq_off.ring_entries)
|
||||||
.assumingMemoryBound(to: UInt32.self).pointee)
|
.assumingMemoryBound(to: UInt32.self).pointee)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
// fill submission ring array with 1:1 map to underlying SQEs
|
let completionRing = CQRing(
|
||||||
for i in 0 ..< submissionRing.array.count {
|
|
||||||
submissionRing.array[i] = UInt32(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
submissionQueueEntries = UnsafeMutableBufferPointer(
|
|
||||||
start: sqes.assumingMemoryBound(to: io_uring_sqe.self),
|
|
||||||
count: Int(params.sq_entries)
|
|
||||||
)
|
|
||||||
|
|
||||||
completionRing = CQRing(
|
|
||||||
kernelHead: UnsafePointer<Atomic<UInt32>>(
|
kernelHead: UnsafePointer<Atomic<UInt32>>(
|
||||||
(ringPtr ?? completionRingPtr!).advanced(by: params.cq_off.head)
|
completionBasePtr.advanced(by: params.cq_off.head)
|
||||||
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
||||||
),
|
),
|
||||||
kernelTail: UnsafePointer<Atomic<UInt32>>(
|
kernelTail: UnsafePointer<Atomic<UInt32>>(
|
||||||
(ringPtr ?? completionRingPtr!).advanced(by: params.cq_off.tail)
|
completionBasePtr.advanced(by: params.cq_off.tail)
|
||||||
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
.assumingMemoryBound(to: Atomic<UInt32>.self)
|
||||||
),
|
),
|
||||||
ringMask: (ringPtr ?? completionRingPtr!).advanced(by: params.cq_off.ring_mask)
|
ringMask: completionBasePtr.advanced(by: params.cq_off.ring_mask)
|
||||||
.assumingMemoryBound(to: UInt32.self).pointee,
|
.assumingMemoryBound(to: UInt32.self).pointee,
|
||||||
cqes: UnsafeBufferPointer(
|
cqes: UnsafeBufferPointer(
|
||||||
start: (ringPtr ?? completionRingPtr!).advanced(by: params.cq_off.cqes)
|
start: completionBasePtr.advanced(by: params.cq_off.cqes)
|
||||||
.assumingMemoryBound(to: io_uring_cqe.self),
|
.assumingMemoryBound(to: io_uring_cqe.self),
|
||||||
count: Int(
|
count: Int(
|
||||||
(ringPtr ?? completionRingPtr!).advanced(by: params.cq_off.ring_entries)
|
completionBasePtr.advanced(by: params.cq_off.ring_entries)
|
||||||
.assumingMemoryBound(to: UInt32.self).pointee)
|
.assumingMemoryBound(to: UInt32.self).pointee)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let submissionQueueEntries = UnsafeMutableBufferPointer(
|
||||||
|
start: sqes.assumingMemoryBound(to: swift_io_uring_sqe.self),
|
||||||
|
count: Int(params.sq_entries)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Now initialize all stored properties
|
||||||
|
self.features = Features(rawValue: params.features)
|
||||||
|
self.ringDescriptor = tmpRingDescriptor
|
||||||
|
self.ringPtr = tmpRingPtr
|
||||||
|
self.ringSize = tmpRingSize
|
||||||
|
self.submissionRingPtr = tmpSQPtr
|
||||||
|
self.submissionRingSize = tmpSQSize
|
||||||
|
self.completionRingPtr = tmpCQPtr
|
||||||
|
self.completionRingSize = tmpCQSize
|
||||||
|
self._registeredFiles = []
|
||||||
|
self._registeredBuffers = []
|
||||||
|
self.submissionRing = submissionRing
|
||||||
|
self.completionRing = completionRing
|
||||||
|
self.submissionQueueEntries = submissionQueueEntries
|
||||||
self.ringFlags = params.flags
|
self.ringFlags = params.flags
|
||||||
|
|
||||||
|
// fill submission ring array with 1:1 map to underlying SQEs
|
||||||
|
// (happens after all properties are initialized)
|
||||||
|
for i in 0 ..< self.submissionRing.array.count {
|
||||||
|
self.submissionRing.array[i] = UInt32(i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@inlinable
|
@inlinable
|
||||||
@@ -858,7 +876,7 @@ public struct IORing: ~Copyable {
|
|||||||
}
|
}
|
||||||
munmap(
|
munmap(
|
||||||
UnsafeMutableRawPointer(submissionQueueEntries.baseAddress!),
|
UnsafeMutableRawPointer(submissionQueueEntries.baseAddress!),
|
||||||
submissionQueueEntries.count * MemoryLayout<io_uring_sqe>.size
|
submissionQueueEntries.count * MemoryLayout<swift_io_uring_sqe>.size
|
||||||
)
|
)
|
||||||
close(ringDescriptor)
|
close(ringDescriptor)
|
||||||
}
|
}
|
||||||
@@ -882,5 +900,5 @@ extension IORing.RegisteredBuffer {
|
|||||||
return unsafe _overrideLifetime(span, borrowing: self)
|
return unsafe _overrideLifetime(span, borrowing: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // os(Linux)
|
||||||
#endif
|
#endif // compiler(>=6.2) && $Lifetimes
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
#if compiler(>=6.2)
|
#if compiler(>=6.2) && $Lifetimes
|
||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
|
|
||||||
import CSystem
|
import CSystem
|
||||||
|
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
internal struct RawIORequest: ~Copyable {
|
internal struct RawIORequest: ~Copyable {
|
||||||
@usableFromInline var rawValue: io_uring_sqe
|
// swift_io_uring_sqe is a typedef of io_uring_sqe on platforms where
|
||||||
|
// IORing is supported (currently requires kernel version >= 5.15).
|
||||||
|
@usableFromInline var rawValue: swift_io_uring_sqe
|
||||||
@usableFromInline var path: FilePath? //buffer owner for the path pointer that the sqe may have
|
@usableFromInline var path: FilePath? //buffer owner for the path pointer that the sqe may have
|
||||||
|
|
||||||
@inlinable public init() {
|
@inlinable public init() {
|
||||||
self.rawValue = io_uring_sqe()
|
self.rawValue = swift_io_uring_sqe()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,8 +178,8 @@ extension RawIORequest {
|
|||||||
|
|
||||||
@inlinable
|
@inlinable
|
||||||
static func withTimeoutRequest<R>(
|
static func withTimeoutRequest<R>(
|
||||||
linkedTo opEntry: UnsafeMutablePointer<io_uring_sqe>,
|
linkedTo opEntry: UnsafeMutablePointer<swift_io_uring_sqe>,
|
||||||
in timeoutEntry: UnsafeMutablePointer<io_uring_sqe>,
|
in timeoutEntry: UnsafeMutablePointer<swift_io_uring_sqe>,
|
||||||
duration: Duration,
|
duration: Duration,
|
||||||
flags: TimeOutFlags,
|
flags: TimeOutFlags,
|
||||||
work: () throws -> R) rethrows -> R {
|
work: () throws -> R) rethrows -> R {
|
||||||
@@ -199,5 +201,5 @@ extension RawIORequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // os(Linux)
|
||||||
#endif
|
#endif // compiler(>=6.2) && $Lifetimes
|
||||||
@@ -37,12 +37,12 @@ import Bionic
|
|||||||
public typealias CModeT = CInt
|
public typealias CModeT = CInt
|
||||||
#else
|
#else
|
||||||
/// The C `mode_t` type.
|
/// The C `mode_t` type.
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
public typealias CModeT = mode_t
|
public typealias CModeT = mode_t
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// A namespace for C and platform types
|
/// A namespace for C and platform types
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
public enum CInterop {
|
public enum CInterop {
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
public typealias Mode = CInt
|
public typealias Mode = CInt
|
||||||
|
|||||||
@@ -116,9 +116,9 @@ internal func system_memset(
|
|||||||
|
|
||||||
// Interop between String and platfrom string
|
// Interop between String and platfrom string
|
||||||
extension String {
|
extension String {
|
||||||
internal func _withPlatformString<Result>(
|
internal func _withPlatformString<Success, Failure: Error>(
|
||||||
_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result
|
_ body: (UnsafePointer<CInterop.PlatformChar>) throws(Failure) -> Success
|
||||||
) rethrows -> Result {
|
) throws(Failure) -> Success {
|
||||||
// Need to #if because CChar may be signed
|
// Need to #if because CChar may be signed
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
return try withCString(encodedAs: CInterop.PlatformUnicodeEncoding.self, body)
|
return try withCString(encodedAs: CInterop.PlatformUnicodeEncoding.self, body)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
// enabled in testing builds of System currently, to minimize runtime overhead of release builds.
|
// enabled in testing builds of System currently, to minimize runtime overhead of release builds.
|
||||||
//
|
//
|
||||||
|
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
internal struct Trace {
|
internal struct Trace {
|
||||||
internal struct Entry {
|
internal struct Entry {
|
||||||
|
|
||||||
@@ -115,12 +115,12 @@ extension MockingDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENABLE_MOCKING
|
#endif // ENABLE_MOCKING && !$Embedded
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
internal var mockingEnabled: Bool {
|
internal var mockingEnabled: Bool {
|
||||||
// Fast constant-foldable check for release builds
|
// Fast constant-foldable check for release builds
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
return contextualMockingEnabled
|
return contextualMockingEnabled
|
||||||
#else
|
#else
|
||||||
return false
|
return false
|
||||||
@@ -129,15 +129,15 @@ internal var mockingEnabled: Bool {
|
|||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
internal var forceWindowsPaths: Bool? {
|
internal var forceWindowsPaths: Bool? {
|
||||||
#if !ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
return nil
|
|
||||||
#else
|
|
||||||
return MockingDriver.forceWindowsPaths
|
return MockingDriver.forceWindowsPaths
|
||||||
|
#else
|
||||||
|
return nil
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
// Strip the mock_system prefix and the arg list suffix
|
// Strip the mock_system prefix and the arg list suffix
|
||||||
private func originalSyscallName(_ function: String) -> String {
|
private func originalSyscallName(_ function: String) -> String {
|
||||||
// `function` must be of format `system_<name>(<parameters>)`
|
// `function` must be of format `system_<name>(<parameters>)`
|
||||||
@@ -193,12 +193,12 @@ internal func _mockOffT(
|
|||||||
) -> _COffT {
|
) -> _COffT {
|
||||||
_COffT(mockImpl(name: name, path: path, args))
|
_COffT(mockImpl(name: name, path: path, args))
|
||||||
}
|
}
|
||||||
#endif // ENABLE_MOCKING
|
#endif // ENABLE_MOCKING && !$Embedded
|
||||||
|
|
||||||
// Force paths to be treated as Windows syntactically if `enabled` is
|
// Force paths to be treated as Windows syntactically if `enabled` is
|
||||||
// true, and as POSIX syntactically if not.
|
// true, and as POSIX syntactically if not.
|
||||||
internal func _withWindowsPaths(enabled: Bool, _ body: () -> ()) {
|
internal func _withWindowsPaths(enabled: Bool, _ body: () -> ()) {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
MockingDriver.withMockingEnabled { driver in
|
MockingDriver.withMockingEnabled { driver in
|
||||||
driver.forceWindowsSyntaxForPaths = enabled
|
driver.forceWindowsSyntaxForPaths = enabled
|
||||||
body()
|
body()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
This source file is part of the Swift System open source project
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
Copyright (c) 2020 - 2024 Apple Inc. and the Swift System project authors
|
Copyright (c) 2020 - 2025 Apple Inc. and the Swift System project authors
|
||||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
@@ -14,6 +14,7 @@ import Glibc
|
|||||||
#elseif canImport(Musl)
|
#elseif canImport(Musl)
|
||||||
import Musl
|
import Musl
|
||||||
#elseif canImport(WASILibc)
|
#elseif canImport(WASILibc)
|
||||||
|
import CSystem
|
||||||
import WASILibc
|
import WASILibc
|
||||||
#elseif os(Windows)
|
#elseif os(Windows)
|
||||||
import ucrt
|
import ucrt
|
||||||
@@ -30,7 +31,7 @@ import Android
|
|||||||
internal func system_open(
|
internal func system_open(
|
||||||
_ path: UnsafePointer<CInterop.PlatformChar>, _ oflag: Int32
|
_ path: UnsafePointer<CInterop.PlatformChar>, _ oflag: Int32
|
||||||
) -> CInt {
|
) -> CInt {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled {
|
if mockingEnabled {
|
||||||
return _mock(path: path, oflag)
|
return _mock(path: path, oflag)
|
||||||
}
|
}
|
||||||
@@ -42,7 +43,7 @@ internal func system_open(
|
|||||||
_ path: UnsafePointer<CInterop.PlatformChar>,
|
_ path: UnsafePointer<CInterop.PlatformChar>,
|
||||||
_ oflag: Int32, _ mode: CInterop.Mode
|
_ oflag: Int32, _ mode: CInterop.Mode
|
||||||
) -> CInt {
|
) -> CInt {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled {
|
if mockingEnabled {
|
||||||
return _mock(path: path, oflag, mode)
|
return _mock(path: path, oflag, mode)
|
||||||
}
|
}
|
||||||
@@ -52,7 +53,7 @@ internal func system_open(
|
|||||||
|
|
||||||
// close
|
// close
|
||||||
internal func system_close(_ fd: Int32) -> Int32 {
|
internal func system_close(_ fd: Int32) -> Int32 {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mock(fd) }
|
if mockingEnabled { return _mock(fd) }
|
||||||
#endif
|
#endif
|
||||||
return close(fd)
|
return close(fd)
|
||||||
@@ -62,7 +63,7 @@ internal func system_close(_ fd: Int32) -> Int32 {
|
|||||||
internal func system_read(
|
internal func system_read(
|
||||||
_ fd: Int32, _ buf: UnsafeMutableRawPointer?, _ nbyte: Int
|
_ fd: Int32, _ buf: UnsafeMutableRawPointer?, _ nbyte: Int
|
||||||
) -> Int {
|
) -> Int {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mockInt(fd, buf, nbyte) }
|
if mockingEnabled { return _mockInt(fd, buf, nbyte) }
|
||||||
#endif
|
#endif
|
||||||
return read(fd, buf, nbyte)
|
return read(fd, buf, nbyte)
|
||||||
@@ -72,7 +73,7 @@ internal func system_read(
|
|||||||
internal func system_pread(
|
internal func system_pread(
|
||||||
_ fd: Int32, _ buf: UnsafeMutableRawPointer?, _ nbyte: Int, _ offset: off_t
|
_ fd: Int32, _ buf: UnsafeMutableRawPointer?, _ nbyte: Int, _ offset: off_t
|
||||||
) -> Int {
|
) -> Int {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
|
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
|
||||||
#endif
|
#endif
|
||||||
#if os(Android)
|
#if os(Android)
|
||||||
@@ -90,7 +91,7 @@ internal func system_pread(
|
|||||||
internal func system_lseek(
|
internal func system_lseek(
|
||||||
_ fd: Int32, _ off: off_t, _ whence: Int32
|
_ fd: Int32, _ off: off_t, _ whence: Int32
|
||||||
) -> off_t {
|
) -> off_t {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mockOffT(fd, off, whence) }
|
if mockingEnabled { return _mockOffT(fd, off, whence) }
|
||||||
#endif
|
#endif
|
||||||
return lseek(fd, off, whence)
|
return lseek(fd, off, whence)
|
||||||
@@ -100,7 +101,7 @@ internal func system_lseek(
|
|||||||
internal func system_write(
|
internal func system_write(
|
||||||
_ fd: Int32, _ buf: UnsafeRawPointer?, _ nbyte: Int
|
_ fd: Int32, _ buf: UnsafeRawPointer?, _ nbyte: Int
|
||||||
) -> Int {
|
) -> Int {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mockInt(fd, buf, nbyte) }
|
if mockingEnabled { return _mockInt(fd, buf, nbyte) }
|
||||||
#endif
|
#endif
|
||||||
return write(fd, buf, nbyte)
|
return write(fd, buf, nbyte)
|
||||||
@@ -110,7 +111,7 @@ internal func system_write(
|
|||||||
internal func system_pwrite(
|
internal func system_pwrite(
|
||||||
_ fd: Int32, _ buf: UnsafeRawPointer?, _ nbyte: Int, _ offset: off_t
|
_ fd: Int32, _ buf: UnsafeRawPointer?, _ nbyte: Int, _ offset: off_t
|
||||||
) -> Int {
|
) -> Int {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
|
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
|
||||||
#endif
|
#endif
|
||||||
#if os(Android)
|
#if os(Android)
|
||||||
@@ -126,14 +127,14 @@ internal func system_pwrite(
|
|||||||
|
|
||||||
#if !os(WASI)
|
#if !os(WASI)
|
||||||
internal func system_dup(_ fd: Int32) -> Int32 {
|
internal func system_dup(_ fd: Int32) -> Int32 {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mock(fd) }
|
if mockingEnabled { return _mock(fd) }
|
||||||
#endif
|
#endif
|
||||||
return dup(fd)
|
return dup(fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func system_dup2(_ fd: Int32, _ fd2: Int32) -> Int32 {
|
internal func system_dup2(_ fd: Int32, _ fd2: Int32) -> Int32 {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mock(fd, fd2) }
|
if mockingEnabled { return _mock(fd, fd2) }
|
||||||
#endif
|
#endif
|
||||||
return dup2(fd, fd2)
|
return dup2(fd, fd2)
|
||||||
@@ -142,7 +143,7 @@ internal func system_dup2(_ fd: Int32, _ fd2: Int32) -> Int32 {
|
|||||||
|
|
||||||
#if !os(WASI)
|
#if !os(WASI)
|
||||||
internal func system_pipe(_ fds: UnsafeMutablePointer<Int32>) -> CInt {
|
internal func system_pipe(_ fds: UnsafeMutablePointer<Int32>) -> CInt {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mock(fds) }
|
if mockingEnabled { return _mock(fds) }
|
||||||
#endif
|
#endif
|
||||||
return pipe(fds)
|
return pipe(fds)
|
||||||
@@ -150,7 +151,7 @@ internal func system_pipe(_ fds: UnsafeMutablePointer<Int32>) -> CInt {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal func system_ftruncate(_ fd: Int32, _ length: off_t) -> Int32 {
|
internal func system_ftruncate(_ fd: Int32, _ length: off_t) -> Int32 {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mock(fd, length) }
|
if mockingEnabled { return _mock(fd, length) }
|
||||||
#endif
|
#endif
|
||||||
return ftruncate(fd, length)
|
return ftruncate(fd, length)
|
||||||
@@ -160,7 +161,7 @@ internal func system_mkdir(
|
|||||||
_ path: UnsafePointer<CInterop.PlatformChar>,
|
_ path: UnsafePointer<CInterop.PlatformChar>,
|
||||||
_ mode: CInterop.Mode
|
_ mode: CInterop.Mode
|
||||||
) -> CInt {
|
) -> CInt {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mock(path: path, mode) }
|
if mockingEnabled { return _mock(path: path, mode) }
|
||||||
#endif
|
#endif
|
||||||
return mkdir(path, mode)
|
return mkdir(path, mode)
|
||||||
@@ -169,7 +170,7 @@ internal func system_mkdir(
|
|||||||
internal func system_rmdir(
|
internal func system_rmdir(
|
||||||
_ path: UnsafePointer<CInterop.PlatformChar>
|
_ path: UnsafePointer<CInterop.PlatformChar>
|
||||||
) -> CInt {
|
) -> CInt {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mock(path: path) }
|
if mockingEnabled { return _mock(path: path) }
|
||||||
#endif
|
#endif
|
||||||
return rmdir(path)
|
return rmdir(path)
|
||||||
@@ -189,9 +190,14 @@ internal func system_confstr(
|
|||||||
|
|
||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
internal let SYSTEM_AT_REMOVE_DIR = AT_REMOVEDIR
|
internal let SYSTEM_AT_REMOVE_DIR = AT_REMOVEDIR
|
||||||
|
#if os(WASI)
|
||||||
|
internal let SYSTEM_DT_DIR = _getConst_DT_DIR()
|
||||||
|
internal typealias system_dirent = _system_dirent
|
||||||
|
#else
|
||||||
internal let SYSTEM_DT_DIR = DT_DIR
|
internal let SYSTEM_DT_DIR = DT_DIR
|
||||||
internal typealias system_dirent = dirent
|
internal typealias system_dirent = dirent
|
||||||
#if os(Linux) || os(Android) || os(FreeBSD) || os(OpenBSD)
|
#endif
|
||||||
|
#if os(Linux) || os(Android) || os(FreeBSD) || os(OpenBSD) || os(WASI)
|
||||||
internal typealias system_DIRPtr = OpaquePointer
|
internal typealias system_DIRPtr = OpaquePointer
|
||||||
#else
|
#else
|
||||||
internal typealias system_DIRPtr = UnsafeMutablePointer<DIR>
|
internal typealias system_DIRPtr = UnsafeMutablePointer<DIR>
|
||||||
@@ -202,7 +208,7 @@ internal func system_unlinkat(
|
|||||||
_ path: UnsafePointer<CInterop.PlatformChar>,
|
_ path: UnsafePointer<CInterop.PlatformChar>,
|
||||||
_ flag: CInt
|
_ flag: CInt
|
||||||
) -> CInt {
|
) -> CInt {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled { return _mock(fd, path, flag) }
|
if mockingEnabled { return _mock(fd, path, flag) }
|
||||||
#endif
|
#endif
|
||||||
return unlinkat(fd, path, flag)
|
return unlinkat(fd, path, flag)
|
||||||
@@ -216,8 +222,12 @@ internal func system_fdopendir(
|
|||||||
|
|
||||||
internal func system_readdir(
|
internal func system_readdir(
|
||||||
_ dir: system_DIRPtr
|
_ dir: system_DIRPtr
|
||||||
) -> UnsafeMutablePointer<dirent>? {
|
) -> UnsafeMutablePointer<system_dirent>? {
|
||||||
|
#if os(WASI)
|
||||||
|
return _system_dirent_from_wasi_dirent(readdir(dir))
|
||||||
|
#else
|
||||||
return readdir(dir)
|
return readdir(dir)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func system_rewinddir(
|
internal func system_rewinddir(
|
||||||
@@ -237,7 +247,7 @@ internal func system_openat(
|
|||||||
_ path: UnsafePointer<CInterop.PlatformChar>,
|
_ path: UnsafePointer<CInterop.PlatformChar>,
|
||||||
_ oflag: Int32
|
_ oflag: Int32
|
||||||
) -> CInt {
|
) -> CInt {
|
||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING && !$Embedded
|
||||||
if mockingEnabled {
|
if mockingEnabled {
|
||||||
return _mock(fd, path, oflag)
|
return _mock(fd, path, oflag)
|
||||||
}
|
}
|
||||||
@@ -246,11 +256,13 @@ internal func system_openat(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !os(WASI) // WASI has no umask
|
||||||
internal func system_umask(
|
internal func system_umask(
|
||||||
_ mode: CInterop.Mode
|
_ mode: CInterop.Mode
|
||||||
) -> CInterop.Mode {
|
) -> CInterop.Mode {
|
||||||
return umask(mode)
|
return umask(mode)
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
internal func system_getenv(
|
internal func system_getenv(
|
||||||
_ name: UnsafePointer<CChar>
|
_ name: UnsafePointer<CChar>
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
This source file is part of the Swift System open source project
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
Copyright (c) 2022 Apple Inc. and the Swift System project authors
|
Copyright (c) 2022 - 2025 Apple Inc. and the Swift System project authors
|
||||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if swift(>=5.9) && SYSTEM_PACKAGE_DARWIN
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
|
|
||||||
import Darwin.Mach
|
import Darwin.Mach
|
||||||
|
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public protocol MachPortRight {}
|
public protocol MachPortRight {}
|
||||||
|
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
@inlinable
|
@inlinable
|
||||||
internal func _machPrecondition(
|
internal func _machPrecondition(
|
||||||
file: StaticString = #file,
|
file: StaticString = #file,
|
||||||
@@ -26,10 +26,10 @@ internal func _machPrecondition(
|
|||||||
precondition(kr == expected, file: file, line: line)
|
precondition(kr == expected, file: file, line: line)
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
@frozen
|
@frozen
|
||||||
public enum Mach {
|
public enum Mach {
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public struct Port<RightType: MachPortRight>: ~Copyable {
|
public struct Port<RightType: MachPortRight>: ~Copyable {
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
internal var _name: mach_port_name_t
|
internal var _name: mach_port_name_t
|
||||||
@@ -133,7 +133,7 @@ public enum Mach {
|
|||||||
public struct SendOnceRight: MachPortRight {}
|
public struct SendOnceRight: MachPortRight {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
extension Mach.Port where RightType == Mach.ReceiveRight {
|
extension Mach.Port where RightType == Mach.ReceiveRight {
|
||||||
/// Transfer ownership of an existing, unmanaged, but already guarded,
|
/// Transfer ownership of an existing, unmanaged, but already guarded,
|
||||||
/// Mach port right into a Mach.Port by name.
|
/// Mach port right into a Mach.Port by name.
|
||||||
@@ -158,7 +158,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
|||||||
/// This initializer will abort if the right could not be created.
|
/// This initializer will abort if the right could not be created.
|
||||||
/// Callers may assert that a valid right is always returned.
|
/// Callers may assert that a valid right is always returned.
|
||||||
@inlinable
|
@inlinable
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public init() {
|
public init() {
|
||||||
var storage: mach_port_name_t = mach_port_name_t(MACH_PORT_NULL)
|
var storage: mach_port_name_t = mach_port_name_t(MACH_PORT_NULL)
|
||||||
_machPrecondition(
|
_machPrecondition(
|
||||||
@@ -181,7 +181,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
|||||||
/// After this function completes, the Mach.Port is destroyed and no longer
|
/// After this function completes, the Mach.Port is destroyed and no longer
|
||||||
/// usable.
|
/// usable.
|
||||||
@inlinable
|
@inlinable
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public consuming func relinquish(
|
public consuming func relinquish(
|
||||||
) -> (name: mach_port_name_t, context: mach_port_context_t) {
|
) -> (name: mach_port_name_t, context: mach_port_context_t) {
|
||||||
let destructured = (name: _name, context: _context)
|
let destructured = (name: _name, context: _context)
|
||||||
@@ -204,7 +204,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
|||||||
/// Mach.ReceiveRights. Use relinquish() to avoid the syscall and extract
|
/// Mach.ReceiveRights. Use relinquish() to avoid the syscall and extract
|
||||||
/// the context value along with the port name.
|
/// the context value along with the port name.
|
||||||
@inlinable
|
@inlinable
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public consuming func unguardAndRelinquish() -> mach_port_name_t {
|
public consuming func unguardAndRelinquish() -> mach_port_name_t {
|
||||||
let (name, context) = self.relinquish()
|
let (name, context) = self.relinquish()
|
||||||
_machPrecondition(mach_port_unguard(mach_task_self_, name, context))
|
_machPrecondition(mach_port_unguard(mach_task_self_, name, context))
|
||||||
@@ -221,7 +221,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
|||||||
/// The body block may optionally return something, which will then be
|
/// The body block may optionally return something, which will then be
|
||||||
/// returned to the caller of withBorrowedName.
|
/// returned to the caller of withBorrowedName.
|
||||||
@inlinable
|
@inlinable
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public func withBorrowedName<ReturnType>(
|
public func withBorrowedName<ReturnType>(
|
||||||
body: (mach_port_name_t, mach_port_context_t) -> ReturnType
|
body: (mach_port_name_t, mach_port_context_t) -> ReturnType
|
||||||
) -> ReturnType {
|
) -> ReturnType {
|
||||||
@@ -235,7 +235,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
|||||||
/// This function will abort if the right could not be created.
|
/// This function will abort if the right could not be created.
|
||||||
/// Callers may assert that a valid right is always returned.
|
/// Callers may assert that a valid right is always returned.
|
||||||
@inlinable
|
@inlinable
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public func makeSendOnceRight() -> Mach.Port<Mach.SendOnceRight> {
|
public func makeSendOnceRight() -> Mach.Port<Mach.SendOnceRight> {
|
||||||
// send once rights do not coalesce
|
// send once rights do not coalesce
|
||||||
var newRight: mach_port_name_t = mach_port_name_t(MACH_PORT_NULL)
|
var newRight: mach_port_name_t = mach_port_name_t(MACH_PORT_NULL)
|
||||||
@@ -264,7 +264,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
|||||||
/// This function will abort if the right could not be created.
|
/// This function will abort if the right could not be created.
|
||||||
/// Callers may assert that a valid right is always returned.
|
/// Callers may assert that a valid right is always returned.
|
||||||
@inlinable
|
@inlinable
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public func makeSendRight() -> Mach.Port<Mach.SendRight> {
|
public func makeSendRight() -> Mach.Port<Mach.SendRight> {
|
||||||
let how = MACH_MSG_TYPE_MAKE_SEND
|
let how = MACH_MSG_TYPE_MAKE_SEND
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
|||||||
///
|
///
|
||||||
/// Each get/set of this property makes a syscall.
|
/// Each get/set of this property makes a syscall.
|
||||||
@inlinable
|
@inlinable
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public var makeSendCount: mach_port_mscount_t {
|
public var makeSendCount: mach_port_mscount_t {
|
||||||
get {
|
get {
|
||||||
var status: mach_port_status = mach_port_status()
|
var status: mach_port_status = mach_port_status()
|
||||||
@@ -311,7 +311,7 @@ extension Mach.Port where RightType == Mach.ReceiveRight {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
extension Mach.Port where RightType == Mach.SendRight {
|
extension Mach.Port where RightType == Mach.SendRight {
|
||||||
/// Transfer ownership of the underlying port right to the caller.
|
/// Transfer ownership of the underlying port right to the caller.
|
||||||
///
|
///
|
||||||
@@ -337,7 +337,7 @@ extension Mach.Port where RightType == Mach.SendRight {
|
|||||||
/// receiving side has been deallocated, then copySendRight() will throw
|
/// receiving side has been deallocated, then copySendRight() will throw
|
||||||
/// a Mach.PortRightError.deadName error.
|
/// a Mach.PortRightError.deadName error.
|
||||||
@inlinable
|
@inlinable
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public func copySendRight() throws -> Mach.Port<Mach.SendRight> {
|
public func copySendRight() throws -> Mach.Port<Mach.SendRight> {
|
||||||
let how = MACH_MSG_TYPE_COPY_SEND
|
let how = MACH_MSG_TYPE_COPY_SEND
|
||||||
|
|
||||||
@@ -354,7 +354,7 @@ extension Mach.Port where RightType == Mach.SendRight {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
extension Mach.Port where RightType == Mach.SendOnceRight {
|
extension Mach.Port where RightType == Mach.SendOnceRight {
|
||||||
/// Transfer ownership of the underlying port right to the caller.
|
/// Transfer ownership of the underlying port right to the caller.
|
||||||
///
|
///
|
||||||
@@ -366,7 +366,7 @@ extension Mach.Port where RightType == Mach.SendOnceRight {
|
|||||||
/// After this function completes, the Mach.Port is destroyed and no longer
|
/// After this function completes, the Mach.Port is destroyed and no longer
|
||||||
/// usable.
|
/// usable.
|
||||||
@inlinable
|
@inlinable
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
public consuming func relinquish() -> mach_port_name_t {
|
public consuming func relinquish() -> mach_port_name_t {
|
||||||
let name = _name
|
let name = _name
|
||||||
discard self
|
discard self
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension String {
|
extension String {
|
||||||
/// Creates a string by interpreting the null-terminated platform string as
|
/// Creates a string by interpreting the null-terminated platform string as
|
||||||
/// UTF-8 on Unix and UTF-16 on Windows.
|
/// UTF-8 on Unix and UTF-16 on Windows.
|
||||||
@@ -158,14 +158,14 @@ extension String {
|
|||||||
/// only during the execution of this method.
|
/// only during the execution of this method.
|
||||||
/// Don't try to store the pointer for later use.
|
/// Don't try to store the pointer for later use.
|
||||||
public func withPlatformString<Result>(
|
public func withPlatformString<Result>(
|
||||||
_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result
|
_ body: (UnsafePointer<CInterop.PlatformChar>) throws(SystemError) -> Result
|
||||||
) rethrows -> Result {
|
) throws(SystemError) -> Result {
|
||||||
try _withPlatformString(body)
|
try _withPlatformString(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension CInterop.PlatformChar {
|
extension CInterop.PlatformChar {
|
||||||
internal var _platformCodeUnit: CInterop.PlatformUnicodeEncoding.CodeUnit {
|
internal var _platformCodeUnit: CInterop.PlatformUnicodeEncoding.CodeUnit {
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
@@ -176,7 +176,7 @@ extension CInterop.PlatformChar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension CInterop.PlatformUnicodeEncoding.CodeUnit {
|
extension CInterop.PlatformUnicodeEncoding.CodeUnit {
|
||||||
internal var _platformChar: CInterop.PlatformChar {
|
internal var _platformChar: CInterop.PlatformChar {
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
@@ -189,8 +189,8 @@ extension CInterop.PlatformUnicodeEncoding.CodeUnit {
|
|||||||
|
|
||||||
internal protocol _PlatformStringable {
|
internal protocol _PlatformStringable {
|
||||||
func _withPlatformString<Result>(
|
func _withPlatformString<Result>(
|
||||||
_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result
|
_ body: (UnsafePointer<CInterop.PlatformChar>) throws(SystemError) -> Result
|
||||||
) rethrows -> Result
|
) throws(SystemError) -> Result
|
||||||
|
|
||||||
init?(_platformString: UnsafePointer<CInterop.PlatformChar>)
|
init?(_platformString: UnsafePointer<CInterop.PlatformChar>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// A platform-native character representation, currently used for file paths
|
// A platform-native character representation, currently used for file paths
|
||||||
internal struct SystemChar:
|
internal struct SystemChar:
|
||||||
RawRepresentable, Sendable, Comparable, Hashable, Codable {
|
RawRepresentable, Sendable, Comparable, Hashable {
|
||||||
internal typealias RawValue = CInterop.PlatformChar
|
internal typealias RawValue = CInterop.PlatformChar
|
||||||
|
|
||||||
internal var rawValue: RawValue
|
internal var rawValue: RawValue
|
||||||
@@ -23,6 +23,12 @@ internal struct SystemChar:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !$Embedded
|
||||||
|
|
||||||
|
extension SystemChar: Codable {}
|
||||||
|
|
||||||
|
#endif // !$Embedded
|
||||||
|
|
||||||
extension SystemChar {
|
extension SystemChar {
|
||||||
internal init(ascii: Unicode.Scalar) {
|
internal init(ascii: Unicode.Scalar) {
|
||||||
self.init(rawValue: numericCast(UInt8(ascii: ascii)))
|
self.init(rawValue: numericCast(UInt8(ascii: ascii)))
|
||||||
@@ -104,7 +110,7 @@ extension SystemString {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _invariantCheck() {
|
fileprivate func _invariantCheck() {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
precondition(_invariantsSatisfied())
|
precondition(_invariantsSatisfied())
|
||||||
@@ -173,10 +179,14 @@ extension SystemString: RangeReplaceableCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SystemString: Hashable, Codable {
|
extension SystemString: Hashable {}
|
||||||
|
|
||||||
|
#if !$Embedded
|
||||||
|
|
||||||
|
extension SystemString: Codable {
|
||||||
// Encoder is synthesized; it probably should have been explicit and used
|
// Encoder is synthesized; it probably should have been explicit and used
|
||||||
// a single-value container, but making that change now is somewhat risky.
|
// a single-value container, but making that change now is somewhat risky.
|
||||||
|
|
||||||
// Decoder is written explicitly to ensure that we validate invariants on
|
// Decoder is written explicitly to ensure that we validate invariants on
|
||||||
// untrusted input.
|
// untrusted input.
|
||||||
public init(from decoder: any Decoder) throws {
|
public init(from decoder: any Decoder) throws {
|
||||||
@@ -195,6 +205,8 @@ extension SystemString: Hashable, Codable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // !$Embedded
|
||||||
|
|
||||||
extension SystemString {
|
extension SystemString {
|
||||||
|
|
||||||
internal func withNullTerminatedSystemChars<T>(
|
internal func withNullTerminatedSystemChars<T>(
|
||||||
|
|||||||
@@ -8,21 +8,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Results in errno if i == -1
|
// Results in errno if i == -1
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
private func valueOrErrno<I: FixedWidthInteger>(
|
private func valueOrErrno<I: FixedWidthInteger>(
|
||||||
_ i: I
|
_ i: I
|
||||||
) -> Result<I, Errno> {
|
) -> Result<I, Errno> {
|
||||||
i == -1 ? .failure(Errno.current) : .success(i)
|
i == -1 ? .failure(Errno.current) : .success(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
private func nothingOrErrno<I: FixedWidthInteger>(
|
private func nothingOrErrno<I: FixedWidthInteger>(
|
||||||
_ i: I
|
_ i: I
|
||||||
) -> Result<(), Errno> {
|
) -> Result<(), Errno> {
|
||||||
valueOrErrno(i).map { _ in () }
|
valueOrErrno(i).map { _ in () }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
internal func valueOrErrno<I: FixedWidthInteger>(
|
internal func valueOrErrno<I: FixedWidthInteger>(
|
||||||
retryOnInterrupt: Bool, _ f: () -> I
|
retryOnInterrupt: Bool, _ f: () -> I
|
||||||
) -> Result<I, Errno> {
|
) -> Result<I, Errno> {
|
||||||
@@ -36,13 +36,15 @@ internal func valueOrErrno<I: FixedWidthInteger>(
|
|||||||
} while true
|
} while true
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
internal func nothingOrErrno<I: FixedWidthInteger>(
|
internal func nothingOrErrno<I: FixedWidthInteger>(
|
||||||
retryOnInterrupt: Bool, _ f: () -> I
|
retryOnInterrupt: Bool, _ f: () -> I
|
||||||
) -> Result<(), Errno> {
|
) -> Result<(), Errno> {
|
||||||
valueOrErrno(retryOnInterrupt: retryOnInterrupt, f).map { _ in () }
|
valueOrErrno(retryOnInterrupt: retryOnInterrupt, f).map { _ in () }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !$Embedded
|
||||||
|
|
||||||
// Run a precondition for debug client builds
|
// Run a precondition for debug client builds
|
||||||
internal func _debugPrecondition(
|
internal func _debugPrecondition(
|
||||||
_ condition: @autoclosure () -> Bool,
|
_ condition: @autoclosure () -> Bool,
|
||||||
@@ -56,6 +58,8 @@ internal func _debugPrecondition(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // !$Embedded
|
||||||
|
|
||||||
extension OpaquePointer {
|
extension OpaquePointer {
|
||||||
internal var _isNULL: Bool {
|
internal var _isNULL: Bool {
|
||||||
OpaquePointer(bitPattern: Int(bitPattern: self)) == nil
|
OpaquePointer(bitPattern: Int(bitPattern: self)) == nil
|
||||||
|
|||||||
@@ -52,13 +52,13 @@ extension Slice where Element: Equatable {
|
|||||||
return self[...idx]
|
return self[...idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
// If `e` is present, eat up to first occurence of `e`
|
// If `e` is present, eat up to first occurrence of `e`
|
||||||
internal mutating func _eatUntil(_ e: Element) -> Slice? {
|
internal mutating func _eatUntil(_ e: Element) -> Slice? {
|
||||||
guard let idx = self.firstIndex(of: e) else { return nil }
|
guard let idx = self.firstIndex(of: e) else { return nil }
|
||||||
return _eatUntil(idx)
|
return _eatUntil(idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If `e` is present, eat up to and through first occurence of `e`
|
// If `e` is present, eat up to and through first occurrence of `e`
|
||||||
internal mutating func _eatThrough(_ e: Element) -> Slice? {
|
internal mutating func _eatThrough(_ e: Element) -> Slice? {
|
||||||
guard let idx = self.firstIndex(of: e) else { return nil }
|
guard let idx = self.firstIndex(of: e) else { return nil }
|
||||||
return _eatThrough(idx)
|
return _eatThrough(idx)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
This source file is part of the Swift System open source project
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
Copyright (c) 2020 Apple Inc. and the Swift System project authors
|
Copyright (c) 2020 - 2025 Apple Inc. and the Swift System project authors
|
||||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
@@ -19,7 +19,7 @@ import System
|
|||||||
import WinSDK
|
import WinSDK
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
final class ErrnoTest: XCTestCase {
|
final class ErrnoTest: XCTestCase {
|
||||||
func testConstants() {
|
func testConstants() {
|
||||||
XCTAssert(EPERM == Errno.notPermitted.rawValue)
|
XCTAssert(EPERM == Errno.notPermitted.rawValue)
|
||||||
@@ -36,7 +36,7 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(ENOMEM == Errno.noMemory.rawValue)
|
XCTAssert(ENOMEM == Errno.noMemory.rawValue)
|
||||||
XCTAssert(EACCES == Errno.permissionDenied.rawValue)
|
XCTAssert(EACCES == Errno.permissionDenied.rawValue)
|
||||||
XCTAssert(EFAULT == Errno.badAddress.rawValue)
|
XCTAssert(EFAULT == Errno.badAddress.rawValue)
|
||||||
#if !os(Windows)
|
#if !os(Windows) && !os(WASI)
|
||||||
XCTAssert(ENOTBLK == Errno.notBlockDevice.rawValue)
|
XCTAssert(ENOTBLK == Errno.notBlockDevice.rawValue)
|
||||||
#endif
|
#endif
|
||||||
XCTAssert(EBUSY == Errno.resourceBusy.rawValue)
|
XCTAssert(EBUSY == Errno.resourceBusy.rawValue)
|
||||||
@@ -74,9 +74,11 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(WSAEOPNOTSUPP == Errno.notSupported.rawValue)
|
XCTAssert(WSAEOPNOTSUPP == Errno.notSupported.rawValue)
|
||||||
XCTAssert(WSAEPFNOSUPPORT == Errno.protocolFamilyNotSupported.rawValue)
|
XCTAssert(WSAEPFNOSUPPORT == Errno.protocolFamilyNotSupported.rawValue)
|
||||||
#else
|
#else
|
||||||
XCTAssert(ESOCKTNOSUPPORT == Errno.socketTypeNotSupported.rawValue)
|
|
||||||
XCTAssert(ENOTSUP == Errno.notSupported.rawValue)
|
XCTAssert(ENOTSUP == Errno.notSupported.rawValue)
|
||||||
|
#if !os(WASI)
|
||||||
|
XCTAssert(ESOCKTNOSUPPORT == Errno.socketTypeNotSupported.rawValue)
|
||||||
XCTAssert(EPFNOSUPPORT == Errno.protocolFamilyNotSupported.rawValue)
|
XCTAssert(EPFNOSUPPORT == Errno.protocolFamilyNotSupported.rawValue)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
XCTAssert(EAFNOSUPPORT == Errno.addressFamilyNotSupported.rawValue)
|
XCTAssert(EAFNOSUPPORT == Errno.addressFamilyNotSupported.rawValue)
|
||||||
XCTAssert(EADDRINUSE == Errno.addressInUse.rawValue)
|
XCTAssert(EADDRINUSE == Errno.addressInUse.rawValue)
|
||||||
@@ -91,7 +93,7 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(ENOTCONN == Errno.socketNotConnected.rawValue)
|
XCTAssert(ENOTCONN == Errno.socketNotConnected.rawValue)
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
XCTAssert(WSAESHUTDOWN == Errno.socketShutdown.rawValue)
|
XCTAssert(WSAESHUTDOWN == Errno.socketShutdown.rawValue)
|
||||||
#else
|
#elseif !os(WASI)
|
||||||
XCTAssert(ESHUTDOWN == Errno.socketShutdown.rawValue)
|
XCTAssert(ESHUTDOWN == Errno.socketShutdown.rawValue)
|
||||||
#endif
|
#endif
|
||||||
XCTAssert(ETIMEDOUT == Errno.timedOut.rawValue)
|
XCTAssert(ETIMEDOUT == Errno.timedOut.rawValue)
|
||||||
@@ -100,7 +102,7 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(ENAMETOOLONG == Errno.fileNameTooLong.rawValue)
|
XCTAssert(ENAMETOOLONG == Errno.fileNameTooLong.rawValue)
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
XCTAssert(WSAEHOSTDOWN == Errno.hostIsDown.rawValue)
|
XCTAssert(WSAEHOSTDOWN == Errno.hostIsDown.rawValue)
|
||||||
#else
|
#elseif !os(WASI)
|
||||||
XCTAssert(EHOSTDOWN == Errno.hostIsDown.rawValue)
|
XCTAssert(EHOSTDOWN == Errno.hostIsDown.rawValue)
|
||||||
#endif
|
#endif
|
||||||
XCTAssert(EHOSTUNREACH == Errno.noRouteToHost.rawValue)
|
XCTAssert(EHOSTUNREACH == Errno.noRouteToHost.rawValue)
|
||||||
@@ -115,7 +117,9 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(WSAEDQUOT == Errno.diskQuotaExceeded.rawValue)
|
XCTAssert(WSAEDQUOT == Errno.diskQuotaExceeded.rawValue)
|
||||||
XCTAssert(WSAESTALE == Errno.staleNFSFileHandle.rawValue)
|
XCTAssert(WSAESTALE == Errno.staleNFSFileHandle.rawValue)
|
||||||
#else
|
#else
|
||||||
|
#if !os(WASI)
|
||||||
XCTAssert(EUSERS == Errno.tooManyUsers.rawValue)
|
XCTAssert(EUSERS == Errno.tooManyUsers.rawValue)
|
||||||
|
#endif
|
||||||
XCTAssert(EDQUOT == Errno.diskQuotaExceeded.rawValue)
|
XCTAssert(EDQUOT == Errno.diskQuotaExceeded.rawValue)
|
||||||
XCTAssert(ESTALE == Errno.staleNFSFileHandle.rawValue)
|
XCTAssert(ESTALE == Errno.staleNFSFileHandle.rawValue)
|
||||||
#endif
|
#endif
|
||||||
@@ -171,7 +175,7 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(EPROTO == Errno.protocolError.rawValue)
|
XCTAssert(EPROTO == Errno.protocolError.rawValue)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !os(Windows) && !os(FreeBSD)
|
#if !os(Windows) && !os(FreeBSD) && !os(WASI)
|
||||||
XCTAssert(ENODATA == Errno.noData.rawValue)
|
XCTAssert(ENODATA == Errno.noData.rawValue)
|
||||||
XCTAssert(ENOSR == Errno.noStreamResources.rawValue)
|
XCTAssert(ENOSR == Errno.noStreamResources.rawValue)
|
||||||
XCTAssert(ENOSTR == Errno.notStream.rawValue)
|
XCTAssert(ENOSTR == Errno.notStream.rawValue)
|
||||||
@@ -181,11 +185,13 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(EOPNOTSUPP == Errno.notSupportedOnSocket.rawValue)
|
XCTAssert(EOPNOTSUPP == Errno.notSupportedOnSocket.rawValue)
|
||||||
|
|
||||||
// From headers but not man page
|
// From headers but not man page
|
||||||
|
#if !os(WASI) // Would need to use _getConst func from CSystem
|
||||||
XCTAssert(EWOULDBLOCK == Errno.wouldBlock.rawValue)
|
XCTAssert(EWOULDBLOCK == Errno.wouldBlock.rawValue)
|
||||||
|
#endif
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
XCTAssert(WSAETOOMANYREFS == Errno.tooManyReferences.rawValue)
|
XCTAssert(WSAETOOMANYREFS == Errno.tooManyReferences.rawValue)
|
||||||
XCTAssert(WSAEREMOTE == Errno.tooManyRemoteLevels.rawValue)
|
XCTAssert(WSAEREMOTE == Errno.tooManyRemoteLevels.rawValue)
|
||||||
#else
|
#elseif !os(WASI)
|
||||||
XCTAssert(ETOOMANYREFS == Errno.tooManyReferences.rawValue)
|
XCTAssert(ETOOMANYREFS == Errno.tooManyReferences.rawValue)
|
||||||
XCTAssert(EREMOTE == Errno.tooManyRemoteLevels.rawValue)
|
XCTAssert(EREMOTE == Errno.tooManyRemoteLevels.rawValue)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
This source file is part of the Swift System open source project
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
Copyright (c) 2020 Apple Inc. and the Swift System project authors
|
Copyright (c) 2020 - 2025 Apple Inc. and the Swift System project authors
|
||||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
@@ -16,10 +16,13 @@ import XCTest
|
|||||||
#endif
|
#endif
|
||||||
#if canImport(Android)
|
#if canImport(Android)
|
||||||
import Android
|
import Android
|
||||||
|
#elseif os(WASI)
|
||||||
|
import CSystem
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
final class FileOperationsTest: XCTestCase {
|
final class FileOperationsTest: XCTestCase {
|
||||||
|
#if ENABLE_MOCKING && !os(WASI) // Would need to use _getConst funcs from CSystem
|
||||||
func testSyscalls() {
|
func testSyscalls() {
|
||||||
let fd = FileDescriptor(rawValue: 1)
|
let fd = FileDescriptor(rawValue: 1)
|
||||||
|
|
||||||
@@ -88,6 +91,7 @@ final class FileOperationsTest: XCTestCase {
|
|||||||
|
|
||||||
for test in syscallTestCases { test.runAllTests() }
|
for test in syscallTestCases { test.runAllTests() }
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MOCKING && !os(WASI)
|
||||||
|
|
||||||
func testWriteFromEmptyBuffer() throws {
|
func testWriteFromEmptyBuffer() throws {
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
@@ -153,6 +157,7 @@ final class FileOperationsTest: XCTestCase {
|
|||||||
// TODO: Test writeAll, writeAll(toAbsoluteOffset), closeAfter
|
// TODO: Test writeAll, writeAll(toAbsoluteOffset), closeAfter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !os(WASI) // WASI has no pipe
|
||||||
func testAdHocPipe() throws {
|
func testAdHocPipe() throws {
|
||||||
// Ad-hoc test testing `Pipe` functionality.
|
// Ad-hoc test testing `Pipe` functionality.
|
||||||
// We cannot test `Pipe` using `MockTestCase` because it calls `pipe` with a pointer to an array local to the `Pipe`, the address of which we do not know prior to invoking `Pipe`.
|
// We cannot test `Pipe` using `MockTestCase` because it calls `pipe` with a pointer to an array local to the `Pipe`, the address of which we do not know prior to invoking `Pipe`.
|
||||||
@@ -171,6 +176,7 @@ final class FileOperationsTest: XCTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
func testAdHocOpen() {
|
func testAdHocOpen() {
|
||||||
// Ad-hoc test touching a file system.
|
// Ad-hoc test touching a file system.
|
||||||
@@ -209,10 +215,16 @@ final class FileOperationsTest: XCTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MOCKING
|
||||||
func testGithubIssues() {
|
func testGithubIssues() {
|
||||||
// https://github.com/apple/swift-system/issues/26
|
// https://github.com/apple/swift-system/issues/26
|
||||||
|
#if os(WASI)
|
||||||
|
let openOptions = _getConst_O_WRONLY() | _getConst_O_CREAT()
|
||||||
|
#else
|
||||||
|
let openOptions = O_WRONLY | O_CREAT
|
||||||
|
#endif
|
||||||
let issue26 = MockTestCase(
|
let issue26 = MockTestCase(
|
||||||
name: "open", .interruptable, "a path", O_WRONLY | O_CREAT, 0o020
|
name: "open", .interruptable, "a path", openOptions, 0o020
|
||||||
) {
|
) {
|
||||||
retryOnInterrupt in
|
retryOnInterrupt in
|
||||||
_ = try FileDescriptor.open(
|
_ = try FileDescriptor.open(
|
||||||
@@ -221,8 +233,8 @@ final class FileOperationsTest: XCTestCase {
|
|||||||
retryOnInterrupt: retryOnInterrupt)
|
retryOnInterrupt: retryOnInterrupt)
|
||||||
}
|
}
|
||||||
issue26.runAllTests()
|
issue26.runAllTests()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MOCKING
|
||||||
|
|
||||||
func testResizeFile() throws {
|
func testResizeFile() throws {
|
||||||
try withTemporaryFilePath(basename: "testResizeFile") { path in
|
try withTemporaryFilePath(basename: "testResizeFile") { path in
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import XCTest
|
|||||||
@testable import System
|
@testable import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
struct TestPathComponents: TestCase {
|
struct TestPathComponents: TestCase {
|
||||||
var path: FilePath
|
var path: FilePath
|
||||||
var expectedRoot: FilePath.Root?
|
var expectedRoot: FilePath.Root?
|
||||||
@@ -100,7 +100,7 @@ struct TestPathComponents: TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
final class FilePathComponentsTest: XCTestCase {
|
final class FilePathComponentsTest: XCTestCase {
|
||||||
func testAdHocRRC() {
|
func testAdHocRRC() {
|
||||||
var path: FilePath = "/usr/local/bin"
|
var path: FilePath = "/usr/local/bin"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import XCTest
|
|||||||
@testable import System
|
@testable import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
final class FilePathDecodableTest: XCTestCase {
|
final class FilePathDecodableTest: XCTestCase {
|
||||||
func testInvalidFilePath() {
|
func testInvalidFilePath() {
|
||||||
// _storage is a valid SystemString, but the invariants of FilePath are
|
// _storage is a valid SystemString, but the invariants of FilePath are
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Why can't I write this extension on `FilePath.ComponentView.SubSequence`?
|
// Why can't I write this extension on `FilePath.ComponentView.SubSequence`?
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension Slice where Base == FilePath.ComponentView {
|
extension Slice where Base == FilePath.ComponentView {
|
||||||
internal var _storageSlice: SystemString.SubSequence {
|
internal var _storageSlice: SystemString.SubSequence {
|
||||||
base._path._storage[self.startIndex._storage ..< self.endIndex._storage]
|
base._path._storage[self.startIndex._storage ..< self.endIndex._storage]
|
||||||
@@ -15,7 +15,7 @@ extension Slice where Base == FilePath.ComponentView {
|
|||||||
|
|
||||||
|
|
||||||
// Proposed API that didn't make the cut, but we stil want to keep our testing for
|
// Proposed API that didn't make the cut, but we stil want to keep our testing for
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Returns `self` relative to `base`.
|
/// Returns `self` relative to `base`.
|
||||||
/// This does not cosult the file system or resolve symlinks.
|
/// This does not cosult the file system or resolve symlinks.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if ENABLE_MOCKING
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
#if SYSTEM_PACKAGE
|
#if SYSTEM_PACKAGE
|
||||||
@@ -68,7 +69,7 @@ extension ParsingTestCase {
|
|||||||
@testable import System
|
@testable import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
final class FilePathParsingTest: XCTestCase {
|
final class FilePathParsingTest: XCTestCase {
|
||||||
func testNormalization() {
|
func testNormalization() {
|
||||||
let unixPaths: Array<ParsingTestCase> = [
|
let unixPaths: Array<ParsingTestCase> = [
|
||||||
@@ -105,3 +106,4 @@ final class FilePathParsingTest: XCTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MOCKING
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if ENABLE_MOCKING
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
#if SYSTEM_PACKAGE
|
#if SYSTEM_PACKAGE
|
||||||
@@ -146,7 +147,7 @@ extension SyntaxTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension SyntaxTestCase {
|
extension SyntaxTestCase {
|
||||||
func testComponents(_ path: FilePath, expected: [String]) {
|
func testComponents(_ path: FilePath, expected: [String]) {
|
||||||
let expectedComponents = expected.map { FilePath.Component($0)! }
|
let expectedComponents = expected.map { FilePath.Component($0)! }
|
||||||
@@ -342,7 +343,7 @@ private struct WindowsRootTestCase: TestCase {
|
|||||||
var line: UInt
|
var line: UInt
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
extension WindowsRootTestCase {
|
extension WindowsRootTestCase {
|
||||||
func runAllTests() {
|
func runAllTests() {
|
||||||
withWindowsPaths(enabled: true) {
|
withWindowsPaths(enabled: true) {
|
||||||
@@ -357,7 +358,7 @@ extension WindowsRootTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
final class FilePathSyntaxTest: XCTestCase {
|
final class FilePathSyntaxTest: XCTestCase {
|
||||||
func testPathSyntax() {
|
func testPathSyntax() {
|
||||||
let unixPaths: Array<SyntaxTestCase> = [
|
let unixPaths: Array<SyntaxTestCase> = [
|
||||||
@@ -1238,3 +1239,4 @@ final class FilePathSyntaxTest: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MOCKING
|
||||||
@@ -15,7 +15,7 @@ import SystemPackage
|
|||||||
import System
|
import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
func filePathFromInvalidCodePointSequence<S: Sequence>(_ bytes: S) -> FilePath where S.Element == CInterop.PlatformUnicodeEncoding.CodeUnit {
|
func filePathFromInvalidCodePointSequence<S: Sequence>(_ bytes: S) -> FilePath where S.Element == CInterop.PlatformUnicodeEncoding.CodeUnit {
|
||||||
var array = Array(bytes)
|
var array = Array(bytes)
|
||||||
assert(array.last != 0, "already null terminated")
|
assert(array.last != 0, "already null terminated")
|
||||||
@@ -28,7 +28,7 @@ func filePathFromInvalidCodePointSequence<S: Sequence>(_ bytes: S) -> FilePath w
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
final class FilePathTest: XCTestCase {
|
final class FilePathTest: XCTestCase {
|
||||||
struct TestPath {
|
struct TestPath {
|
||||||
let filePath: FilePath
|
let filePath: FilePath
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
This source file is part of the Swift System open source project
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
Copyright (c) 2020 - 2021 Apple Inc. and the Swift System project authors
|
Copyright (c) 2020 - 2025 Apple Inc. and the Swift System project authors
|
||||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
@@ -18,7 +18,7 @@ import System
|
|||||||
import Android
|
import Android
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
final class FileDescriptorTest: XCTestCase {
|
final class FileDescriptorTest: XCTestCase {
|
||||||
func testStandardDescriptors() {
|
func testStandardDescriptors() {
|
||||||
XCTAssertEqual(FileDescriptor.standardInput.rawValue, 0)
|
XCTAssertEqual(FileDescriptor.standardInput.rawValue, 0)
|
||||||
@@ -32,6 +32,7 @@ final class FileDescriptorTest: XCTestCase {
|
|||||||
XCTAssertEqual(O_WRONLY, FileDescriptor.AccessMode.writeOnly.rawValue)
|
XCTAssertEqual(O_WRONLY, FileDescriptor.AccessMode.writeOnly.rawValue)
|
||||||
XCTAssertEqual(O_RDWR, FileDescriptor.AccessMode.readWrite.rawValue)
|
XCTAssertEqual(O_RDWR, FileDescriptor.AccessMode.readWrite.rawValue)
|
||||||
|
|
||||||
|
#if !os(WASI) // Would need to use _getConst funcs from CSystem
|
||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
XCTAssertEqual(O_NONBLOCK, FileDescriptor.OpenOptions.nonBlocking.rawValue)
|
XCTAssertEqual(O_NONBLOCK, FileDescriptor.OpenOptions.nonBlocking.rawValue)
|
||||||
#endif
|
#endif
|
||||||
@@ -39,6 +40,7 @@ final class FileDescriptorTest: XCTestCase {
|
|||||||
XCTAssertEqual(O_CREAT, FileDescriptor.OpenOptions.create.rawValue)
|
XCTAssertEqual(O_CREAT, FileDescriptor.OpenOptions.create.rawValue)
|
||||||
XCTAssertEqual(O_TRUNC, FileDescriptor.OpenOptions.truncate.rawValue)
|
XCTAssertEqual(O_TRUNC, FileDescriptor.OpenOptions.truncate.rawValue)
|
||||||
XCTAssertEqual(O_EXCL, FileDescriptor.OpenOptions.exclusiveCreate.rawValue)
|
XCTAssertEqual(O_EXCL, FileDescriptor.OpenOptions.exclusiveCreate.rawValue)
|
||||||
|
#endif // !os(WASI
|
||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
XCTAssertEqual(O_NOFOLLOW, FileDescriptor.OpenOptions.noFollow.rawValue)
|
XCTAssertEqual(O_NOFOLLOW, FileDescriptor.OpenOptions.noFollow.rawValue)
|
||||||
XCTAssertEqual(O_CLOEXEC, FileDescriptor.OpenOptions.closeOnExec.rawValue)
|
XCTAssertEqual(O_CLOEXEC, FileDescriptor.OpenOptions.closeOnExec.rawValue)
|
||||||
@@ -74,7 +76,7 @@ final class FileDescriptorTest: XCTestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
@available(System 0.0.1, *)
|
||||||
final class FilePermissionsTest: XCTestCase {
|
final class FilePermissionsTest: XCTestCase {
|
||||||
|
|
||||||
func testPermissions() {
|
func testPermissions() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#if compiler(>=6.2)
|
#if compiler(>=6.2) && $Lifetimes
|
||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
|
|
||||||
import XCTest
|
import XCTest
|
||||||
@@ -30,5 +30,5 @@ final class IORequestTests: XCTestCase {
|
|||||||
XCTAssertEqual(sourceBytes, .init(repeating: 0, count: 64))
|
XCTAssertEqual(sourceBytes, .init(repeating: 0, count: 64))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // os(Linux)
|
||||||
#endif
|
#endif // compiler(>=6.2) && $Lifetimes
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#if compiler(>=6.2)
|
#if compiler(>=6.2) && $Lifetimes
|
||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
|
|
||||||
import XCTest
|
import XCTest
|
||||||
@@ -128,5 +128,5 @@ final class IORingTests: XCTestCase {
|
|||||||
rawBuffer.deallocate()
|
rawBuffer.deallocate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // os(Linux)
|
||||||
#endif
|
#endif // compiler(>=6.2) && $Lifetimes
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
This source file is part of the Swift System open source project
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
Copyright (c) 2022 Apple Inc. and the Swift System project authors
|
Copyright (c) 2022 - 2025 Apple Inc. and the Swift System project authors
|
||||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if swift(>=5.9) && SYSTEM_PACKAGE_DARWIN
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
|
|
||||||
import XCTest
|
import XCTest
|
||||||
import Darwin.Mach
|
import Darwin.Mach
|
||||||
@@ -18,7 +18,7 @@ import SystemPackage
|
|||||||
import System
|
import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 1.4.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
|
@available(System 1.4.0, *)
|
||||||
final class MachPortTests: XCTestCase {
|
final class MachPortTests: XCTestCase {
|
||||||
func refCountForMachPortName(name:mach_port_name_t, kind:mach_port_right_t) -> mach_port_urefs_t {
|
func refCountForMachPortName(name:mach_port_name_t, kind:mach_port_right_t) -> mach_port_urefs_t {
|
||||||
var refCount:mach_port_urefs_t = .max
|
var refCount:mach_port_urefs_t = .max
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if ENABLE_MOCKING
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
#if SYSTEM_PACKAGE
|
#if SYSTEM_PACKAGE
|
||||||
@@ -15,7 +16,7 @@ import XCTest
|
|||||||
@testable import System
|
@testable import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
@available(System 0.0.2, *)
|
||||||
final class MockingTest: XCTestCase {
|
final class MockingTest: XCTestCase {
|
||||||
func testMocking() {
|
func testMocking() {
|
||||||
XCTAssertFalse(mockingEnabled)
|
XCTAssertFalse(mockingEnabled)
|
||||||
@@ -48,3 +49,4 @@ final class MockingTest: XCTestCase {
|
|||||||
XCTAssertFalse(mockingEnabled)
|
XCTAssertFalse(mockingEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MOCKING
|
||||||
@@ -17,6 +17,7 @@ import XCTest
|
|||||||
|
|
||||||
internal struct Wildcard: Hashable {}
|
internal struct Wildcard: Hashable {}
|
||||||
|
|
||||||
|
#if ENABLE_MOCKING
|
||||||
extension Trace.Entry {
|
extension Trace.Entry {
|
||||||
/// This implements `==` with wildcard matching.
|
/// This implements `==` with wildcard matching.
|
||||||
/// (`Entry` cannot conform to `Equatable`/`Hashable` this way because
|
/// (`Entry` cannot conform to `Equatable`/`Hashable` this way because
|
||||||
@@ -33,6 +34,7 @@ extension Trace.Entry {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MOCKING
|
||||||
|
|
||||||
// To aid debugging, force failures to fatal error
|
// To aid debugging, force failures to fatal error
|
||||||
internal var forceFatalFailures = false
|
internal var forceFatalFailures = false
|
||||||
@@ -81,6 +83,7 @@ extension TestCase {
|
|||||||
fail(message)
|
fail(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if ENABLE_MOCKING
|
||||||
func expectMatch(
|
func expectMatch(
|
||||||
_ expected: Trace.Entry?, _ actual: Trace.Entry?,
|
_ expected: Trace.Entry?, _ actual: Trace.Entry?,
|
||||||
_ message: String? = nil
|
_ message: String? = nil
|
||||||
@@ -102,6 +105,7 @@ extension TestCase {
|
|||||||
fail(message)
|
fail(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MOCKING
|
||||||
func expectNil<T>(
|
func expectNil<T>(
|
||||||
_ actual: T?,
|
_ actual: T?,
|
||||||
_ message: String? = nil
|
_ message: String? = nil
|
||||||
@@ -142,6 +146,7 @@ extension TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MOCKING
|
||||||
internal struct MockTestCase: TestCase {
|
internal struct MockTestCase: TestCase {
|
||||||
var file: StaticString
|
var file: StaticString
|
||||||
var line: UInt
|
var line: UInt
|
||||||
@@ -241,6 +246,7 @@ internal struct MockTestCase: TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MOCKING
|
||||||
|
|
||||||
internal func withWindowsPaths(enabled: Bool, _ body: () -> ()) {
|
internal func withWindowsPaths(enabled: Bool, _ body: () -> ()) {
|
||||||
_withWindowsPaths(enabled: enabled, body)
|
_withWindowsPaths(enabled: enabled, body)
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
# This script can be used to automatically add/remove `@available` attributes to
|
|
||||||
# declarations in Swift sources in this package.
|
|
||||||
#
|
|
||||||
# In order for this to work, ABI-impacting declarations need to be annotated
|
|
||||||
# with special comments in the following format:
|
|
||||||
#
|
|
||||||
# @available(/*System 0.0.2*/iOS 8, *)
|
|
||||||
# public func greeting() -> String {
|
|
||||||
# "Hello"
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# (The iOS 8 availability is a dummy no-op declaration -- it only has to be
|
|
||||||
# there because `@available(*)` isn't valid syntax, and commenting out the
|
|
||||||
# entire `@available` attribute would interfere with parser tools for doc
|
|
||||||
# comments. `iOS 8` is the shortest version string that matches the minimum
|
|
||||||
# possible deployment target for Swift code, so we use that as our dummy
|
|
||||||
# availability version. `@available(iOS 8, *)` is functionally equivalent to not
|
|
||||||
# having an `@available` attribute at all.)
|
|
||||||
#
|
|
||||||
# The script adds full availability incantations to these comments. It can run
|
|
||||||
# in one of two modes:
|
|
||||||
#
|
|
||||||
# By default, `expand-availability.py` expands availability macros within the
|
|
||||||
# comments. This is useful during package development to cross-reference
|
|
||||||
# availability across `SystemPackage` and the ABI-stable `System` module that
|
|
||||||
# ships in Apple's OS releases:
|
|
||||||
#
|
|
||||||
# @available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
|
||||||
# public func greeting() -> String {
|
|
||||||
# "Hello"
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# `expand-availability.py --attributes` adds actual availability declarations.
|
|
||||||
# This is used by maintainers to build ABI stable releases of System on Apple's
|
|
||||||
# platforms:
|
|
||||||
#
|
|
||||||
# @available(/*System 0.0.2: */macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
|
||||||
# public func greeting() -> String {
|
|
||||||
# "Hello"
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# The script recognizes all three forms of these annotations and updates them on
|
|
||||||
# every run, so we can run the script to enable/disable attributes as needed.
|
|
||||||
|
|
||||||
import os
|
|
||||||
import os.path
|
|
||||||
import fileinput
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
versions = {
|
|
||||||
"System 0.0.1": "macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0",
|
|
||||||
"System 0.0.2": "macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0",
|
|
||||||
"System 1.1.0": "macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4",
|
|
||||||
"System 1.2.0": "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999",
|
|
||||||
"System 1.3.0": "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999",
|
|
||||||
"System 1.4.0": "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999",
|
|
||||||
}
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Expand availability macros.")
|
|
||||||
parser.add_argument("--attributes", help="Add @available attributes",
|
|
||||||
action="store_true")
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
def swift_sources_in(path):
|
|
||||||
result = []
|
|
||||||
for (dir, _, files) in os.walk(path):
|
|
||||||
for file in files:
|
|
||||||
extension = os.path.splitext(file)[1]
|
|
||||||
if extension == ".swift":
|
|
||||||
result.append(os.path.join(dir, file))
|
|
||||||
return result
|
|
||||||
|
|
||||||
# Old-style syntax:
|
|
||||||
# /*System 0.0.2*/
|
|
||||||
# /*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
|
||||||
# /*System 0.0.2*/@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
|
||||||
old_macro_pattern = re.compile(
|
|
||||||
r"/\*(System [^ *]+)(, @available\([^)]*\))?\*/(@available\([^)]*\))?")
|
|
||||||
|
|
||||||
# New-style comments:
|
|
||||||
# @available(/*SwiftSystem 0.0.2*/macOS 10, *)
|
|
||||||
# @available(/*SwiftSystem 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
|
|
||||||
# @available(/*SwiftSystem 0.0.2*/macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
|
||||||
#
|
|
||||||
# These do not interfere with our tools' ability to find doc comments.
|
|
||||||
macro_pattern = re.compile(
|
|
||||||
r"@available\(/\*(System [^ *:]+)[^*/)]*\*/([^)]*)\*\)")
|
|
||||||
|
|
||||||
def available_attribute(filename, lineno, symbolic_version):
|
|
||||||
expansion = versions[symbolic_version]
|
|
||||||
if expansion is None:
|
|
||||||
raise ValueError("{0}:{1}: error: Unknown System version '{0}'"
|
|
||||||
.format(fileinput.filename(), fileinput.lineno(), symbolic_version))
|
|
||||||
if args.attributes:
|
|
||||||
attribute = "@available(/*{0}*/{1}, *)".format(symbolic_version, expansion)
|
|
||||||
else:
|
|
||||||
# Sadly `@available(*)` is not valid syntax, so we have to mention at
|
|
||||||
# least one actual platform here.
|
|
||||||
attribute = "@available(/*{0}: {1}*/iOS 8, *)".format(symbolic_version, expansion)
|
|
||||||
return attribute
|
|
||||||
|
|
||||||
|
|
||||||
sources = swift_sources_in("Sources") + swift_sources_in("Tests")
|
|
||||||
for line in fileinput.input(files=sources, inplace=True):
|
|
||||||
match = re.search(macro_pattern, line)
|
|
||||||
if match is None:
|
|
||||||
match = re.search(old_macro_pattern, line)
|
|
||||||
if match:
|
|
||||||
symbolic_version = match.group(1)
|
|
||||||
replacement = available_attribute(
|
|
||||||
fileinput.filename(), fileinput.lineno(), symbolic_version)
|
|
||||||
line = line[:match.start()] + replacement + line[match.end():]
|
|
||||||
print(line, end="")
|
|
||||||
Reference in new issue
Block a user