Created
September 16, 2017 19:58
-
-
Save spevans/8eeda038a9c44c9a337aaa2833627c3b to your computer and use it in GitHub Desktop.
Changes to Foundation to compile sclf on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Foundation/JSONSerialization.swift b/Foundation/JSONSerialization.swift | |
index c624e7a7..3eda7b4d 100644 | |
--- a/Foundation/JSONSerialization.swift | |
+++ b/Foundation/JSONSerialization.swift | |
@@ -15,6 +15,8 @@ import CoreFoundation | |
import Glibc | |
#endif | |
+public typealias NSErrorPointer = AutoreleasingUnsafeMutablePointer<NSError?>? | |
+ | |
extension JSONSerialization { | |
public struct ReadingOptions : OptionSet { | |
public let rawValue : UInt | |
@@ -208,10 +210,21 @@ open class JSONSerialization : NSObject { | |
return jsonData.withUnsafeBytes { (bytePtr: UnsafePointer<UInt8>) -> Int in | |
let res: Int = stream.write(bytePtr, maxLength: count) | |
/// TODO: If the result here is negative the error should be obtained from the stream to propigate as a throw | |
+ if res < 0 { | |
+ | |
+ } | |
return res | |
} | |
} | |
- | |
+ | |
+ open class func writeJSONObject(_ obj: Any, to stream: OutputStream, options opt: WritingOptions = [], error: NSErrorPointer) -> Int { | |
+ do { | |
+ return try writeJSONObject(obj, toStream: stream, options: opt) | |
+ } catch { | |
+ return 0 | |
+ } | |
+ } | |
+ | |
/* Create a JSON object from JSON data stream. The stream should be opened and configured. All other behavior of this method is the same as the JSONObjectWithData:options:error: method. | |
*/ | |
open class func jsonObject(with stream: InputStream, options opt: ReadingOptions = []) throws -> Any { | |
diff --git a/Foundation/NSArray.swift b/Foundation/NSArray.swift | |
index 5b5d40ff..3bad6341 100644 | |
--- a/Foundation/NSArray.swift | |
+++ b/Foundation/NSArray.swift | |
@@ -853,8 +853,8 @@ open class NSMutableArray : NSArray { | |
self.setArray(self.sortedArray(compare, context: context)) | |
} | |
- open func sort(_ cmptr: Comparator) { | |
- self.sort(options: [], usingComparator: cmptr) | |
+ open func sort(comparator: Comparator) { | |
+ self.sort(options: [], usingComparator: comparator) | |
} | |
open func sort(options opts: NSSortOptions, usingComparator cmptr: Comparator) { | |
diff --git a/Foundation/NSKeyedUnarchiver.swift b/Foundation/NSKeyedUnarchiver.swift | |
index b977cc86..d75a6641 100644 | |
--- a/Foundation/NSKeyedUnarchiver.swift | |
+++ b/Foundation/NSKeyedUnarchiver.swift | |
@@ -86,7 +86,7 @@ open class NSKeyedUnarchiver : NSCoder { | |
return root | |
} | |
- public convenience init(forReadingWithData data: Data) { | |
+ public convenience init(forReadingWith data: Data) { | |
self.init(stream: Stream.data(data)) | |
} | |
@@ -863,7 +863,7 @@ open class NSKeyedUnarchiver : NSCoder { | |
} | |
open class func unarchiveTopLevelObjectWithData(_ data: Data) throws -> Any? { | |
- let keyedUnarchiver = NSKeyedUnarchiver(forReadingWithData: data) | |
+ let keyedUnarchiver = NSKeyedUnarchiver(forReadingWith: data) | |
let root = try keyedUnarchiver.decodeTopLevelObject(forKey: NSKeyedArchiveRootObjectKey) | |
keyedUnarchiver.finishDecoding() | |
return root | |
diff --git a/Foundation/NSString.swift b/Foundation/NSString.swift | |
index 54fe91fc..26c45b5d 100644 | |
--- a/Foundation/NSString.swift | |
+++ b/Foundation/NSString.swift | |
@@ -1221,18 +1221,6 @@ extension NSString { | |
free(bytes) | |
} | |
} | |
- | |
- public convenience init?(CString nullTerminatedCString: UnsafePointer<Int8>, encoding: UInt) { | |
- guard let cf = CFStringCreateWithCString(kCFAllocatorSystemDefault, nullTerminatedCString, CFStringConvertNSStringEncodingToEncoding(encoding)) else { | |
- return nil | |
- } | |
- var str: String? | |
- if String._conditionallyBridgeFromObjectiveC(cf._nsObject, result: &str) { | |
- self.init(str!) | |
- } else { | |
- return nil | |
- } | |
- } | |
public convenience init(contentsOf url: URL, encoding enc: UInt) throws { | |
let readResult = try NSData(contentsOf: url, options: []) | |
diff --git a/Foundation/NSSwiftRuntime.swift b/Foundation/NSSwiftRuntime.swift | |
index 58a71740..5fd08945 100644 | |
--- a/Foundation/NSSwiftRuntime.swift | |
+++ b/Foundation/NSSwiftRuntime.swift | |
@@ -25,6 +25,9 @@ import CoreFoundation | |
#endif | |
public typealias ObjCBool = Bool | |
+extension ObjCBool { | |
+ public var boolValue: Bool { return self == true } | |
+} | |
internal class __NSCFType : NSObject { | |
private var _cfinfo : Int32 | |
diff --git a/Foundation/NSTextCheckingResult.swift b/Foundation/NSTextCheckingResult.swift | |
index caed9a8e..74dd8c0a 100644 | |
--- a/Foundation/NSTextCheckingResult.swift | |
+++ b/Foundation/NSTextCheckingResult.swift | |
@@ -87,7 +87,7 @@ internal class _NSRegularExpressionNSTextCheckingResultResult : NSTextCheckingRe | |
extension NSTextCheckingResult { | |
- public func resultByAdjustingRangesWithOffset(_ offset: Int) -> NSTextCheckingResult { | |
+ public func adjustingRanges(offset: Int) -> NSTextCheckingResult { | |
let count = self.numberOfRanges | |
var newRanges = [NSRange]() | |
for idx in 0..<count { | |
diff --git a/Foundation/Thread.swift b/Foundation/Thread.swift | |
index 402294da..72f05a0d 100644 | |
--- a/Foundation/Thread.swift | |
+++ b/Foundation/Thread.swift | |
@@ -201,9 +201,27 @@ open class Thread : NSObject { | |
} | |
open var name: String? { | |
- didSet { | |
- if _thread == Thread.current._thread { | |
- _CFThreadSetName(name) | |
+ get { | |
+ guard let thread = _thread else { | |
+ return nil | |
+ } | |
+ var buf = [Int8](repeating: 0, count: 16) | |
+ let r = pthread_getname_np(thread, &buf, buf.count) | |
+ guard r == 0 else { | |
+ return nil | |
+ } | |
+ return String(cString: buf) | |
+ } | |
+ set { | |
+ let name = (newValue == nil) ? "" : newValue! | |
+ name.withCString { namePtr in | |
+#if os(Linux) | |
+ if let thread = _thread { | |
+ pthread_setname_np(thread, namePtr) | |
+ } | |
+#elseif os(OSX) || os(iOS) | |
+ pthread_setname_np(namePtr) | |
+#endif | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment