Skip to content

Commit 8712d83

Browse files
committed
Various fixes to allow for building on Windows
1 parent 27ae565 commit 8712d83

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

Sources/CoreFoundation/include/CFRunLoop.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "CFString.h"
1717
#if TARGET_OS_OSX || TARGET_OS_IPHONE
1818
#include <mach/port.h>
19+
#elif TARGET_OS_WIN32
20+
#include <Windows.h>
1921
#endif
2022

2123
CF_IMPLICIT_BRIDGING_ENABLED

Sources/CoreFoundation/include/ForSwiftFoundationOnly.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,11 @@ static inline bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((no
517517
buffer.capacity = amount;
518518
#endif
519519
buffer.onStack = (_CFIsMainThread() != 0 ? buffer.capacity < 2048 : buffer.capacity < 512);
520+
#if TARGET_OS_WIN32
521+
buffer.memory = buffer.onStack ? _alloca(buffer.capacity) : malloc(buffer.capacity);
522+
#else
520523
buffer.memory = buffer.onStack ? alloca(buffer.capacity) : malloc(buffer.capacity);
524+
#endif
521525
if (buffer.memory == NULL) { return false; }
522526
applier(&buffer);
523527
if (!buffer.onStack) {
@@ -540,6 +544,7 @@ CF_CROSS_PLATFORM_EXPORT CFIndex __CFCharDigitValue(UniChar ch);
540544
#pragma mark - File Functions
541545

542546
#if TARGET_OS_WIN32
547+
typedef int mode_t;
543548
CF_CROSS_PLATFORM_EXPORT int _CFOpenFileWithMode(const unsigned short *path, int opts, mode_t mode);
544549
#else
545550
CF_CROSS_PLATFORM_EXPORT int _CFOpenFileWithMode(const char *path, int opts, mode_t mode);

Sources/CoreFoundation/include/module.modulemap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module CoreFoundation {
22
umbrella header "CoreFoundation.h"
3-
explicit module CFPlugInCOM { header "CFPlugInCOM.h" }
43

54
export *
65
module * {

Sources/Foundation/FileManager+Win32.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ extension FileManager {
162162

163163
internal func _recursiveDestinationOfSymbolicLink(atPath path: String) throws -> String {
164164
// Throw error if path is not a symbolic link:
165-
var previousIterationDestination = try _destinationOfSymbolicLink(atPath: path)
165+
var previousIterationDestination = try destinationOfSymbolicLink(atPath: path)
166166

167167
// Same recursion limit as in Darwin:
168168
let symbolicLinkRecursionLimit = 32

Sources/Foundation/FileManager.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,10 @@ extension FileManager {
283283
let hiddenAttrs = isHidden
284284
? attrs | FILE_ATTRIBUTE_HIDDEN
285285
: attrs & ~FILE_ATTRIBUTE_HIDDEN
286-
guard SetFileAttributesW(fsRep, hiddenAttrs) else {
287-
throw _NSErrorWithWindowsError(GetLastError(), reading: false, paths: [path])
286+
try _fileSystemRepresentation(withPath: path) { fsRep in
287+
guard SetFileAttributesW(fsRep, hiddenAttrs) else {
288+
throw _NSErrorWithWindowsError(GetLastError(), reading: false, paths: [path])
289+
}
288290
}
289291
#else
290292
if isHidden {
@@ -308,7 +310,7 @@ extension FileManager {
308310
// Setting these attributes is unsupported on these platforms.
309311
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.fileWriteUnknown.rawValue)
310312
#else
311-
let stat = try _lstatFile(atPath: path, withFileSystemRepresentation: fsRep)
313+
let stat = try _lstatFile(atPath: path, withFileSystemRepresentation: nil)
312314
var flags = stat.st_flags
313315
flags |= flagsToSet
314316
flags &= ~flagsToUnset

Sources/Foundation/NSUUID.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding {
9090

9191
open override func isEqual(_ value: Any?) -> Bool {
9292
switch value {
93-
case let other as UUID:
93+
case let other as FoundationEssentials.UUID:
9494
return other.uuid.0 == buffer[0] &&
9595
other.uuid.1 == buffer[1] &&
9696
other.uuid.2 == buffer[2] &&
@@ -124,9 +124,9 @@ open class NSUUID : NSObject, NSCopying, NSSecureCoding, NSCoding {
124124
}
125125

126126
extension NSUUID : _StructTypeBridgeable {
127-
public typealias _StructType = UUID
127+
public typealias _StructType = FoundationEssentials.UUID
128128

129-
public func _bridgeToSwift() -> UUID {
130-
return UUID._unconditionallyBridgeFromObjectiveC(self)
129+
public func _bridgeToSwift() -> FoundationEssentials.UUID {
130+
return FoundationEssentials.UUID._unconditionallyBridgeFromObjectiveC(self)
131131
}
132132
}

0 commit comments

Comments
 (0)