Skip to content

Commit

Permalink
Merge branch 'release/2.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Sep 24, 2016
2 parents ec60a28 + 2a5af94 commit 371ec55
Show file tree
Hide file tree
Showing 35 changed files with 455 additions and 258 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ SwiftFoundation/build
Xcode/SwiftFoundation.xcodeproj/xcuserdata

Xcode/SwiftFoundation.xcodeproj/project.xcworkspace/xcuserdata

.DS_Store
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: generic
osx_image: xcode8
os:
- linux
- osx
sudo: required
dist: trusty
before_install:
Expand All @@ -13,9 +12,9 @@ install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install clang uuid-dev libjson-c-dev ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/swift-3.0-preview-1/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/development/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi
env:
- SWIFT_VERSION=swift-3.0-PREVIEW-1
- SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a
script:
- uname
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -project Xcode/SwiftFoundation.xcodeproj -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi
Expand Down
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "PureSwift/JSON-C" "098c5ad91d262de5ad695a6162b6d0d4b384741d"
github "PureSwift/JSON-C" "0b49467d3f881523c9a74994f6e460a757bdb84f"
7 changes: 0 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import PackageDescription

let package = Package(
name: "SwiftFoundation",
targets: [
Target(
name: "UnitTests",
dependencies: [.Target(name: "SwiftFoundation")]),
Target(
name: "SwiftFoundation")
],
dependencies: [
.Package(url: "https://github.com/PureSwift/CStatfs.git", majorVersion: 1),
.Package(url: "https://github.com/PureSwift/CJSONC.git", majorVersion: 1)
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftFoundation/Base64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/* Create an NSData from a Base-64 encoded NSString using the given options. By default, returns nil when the input is not recognized as valid Base-64.
*/
public init?(base64Encoded base64String: String, options: Base64DecodingOptions) {
public init?(base64Encoded base64String: String, options: Base64DecodingOptions = []) {
let encodedBytes = Array(base64String.utf8)
guard let decodedBytes = Data.base64DecodeBytes(encodedBytes, options: options) else {
return nil
Expand All @@ -47,7 +47,7 @@

/* Create an NSData from a Base-64, UTF-8 encoded NSData. By default, returns nil when the input is not recognized as valid Base-64.
*/
public init?(base64Encoded base64Data: Data, options: Base64DecodingOptions) {
public init?(base64Encoded base64Data: Data, options: Base64DecodingOptions = []) {
guard let decodedBytes = Data.base64DecodeBytes(base64Data.bytes, options: options) else {
return nil
}
Expand Down Expand Up @@ -232,7 +232,7 @@
let appendByteToResult : (UInt8) -> () = {
result.append($0)
currentLineCount += 1
if let options = lineOptions where currentLineCount == options.lineLength {
if let options = lineOptions, currentLineCount == options.lineLength {
result.append(contentsOf: options.separator)
currentLineCount = 0
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFoundation/BitMaskOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public protocol BitMaskOption: RawRepresentable {

public extension BitMaskOption where Self.RawValue: Integer {

static func bitmask<S: Sequence where S.Iterator.Element == Self>(options: S) -> Self.RawValue {
static func bitmask<S: Sequence>(options: S) -> Self.RawValue where S.Iterator.Element == Self {
return options.reduce(0) { mask, option in
mask | option.rawValue
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFoundation/ByteValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public protocol ByteValue: Equatable {

// MARK: - Equatable

public func == <T: ByteValue where T.ByteValue: Equatable> (lhs: T, rhs: T) -> Bool {
public func == <T: ByteValue> (lhs: T, rhs: T) -> Bool where T.ByteValue: Equatable {

return lhs.bytes == rhs.bytes
}
8 changes: 4 additions & 4 deletions Sources/SwiftFoundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

// MARK: - Properties

private var _bytes: ContiguousArray<Byte>
fileprivate var _bytes: ContiguousArray<Byte>

public var bytes: [Byte] {

Expand Down Expand Up @@ -70,7 +70,7 @@
/// - parameter bytes: A pointer to the memory. It will be copied.
/// - parameter count: The number of bytes to copy.
@inline(__always)
public init(bytes pointer: UnsafePointer<Void>, count: Int) {
public init(bytes pointer: UnsafeRawPointer, count: Int) {

_bytes = ContiguousArray<UInt8>(repeating: 0, count: count)

Expand All @@ -85,7 +85,7 @@
guard let pointer = buffer.baseAddress
else { self.init(); return }

self.init(bytes: pointer, count: sizeof(SourceType) * buffer.count)
self.init(bytes: pointer, count: MemoryLayout<SourceType>.size * buffer.count)
}

// MARK: - Accessors
Expand All @@ -100,7 +100,7 @@

public var description: String {

let hexString = bytes.map({ $0.toHexadecimal() }).reduce("", combine: { $0.0 + $0.1 })
let hexString = bytes.map({ $0.toHexadecimal() }).reduce("", { $0.0 + $0.1 })

return "<" + hexString + ">"
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftFoundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public struct FileManager {

let stringBufferSize = Int(PATH_MAX)

let path = UnsafeMutablePointer<CChar>(allocatingCapacity: stringBufferSize)
let path = UnsafeMutablePointer<CChar>.allocate(capacity: stringBufferSize)

defer { path.deallocateCapacity(stringBufferSize) }
defer { path.deallocate(capacity: stringBufferSize) }

getcwd(path, stringBufferSize - 1)

Expand Down Expand Up @@ -193,9 +193,9 @@ public struct FileManager {

#endif

let memoryPointer = UnsafeMutablePointer<Byte>(allocatingCapacity: fileSize)
let memoryPointer = UnsafeMutablePointer<Byte>.allocate(capacity: fileSize)

defer { memoryPointer.deallocateCapacity(fileSize) }
defer { memoryPointer.deallocate(capacity: fileSize) }

let readBytes = read(file, memoryPointer, fileSize)

Expand All @@ -212,7 +212,7 @@ public struct FileManager {
public static func set(contents data: Data, at path: String) throws {

// get file descriptor for path (open file)
let file = open(path, O_WRONLY)
let file = open(path, O_TRUNC | O_WRONLY)

guard file != -1 else { throw POSIXError.fromErrno! }

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFoundation/Hash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
public func Hash(_ data: Data) -> Int {

// more expensive than casting but that's not safe for large values.
return data.bytes.map({ Int($0) }).reduce(0, combine: { $0.0 ^ $0.1 })
return data.bytes.map({ Int($0) }).reduce(0) { $0.0 ^ $0.1 }
}
6 changes: 3 additions & 3 deletions Sources/SwiftFoundation/JSONExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ public extension Collection where Iterator.Element: JSONEncodable {
}
}

public extension Dictionary where Value: JSONEncodable, Key: StringLiteralConvertible {
public extension Collection where Index == DictionaryIndex<String, JSONEncodable>, Iterator.Element == (key: String, value: JSONEncodable) {

/// Encodes the reciever into JSON.
func toJSON() -> JSON.Value {

var jsonObject = JSON.Object(minimumCapacity: self.count)
var jsonObject = JSON.Object(minimumCapacity: numericCast(self.count))

for (key, value) in self {

let jsonValue = value.toJSON()

let keyString = String(key)
let keyString: String = key

jsonObject[keyString] = jsonValue
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftFoundation/JSONParse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public extension JSON.Value {

public init?(string: Swift.String) {

let tokenerError: UnsafeMutablePointer<json_tokener_error>! = UnsafeMutablePointer<json_tokener_error>(allocatingCapacity: 1)
let tokenerError: UnsafeMutablePointer<json_tokener_error>! = UnsafeMutablePointer<json_tokener_error>.allocate(capacity: 1)

defer { tokenerError.deallocateCapacity(1) }
defer { tokenerError.deallocate(capacity: 1) }

let jsonObject = json_tokener_parse_verbose(string, tokenerError)

Expand All @@ -27,7 +27,7 @@ public extension JSON.Value {
// could not parse
guard tokenerError != nil else { return nil }

self = self.dynamicType.init(jsonObject: jsonObject)
self.init(jsonObject: jsonObject)
}
}

Expand Down
18 changes: 9 additions & 9 deletions Sources/SwiftFoundation/JSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ public extension JSON {
public enum WritingOption: BitMaskOption {

/// Causes the output to have minimal whitespace inserted to make things slightly more readable.
case Spaced
case spaced

/// Causes the output to be formatted. See the [Two Space Tab](http://jsonformatter.curiousconcept.com/) option
/// for an example of the format.
case Pretty
case pretty

/// Drop trailing zero for float values
case NoZero
case noZero

public init?(rawValue: Int32) {

switch rawValue {

case JSON_C_TO_STRING_SPACED: self = .Spaced
case JSON_C_TO_STRING_PRETTY: self = .Pretty
case JSON_C_TO_STRING_NOZERO: self = .NoZero
case JSON_C_TO_STRING_SPACED: self = .spaced
case JSON_C_TO_STRING_PRETTY: self = .pretty
case JSON_C_TO_STRING_NOZERO: self = .noZero

default: return nil
}
Expand All @@ -128,9 +128,9 @@ public extension JSON {

switch self {

case Spaced: return JSON_C_TO_STRING_SPACED
case Pretty: return JSON_C_TO_STRING_PRETTY
case NoZero: return JSON_C_TO_STRING_NOZERO
case .spaced: return JSON_C_TO_STRING_SPACED
case .pretty: return JSON_C_TO_STRING_PRETTY
case .noZero: return JSON_C_TO_STRING_NOZERO
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions Sources/SwiftFoundation/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public final class Lock: Locking {

private var mutex = UnsafeMutablePointer<pthread_mutex_t>(allocatingCapacity: 1)
private var mutex = UnsafeMutablePointer<pthread_mutex_t>.allocate(capacity: 1)

public init() {
pthread_mutex_init(mutex, nil)
Expand All @@ -31,7 +31,7 @@
deinit {
pthread_mutex_destroy(mutex)
mutex.deinitialize()
mutex.deallocateCapacity(1)
mutex.deallocate(capacity: 1)
}

public func lock() {
Expand All @@ -50,7 +50,7 @@
}

extension Lock {
private func synchronized<T>(_ closure: @noescape () -> T) -> T {
private func synchronized<T>(_ closure: () -> T) -> T {
self.lock()
defer { self.unlock() }
return closure()
Expand Down Expand Up @@ -131,12 +131,12 @@
}

public final class RecursiveLock: Locking {
private var mutex = UnsafeMutablePointer<pthread_mutex_t>(allocatingCapacity: 1)
private var mutex = UnsafeMutablePointer<pthread_mutex_t>.allocate(capacity: 1)

public init() {

var attrib = pthread_mutexattr_t()
withUnsafeMutablePointer(&attrib) { attrs in
withUnsafeMutablePointer(to: &attrib) { attrs in
pthread_mutexattr_settype(attrs, Int32(PTHREAD_MUTEX_RECURSIVE))
pthread_mutex_init(mutex, attrs)
}
Expand All @@ -145,7 +145,7 @@
deinit {
pthread_mutex_destroy(mutex)
mutex.deinitialize()
mutex.deallocateCapacity(1)
mutex.deallocate(capacity: 1)
}

public func lock() {
Expand All @@ -164,8 +164,8 @@
}

public final class Condition: Locking {
private var mutex = UnsafeMutablePointer<pthread_mutex_t>(allocatingCapacity: 1)
private var cond = UnsafeMutablePointer<pthread_cond_t>(allocatingCapacity: 1)
private var mutex = UnsafeMutablePointer<pthread_mutex_t>.allocate(capacity: 1)
private var cond = UnsafeMutablePointer<pthread_cond_t>.allocate(capacity: 1)

public init() {
pthread_mutex_init(mutex, nil)
Expand All @@ -177,8 +177,8 @@
pthread_cond_destroy(cond)
mutex.deinitialize()
cond.deinitialize()
mutex.deallocateCapacity(1)
cond.deallocateCapacity(1)
mutex.deallocate(capacity: 1)
cond.deallocate(capacity: 1)
}

public func lock() {
Expand All @@ -203,12 +203,12 @@
ts.tv_sec = Int(floor(ti))
ts.tv_nsec = Int((ti - Double(ts.tv_sec)) * 1000000000.0)
var tv = timeval()
withUnsafeMutablePointer(&tv) { t in
withUnsafeMutablePointer(to: &tv) { t in
gettimeofday(t, nil)
ts.tv_sec += t.pointee.tv_sec
ts.tv_nsec += Int((t.pointee.tv_usec * 1000000) / 1000000000)
}
let retVal: Int32 = withUnsafePointer(&ts) { t in
let retVal: Int32 = withUnsafePointer(to: &ts) { t in
return pthread_cond_timedwait(cond, mutex, t)
}

Expand Down
Loading

0 comments on commit 371ec55

Please sign in to comment.