Skip to content

Commit

Permalink
Fix compatibility with Linux
Browse files Browse the repository at this point in the history
Fixes #12.
  • Loading branch information
lilyball committed Mar 6, 2017
1 parent d968ee5 commit c2f0a20
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Sources/Accessors.swift
Expand Up @@ -313,7 +313,7 @@ internal func convertDoubleToInt64(_ d: Double) -> Int64? {
return NSDecimalNumber(decimal: d).int64Value
}
#else
internal func convertDecimalToInt64(_ d: ()) -> Int64? {
internal func convertDecimalToInt64(_ d: DecimalPlaceholder) -> Int64? {
return nil
}
#endif
6 changes: 5 additions & 1 deletion Sources/JSON.swift
Expand Up @@ -16,7 +16,11 @@
import struct Foundation.Decimal
#else
/// A placeholder used for platforms that don't support `Decimal`.
public typealias DecimalPlaceholder = ()
public struct DecimalPlaceholder: Equatable {
public static func ==(lhs: DecimalPlaceholder, rhs: DecimalPlaceholder) -> Bool {
return true
}
}
#endif

/// A single JSON-compatible value.
Expand Down
2 changes: 0 additions & 2 deletions Sources/JSONError.swift
Expand Up @@ -1764,7 +1764,6 @@ internal func getRequired(_ ary: JSONArray, index: Int, type: JSONError.JSONType
return value
}

@inline(__always)
internal func scoped<T>(_ key: String, _ f: () throws -> T) rethrows -> T {
do {
return try f()
Expand All @@ -1773,7 +1772,6 @@ internal func scoped<T>(_ key: String, _ f: () throws -> T) rethrows -> T {
}
}

@inline(__always)
internal func scoped<T>(_ index: Int, _ f: () throws -> T) rethrows -> T {
do {
return try f()
Expand Down
10 changes: 5 additions & 5 deletions Sources/Parser.swift
Expand Up @@ -395,7 +395,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
}
#endif
/// Invoke this after parsing the "e" character.
@inline(__always) func parseExponent() throws -> JSONEvent {
func parseExponent() throws -> JSONEvent {
let c = try bumpRequired()
tempBuffer.append(Int8(truncatingBitPattern: c.value))
switch c {
Expand All @@ -420,7 +420,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
}
#endif
tempBuffer.append(0)
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)}))
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress!, nil)}))
}
outerLoop: while let c = base.peek() {
switch c {
Expand Down Expand Up @@ -451,7 +451,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
}
#endif
tempBuffer.append(0)
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)}))
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress!, nil)}))
case "e", "E":
bump()
tempBuffer.append(Int8(truncatingBitPattern: c.value))
Expand All @@ -466,7 +466,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
tempBuffer.append(0)
let num = tempBuffer.withUnsafeBufferPointer({ ptr -> Int64? in
errno = 0
let n = strtoll(ptr.baseAddress, nil, 10)
let n = strtoll(ptr.baseAddress!, nil, 10)
if n == 0 && errno != 0 {
return nil
} else {
Expand All @@ -483,7 +483,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
return try .decimalValue(tempBuffer.withUnsafeBufferPointer(parseDecimal(from:)))
}
#endif
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)}))
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress!, nil)}))
case "t":
let line = self.line, column = self.column
guard case "r"? = bump(), case "u"? = bump(), case "e"? = bump() else {
Expand Down

0 comments on commit c2f0a20

Please sign in to comment.