Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Fix compiler warnings in sources and test targets

Jacky34bec3cc5175
diff --git a/VPhoneDaemon/Daemon/GuestVirtualAudioProduct.swift b/VPhoneDaemon/Daemon/GuestVirtualAudioProduct.swift
index e7744283..b9f7b53a 100644
--- a/VPhoneDaemon/Daemon/GuestVirtualAudioProduct.swift
+++ b/VPhoneDaemon/Daemon/GuestVirtualAudioProduct.swift
@@ -67,6 +67,6 @@ enum GuestVirtualAudioProduct {
guard sysctlbyname("hw.machine", nil, &size, nil, 0) == 0, size > 0 else { return "" }
var bytes = [CChar](repeating: 0, count: size + 1)
guard sysctlbyname("hw.machine", &bytes, &size, nil, 0) == 0 else { return "" }
- return String(cString: bytes)
+ return String(decoding: bytes.prefix { $0 != 0 }.map { UInt8(bitPattern: $0) }, as: UTF8.self)
}
}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/VerboseCustomFirmwareDebug.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/VerboseCustomFirmwareDebug.swift
index 7166a54c..58aef99e 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/VerboseCustomFirmwareDebug.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/VerboseCustomFirmwareDebug.swift
@@ -15,7 +15,7 @@ struct VerboseCustomFirmwareDebug {
let patcher = KernelCustomFirmwarePatcher(data: data, verbose: true)
// Initialize patcher state (same as findAll() but without running patches)
- try patcher.parseMachO()
+ patcher.parseMachO()
patcher.buildADRPIndex()
patcher.buildBLIndex()
patcher.buildSymbolTable()
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareSeputilTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareSeputilTests.swift
index 8d383dd1..75e23262 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareSeputilTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareSeputilTests.swift
@@ -481,9 +481,9 @@ struct CustomFirmwareSeputilShapeTests {
return data
}
- @Test func `reads the field after the last separator`() {
+ @Test func `reads the field after the last separator`() throws {
// The mountpoint field is left alone; the one after the last "/" moves.
- let field = try? #require(CustomFirmwareSeputil.fileField(of: Array("%s/%s.gl".utf8)))
+ let field = try #require(CustomFirmwareSeputil.fileField(of: Array("%s/%s.gl".utf8)))
#expect(field == 3 ..< 5)
#expect(CustomFirmwareSeputil.fileField(of: Array("/mnt7/%s.gl".utf8)) == 6 ..< 8)
// No separator, wrong suffix, or a field that is not two bytes wide:
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/DyldSharedCache/DyldSharedCacheMISTrustAuthPatcherTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/DyldSharedCache/DyldSharedCacheMISTrustAuthPatcherTests.swift
index 01b5f613..d63852f5 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/DyldSharedCache/DyldSharedCacheMISTrustAuthPatcherTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/DyldSharedCache/DyldSharedCacheMISTrustAuthPatcherTests.swift
@@ -615,11 +615,11 @@ struct DyldSharedCacheMISTrustAuthShapeDetectorTests {
@Suite(.serialized)
struct DyldSharedCacheMISTrustAuthDerivedSeedTests {
@Test
- func `A derived 32-bit add word disassembles as a w-register add`() {
+ func `A derived 32-bit add word disassembles as a w-register add`() throws {
let decoded = ARM64Disassembler().disassemble(MISFixture.derivation, at: 0)
- let instruction = try? #require(decoded.first)
- #expect(instruction?.mnemonic == "add")
- let operands = instruction?.detail?.operands
+ let instruction = try #require(decoded.first)
+ #expect(instruction.mnemonic == "add")
+ let operands = instruction.detail?.operands
#expect(operands?.count == 3)
#expect(operands?[0].reg.name == "w26")
#expect(operands?[1].reg.name == "w23")
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand.xcodeproj/project.pbxproj b/VPhoneExecutable/VPhoneCommand/VPhoneCommand.xcodeproj/project.pbxproj
index a1c089ee..905bea19 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand.xcodeproj/project.pbxproj
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand.xcodeproj/project.pbxproj
@@ -767,10 +767,6 @@
ARCHS = arm64;
CODE_SIGNING_ALLOWED = NO;
GENERATE_INFOPLIST_FILE = YES;
- LIBRARY_SEARCH_PATHS = (
- "$(inherited)",
- "$(PROJECT_DIR)/VPhoneSignTests/Fixtures",
- );
MACOSX_DEPLOYMENT_TARGET = 15.0;
PRODUCT_BUNDLE_IDENTIFIER = com.vphone.sign.tests;
PRODUCT_NAME = VPhoneSignTests;
@@ -785,10 +781,6 @@
ARCHS = arm64;
CODE_SIGNING_ALLOWED = NO;
GENERATE_INFOPLIST_FILE = YES;
- LIBRARY_SEARCH_PATHS = (
- "$(inherited)",
- "$(PROJECT_DIR)/VPhoneSignTests/Fixtures",
- );
MACOSX_DEPLOYMENT_TARGET = 15.0;
PRODUCT_BUNDLE_IDENTIFIER = com.vphone.sign.tests;
PRODUCT_NAME = VPhoneSignTests;
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestoreTests/RestoreRunnerTests.swift b/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestoreTests/RestoreRunnerTests.swift
index 1afd4121..279f67ce 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestoreTests/RestoreRunnerTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestoreTests/RestoreRunnerTests.swift
@@ -56,6 +56,7 @@ struct RestoreRunnerTests {
}
}
+ @discardableResult
private func withTemporaryDirectory<R>(_ body: (URL) throws -> R) throws -> R {
let root = FileManager.default.temporaryDirectory
.appendingPathComponent("vphone-runner-\(UUID().uuidString)", isDirectory: true)
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneHostHotKeys.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneHostHotKeys.swift
index 5772e355..4609cc17 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneHostHotKeys.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneHostHotKeys.swift
@@ -39,7 +39,7 @@ final class VPhoneHostHotKeys {
let setEnabled: SetEnabled
}
- private nonisolated(unsafe) static let skyLight: SkyLight? = {
+ private nonisolated static let skyLight: SkyLight? = {
guard let handle = dlopen("/System/Library/PrivateFrameworks/SkyLight.framework/SkyLight", RTLD_NOW),
let get = dlsym(handle, "CGSGetSymbolicHotKeyValue"),
let isEnabled = dlsym(handle, "CGSIsSymbolicHotKeyEnabled"),
diff --git a/VPhoneKit/VPhoneCoreKit/Network/VPhoneDHCPLeases.swift b/VPhoneKit/VPhoneCoreKit/Network/VPhoneDHCPLeases.swift
index 5d8a8180..7060720b 100644
--- a/VPhoneKit/VPhoneCoreKit/Network/VPhoneDHCPLeases.swift
+++ b/VPhoneKit/VPhoneCoreKit/Network/VPhoneDHCPLeases.swift
@@ -290,7 +290,7 @@ public enum VPhoneDHCPLeaseRelease {
guard pid > 0 else { return false }
var buffer = [CChar](repeating: 0, count: 256)
guard proc_name(pid, &buffer, UInt32(buffer.count)) > 0 else { return false }
- return String(cString: buffer) == name
+ return String(decoding: buffer.prefix { $0 != 0 }.map { UInt8(bitPattern: $0) }, as: UTF8.self) == name
}
}
diff --git a/VPhoneKit/VPhoneCoreKitTests/Network/VPhoneInternetProtocolTests.swift b/VPhoneKit/VPhoneCoreKitTests/Network/VPhoneInternetProtocolTests.swift
index 141bb3ce..e4b25813 100644
--- a/VPhoneKit/VPhoneCoreKitTests/Network/VPhoneInternetProtocolTests.swift
+++ b/VPhoneKit/VPhoneCoreKitTests/Network/VPhoneInternetProtocolTests.swift
@@ -15,7 +15,7 @@ struct VPhoneInternetProtocolTests {
/// plus the headers came to 1308. Sending it whole got it dropped, silently,
/// once per datagram. UDP has no layer above it to chop anything up, so the
/// splitting has to happen here.
- @Test func `an oversized packet is fragmented rather than dropped`() {
+ @Test func `an oversized packet is fragmented rather than dropped`() throws {
let payload = [UInt8](repeating: 0x5A, count: 3000)
let packet = VPhoneIPv4Packet(
source: VPhoneIPv4Address(192, 168, 127, 1),
@@ -29,8 +29,8 @@ struct VPhoneInternetProtocolTests {
for fragment in fragments {
#expect(fragment.count <= 1500, "a fragment is \(fragment.count)B, over the MTU")
- let parsed = try? #require(VPhoneIPv4Packet(bytes: fragment))
- #expect(parsed?.isFragment == true)
+ let parsed = try #require(VPhoneIPv4Packet(bytes: fragment))
+ #expect(parsed.isFragment)
}
// Every fragment but the last says more are coming, and the offsets walk
@@ -102,7 +102,7 @@ struct VPhoneInternetProtocolTests {
/// Window scaling has to survive the option encoding, and the option list has
/// to pad to a 32-bit boundary or the data offset is wrong.
- @Test func `TCP options round trip and pad to a word boundary`() {
+ @Test func `TCP options round trip and pad to a word boundary`() throws {
let segment = VPhoneTCPSegment(
sourcePort: 1,
destinationPort: 2,
@@ -116,8 +116,8 @@ struct VPhoneInternetProtocolTests {
let bytes = segment.bytes(source: .any, destination: .any)
#expect(bytes[12] >> 4 == 7, "the header should be 28 bytes, i.e. 7 words")
- let parsed = try? #require(VPhoneTCPSegment(bytes: bytes))
- #expect(parsed?.maximumSegmentSize == 1460)
- #expect(parsed?.windowScale == 7)
+ let parsed = try #require(VPhoneTCPSegment(bytes: bytes))
+ #expect(parsed.maximumSegmentSize == 1460)
+ #expect(parsed.windowScale == 7)
}
}
diff --git a/VPhoneKit/VPhoneCoreKitTests/Network/VPhoneTCPForwarderTests.swift b/VPhoneKit/VPhoneCoreKitTests/Network/VPhoneTCPForwarderTests.swift
index 055579af..7427848b 100644
--- a/VPhoneKit/VPhoneCoreKitTests/Network/VPhoneTCPForwarderTests.swift
+++ b/VPhoneKit/VPhoneCoreKitTests/Network/VPhoneTCPForwarderTests.swift
@@ -306,7 +306,7 @@ struct VPhoneTCPForwarderTests {
}
sent += written
}
- _ = server.drain(client)
+ server.drain(client)
}
defer { server.stop() }
@@ -451,7 +451,7 @@ struct VPhoneTCPForwarderTests {
}
sent += written
}
- _ = server.drain(client)
+ server.drain(client)
}
defer { server.stop() }
@@ -495,7 +495,7 @@ struct VPhoneTCPForwarderTests {
var buffer = [UInt8](repeating: 0, count: 4096)
_ = recv(client, &buffer, buffer.count, 0)
_ = payload.withUnsafeBytes { send(client, $0.baseAddress, $0.count, 0) }
- _ = server.drain(client)
+ server.drain(client)
}
defer { server.stop() }
@@ -537,7 +537,7 @@ struct VPhoneTCPForwarderTests {
}
sent += written
}
- _ = server.drain(client, until: total)
+ server.drain(client, until: total)
}
defer { server.stop() }