Skip to content

Commit c2f0a20

Browse files
committed
Fix compatibility with Linux
Fixes #12.
1 parent d968ee5 commit c2f0a20

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

Sources/Accessors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ internal func convertDoubleToInt64(_ d: Double) -> Int64? {
313313
return NSDecimalNumber(decimal: d).int64Value
314314
}
315315
#else
316-
internal func convertDecimalToInt64(_ d: ()) -> Int64? {
316+
internal func convertDecimalToInt64(_ d: DecimalPlaceholder) -> Int64? {
317317
return nil
318318
}
319319
#endif

Sources/JSON.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
import struct Foundation.Decimal
1717
#else
1818
/// A placeholder used for platforms that don't support `Decimal`.
19-
public typealias DecimalPlaceholder = ()
19+
public struct DecimalPlaceholder: Equatable {
20+
public static func ==(lhs: DecimalPlaceholder, rhs: DecimalPlaceholder) -> Bool {
21+
return true
22+
}
23+
}
2024
#endif
2125

2226
/// A single JSON-compatible value.

Sources/JSONError.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,6 @@ internal func getRequired(_ ary: JSONArray, index: Int, type: JSONError.JSONType
17641764
return value
17651765
}
17661766

1767-
@inline(__always)
17681767
internal func scoped<T>(_ key: String, _ f: () throws -> T) rethrows -> T {
17691768
do {
17701769
return try f()
@@ -1773,7 +1772,6 @@ internal func scoped<T>(_ key: String, _ f: () throws -> T) rethrows -> T {
17731772
}
17741773
}
17751774

1776-
@inline(__always)
17771775
internal func scoped<T>(_ index: Int, _ f: () throws -> T) rethrows -> T {
17781776
do {
17791777
return try f()

Sources/Parser.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
395395
}
396396
#endif
397397
/// Invoke this after parsing the "e" character.
398-
@inline(__always) func parseExponent() throws -> JSONEvent {
398+
func parseExponent() throws -> JSONEvent {
399399
let c = try bumpRequired()
400400
tempBuffer.append(Int8(truncatingBitPattern: c.value))
401401
switch c {
@@ -420,7 +420,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
420420
}
421421
#endif
422422
tempBuffer.append(0)
423-
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)}))
423+
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress!, nil)}))
424424
}
425425
outerLoop: while let c = base.peek() {
426426
switch c {
@@ -451,7 +451,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
451451
}
452452
#endif
453453
tempBuffer.append(0)
454-
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)}))
454+
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress!, nil)}))
455455
case "e", "E":
456456
bump()
457457
tempBuffer.append(Int8(truncatingBitPattern: c.value))
@@ -466,7 +466,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
466466
tempBuffer.append(0)
467467
let num = tempBuffer.withUnsafeBufferPointer({ ptr -> Int64? in
468468
errno = 0
469-
let n = strtoll(ptr.baseAddress, nil, 10)
469+
let n = strtoll(ptr.baseAddress!, nil, 10)
470470
if n == 0 && errno != 0 {
471471
return nil
472472
} else {
@@ -483,7 +483,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
483483
return try .decimalValue(tempBuffer.withUnsafeBufferPointer(parseDecimal(from:)))
484484
}
485485
#endif
486-
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)}))
486+
return .doubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress!, nil)}))
487487
case "t":
488488
let line = self.line, column = self.column
489489
guard case "r"? = bump(), case "u"? = bump(), case "e"? = bump() else {

0 commit comments

Comments
 (0)