Skip to content

Commit 0afc1f4

Browse files
committed
Modernize code to not rely on deprecations and old behavior
1 parent 5a80967 commit 0afc1f4

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

CoreFoundation/Base.subproj/CFPlatform.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ static _CFThreadSpecificKey __CFTSDIndexKey;
733733
static void *__CFThreadSpecificData;
734734
#endif
735735

736-
CF_PRIVATE void __CFTSDInitialize() {
736+
CF_PRIVATE void __CFTSDInitialize(void) {
737737
#if !TARGET_OS_WASI
738738
static dispatch_once_t once;
739739
dispatch_once(&once, ^{

CoreFoundation/Base.subproj/CFUtilities.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ CF_EXPORT Boolean _CFExtensionIsValidToAppend(CFStringRef extension) {
16641664

16651665
#if DEPLOYMENT_RUNTIME_SWIFT && !TARGET_OS_WASI
16661666

1667-
CFDictionaryRef __CFGetEnvironment() {
1667+
CFDictionaryRef __CFGetEnvironment(void) {
16681668
static dispatch_once_t once = 0L;
16691669
static CFMutableDictionaryRef envDict = NULL;
16701670
dispatch_once(&once, ^{
@@ -1719,7 +1719,7 @@ CFDictionaryRef __CFGetEnvironment() {
17191719
return envDict;
17201720
}
17211721

1722-
int32_t __CFGetPid() {
1722+
int32_t __CFGetPid(void) {
17231723
return getpid();
17241724
}
17251725

CoreFoundation/RunLoop.subproj/CFRunLoop.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ static CFStringRef __CFRunLoopCopyDescription(CFTypeRef cf) {
806806
return result;
807807
}
808808

809-
CF_PRIVATE void __CFRunLoopDump() { // __private_extern__ to keep the compiler from discarding it
809+
CF_PRIVATE void __CFRunLoopDump(void) { // __private_extern__ to keep the compiler from discarding it
810810
CFStringRef desc = CFCopyDescription(CFRunLoopGetCurrent());
811811
CFShow(desc);
812812
CFRelease(desc);

Darwin/Foundation-swiftoverlay/DataThunks.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static NSInteger _NSWriteToFileDescriptor(int32_t fd, const void *buffer, NSUInt
7575

7676
static NSError *_NSErrorWithFilePath(NSInteger code, id pathOrURL) {
7777
NSString *key = [pathOrURL isKindOfClass:[NSURL self]] ? NSURLErrorKey : NSFilePathErrorKey;
78-
return [NSError errorWithDomain:NSCocoaErrorDomain code:code userInfo:[NSDictionary dictionaryWithObjectsAndKeys:pathOrURL, key, nil]];
78+
return [NSError errorWithDomain:NSCocoaErrorDomain code:code userInfo:@{pathOrURL: key}];
7979
}
8080

8181
static NSError *_NSErrorWithFilePathAndErrno(NSInteger posixErrno, id pathOrURL, BOOL reading) {
@@ -106,7 +106,7 @@ static NSInteger _NSWriteToFileDescriptor(int32_t fd, const void *buffer, NSUInt
106106
}
107107

108108
NSString *key = [pathOrURL isKindOfClass:[NSURL self]] ? NSURLErrorKey : NSFilePathErrorKey;
109-
NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:pathOrURL, key, [NSError errorWithDomain:NSPOSIXErrorDomain code:posixErrno userInfo:nil], NSUnderlyingErrorKey, nil];
109+
NSDictionary *userInfo = @{pathOrURL : key, [NSError errorWithDomain:NSPOSIXErrorDomain code:posixErrno userInfo:nil] : NSUnderlyingErrorKey};
110110
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:code userInfo:userInfo];
111111
[userInfo release];
112112
return error;

Sources/Foundation/Process.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ open class Process: NSObject {
11441144
// convenience; create and launch
11451145
open class func launchedProcess(launchPath path: String, arguments: [String]) -> Process {
11461146
let process = Process()
1147-
process.launchPath = path
1147+
process.executableURL = URL(fileURLWithPath:path)
11481148
process.arguments = arguments
11491149
process.launch()
11501150

Tests/Foundation/Tests/TestProcess.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestProcess : XCTestCase {
1818
// Fallback on earlier versions
1919
process.launchPath = executableURL.path
2020
}
21-
XCTAssertEqual(executableURL.path, process.launchPath)
21+
XCTAssertEqual(process.launchPath, executableURL.path)
2222
process.arguments = ["--exit", "0"]
2323
try process.run()
2424
process.waitUntilExit()
@@ -971,7 +971,12 @@ internal func runTask(_ arguments: [String], environment: [String: String]? = ni
971971
let process = Process()
972972

973973
var arguments = arguments
974-
process.launchPath = arguments.removeFirst()
974+
if #available(OSX 10.13, *) {
975+
process.executableURL = URL(fileURLWithPath:arguments.removeFirst())
976+
} else {
977+
// Fallback on earlier versions
978+
process.launchPath = arguments.removeFirst()
979+
}
975980
process.arguments = arguments
976981
// Darwin Foundation doesnt allow .environment to be set to nil although the documentation
977982
// says it is an optional. https://developer.apple.com/documentation/foundation/process/1409412-environment

0 commit comments

Comments
 (0)