Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick fix for PMJSON on Linux #12

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/JSON.swift
Expand Up @@ -17,6 +17,10 @@
#else
/// A placeholder used for platforms that don't support `Decimal`.
public typealias DecimalPlaceholder = ()
func ==(left:DecimalPlaceholder, right:DecimalPlaceholder) -> Bool {
return true
}

#endif

/// A single JSON-compatible value.
Expand Down
2 changes: 1 addition & 1 deletion Sources/JSONError.swift
Expand Up @@ -64,7 +64,7 @@ public enum JSONError: Error, CustomStringConvertible {
}
}

fileprivate func withPrefix(_ prefix: String) -> JSONError {
func withPrefix(_ prefix: String) -> JSONError {
func prefixPath(_ path: String?, with prefix: String) -> String {
guard let path = path, !path.isEmpty else { return prefix }
if path.unicodeScalars.first == "[" {
Expand Down
18 changes: 9 additions & 9 deletions Sources/Parser.swift
Expand Up @@ -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 Expand Up @@ -536,7 +536,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
return UInt16(truncatingBitPattern: codepoint)
}

@inline(__always) @discardableResult private mutating func bump() -> UnicodeScalar? {
@inline(__always) @discardableResult mutating func bump() -> UnicodeScalar? {
let c = base.next()
if c == "\n" {
line += 1
Expand All @@ -547,12 +547,12 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
return c
}

@inline(__always) private mutating func bumpRequired() throws -> UnicodeScalar {
@inline(__always) mutating func bumpRequired() throws -> UnicodeScalar {
guard let c = bump() else { throw error(.unexpectedEOF) }
return c
}

private func error(_ code: JSONParserError.Code) -> JSONParserError {
func error(_ code: JSONParserError.Code) -> JSONParserError {
return JSONParserError(code: code, line: line, column: column)
}

Expand All @@ -561,7 +561,7 @@ public struct JSONParserIterator<Iter: IteratorProtocol>: JSONEventIterator wher
/// The column of the last emitted token.
public private(set) var column: UInt = 0

private var base: PeekIterator<Iter>
var base: PeekIterator<Iter>
private var state: State = .initial
private var stack: [Stack] = []
private var tempBuffer: ContiguousArray<Int8>?
Expand Down Expand Up @@ -784,7 +784,7 @@ public struct JSONParserError: Error, Hashable, CustomStringConvertible {
}
}

private struct PeekIterator<Base: IteratorProtocol> {
struct PeekIterator<Base: IteratorProtocol> {
init(_ base: Base) {
self.base = base
}
Expand Down