Skip to content

Commit

Permalink
Fixes for v0.7 (#252)
Browse files Browse the repository at this point in the history
* Remove dependency on the Nullables package, and use `Union{Nothing,T}` instead of `Nullable{T}`

* Bump the required Julia version in REQUIRE and CI scripts

* Remove the dependency on Compat
  • Loading branch information
fredrikekre authored and ararslan committed Jul 2, 2018
1 parent 60dda17 commit a822864
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ os:
- osx
- linux
julia:
- 0.6
- 0.7
- nightly
notifications:
email: false
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ JSON.print(io::IO, s::AbstractString)
JSON.print(io::IO, s::Union{Integer, AbstractFloat})
JSON.print(io::IO, n::Nothing)
JSON.print(io::IO, b::Bool)
JSON.print(io::IO, a::Associative)
JSON.print(io::IO, a::AbstractDict)
JSON.print(io::IO, v::AbstractVector)
JSON.print{T, N}(io::IO, v::Array{T, N})
```
Expand All @@ -48,8 +48,8 @@ Writes a compact (no extra whitespace or indentation) JSON representation
to the supplied IO.

```julia
JSON.print(a::Associative, indent)
JSON.print(io::IO, a::Associative, indent)
JSON.print(a::AbstractDict, indent)
JSON.print(io::IO, a::AbstractDict, indent)
```

Writes a JSON representation with newlines, and indentation if specified. Non-zero `indent` will be applied recursively to nested elements.
Expand Down
4 changes: 1 addition & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
julia 0.6
Compat 0.61.0
Nullables 0.0.1
julia 0.7-alpha
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
5 changes: 1 addition & 4 deletions src/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ Internal implementation detail.
"""
module Common

using Compat
if VERSION >= v"0.7.0-DEV.2915"
using Unicode
end
using Unicode

include("bytes.jl")
include("errors.jl")
Expand Down
2 changes: 0 additions & 2 deletions src/JSON.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ __precompile__()

module JSON

using Compat

export json # returns a compact (or indented) JSON representation as a string
export JSONText # string wrapper to insert raw JSON into JSON output

Expand Down
9 changes: 4 additions & 5 deletions src/Parser.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Parser # JSON

using Compat
using Compat.Mmap
using Nullables
using Mmap
using ..Common

"""
Expand Down Expand Up @@ -312,8 +310,9 @@ byte before `to`. Bytes enclosed should all be ASCII characters.
function float_from_bytes(bytes, from::Int, to::Int)
# The ccall is not ideal (Base.tryparse would be better), but it actually
# makes an 2× difference to performance
ccall(:jl_try_substrtod, Nullable{Float64},
hasvalue, val = ccall(:jl_try_substrtod, Tuple{Bool, Float64},
(Ptr{UInt8}, Csize_t, Csize_t), bytes, from - 1, to - from + 1)
hasvalue ? val : nothing
end

"""
Expand Down Expand Up @@ -350,7 +349,7 @@ function number_from_bytes(pc::ParserContext,
int_from_bytes(pc, ps, bytes, from, to)
else
res = float_from_bytes(bytes, from, to)
isnull(res) ? _error(E_BAD_NUMBER, ps) : get(res)
res === nothing ? _error(E_BAD_NUMBER, ps) : res
end
end

Expand Down
18 changes: 3 additions & 15 deletions src/Writer.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
module Writer

using Compat
using Compat.Dates
using Nullables
using Dates
using ..Common
using ..Serializations: Serialization, StandardSerialization,
CommonSerialization

if VERSION >= v"0.7.0-DEV.2915"
using Unicode
end
using Unicode


"""
Expand Down Expand Up @@ -268,14 +264,6 @@ end

show_json(io::SC, ::CS, ::Nothing) = show_null(io)

function show_json(io::SC, s::CS, a::Nullable)
if isnull(a)
Base.print(io, "null")
else
show_json(io, s, get(a))
end
end

function show_json(io::SC, s::CS, a::AbstractDict)
begin_object(io)
for kv in a
Expand Down Expand Up @@ -313,7 +301,7 @@ Serialize a multidimensional array to JSON in column-major format. That is,
function show_json(io::SC, s::CS, A::AbstractArray{<:Any,n}) where n
begin_array(io)
newdims = ntuple(_ -> :, n - 1)
for j in Compat.axes(A, n)
for j in axes(A, n)
show_element(io, s, view(A, newdims..., j))
end
end_array(io)
Expand Down
6 changes: 1 addition & 5 deletions src/bytes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ for c in 0x00:0xFF
elseif haskey(REVERSE_ESCAPES, c)
[BACKSLASH, REVERSE_ESCAPES[c]]
elseif iscntrl(Char(c)) || !isprint(Char(c))
if VERSION < v"0.7.0-DEV.4446"
UInt8[BACKSLASH, LATIN_U, hex(c, 4)...]
else
UInt8[BACKSLASH, LATIN_U, string(c, base=16, pad=4)...]
end
UInt8[BACKSLASH, LATIN_U, string(c, base=16, pad=4)...]
else
[c]
end
Expand Down
6 changes: 1 addition & 5 deletions src/specialized.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
function maxsize_buffer(maxsize::Int)
@static if VERSION < v"0.7.0-DEV.3734"
IOBuffer(maxsize)
else
IOBuffer(maxsize=maxsize)
end
IOBuffer(maxsize=maxsize)
end

# Specialized functions for increased performance when JSON is in-memory
Expand Down
1 change: 0 additions & 1 deletion test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DataStructures
FixedPointNumbers
OffsetArrays
Compat 0.37.0
4 changes: 1 addition & 3 deletions test/async.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
finished_async_tests = RemoteChannel()

if VERSION >= v"0.7.0-DEV.4442"
using Sockets
end
using Sockets

@async begin
s = listen(7777)
Expand Down
4 changes: 2 additions & 2 deletions test/lowering.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module TestLowering

using JSON
using Compat.Test
using Compat.Dates
using Test
using Dates
using FixedPointNumbers: Fixed

@test JSON.json(Date(2016, 8, 3)) == "\"2016-08-03\""
Expand Down
2 changes: 1 addition & 1 deletion test/parser/parsefile.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tmppath, io = mktemp()
write(io, facebook)
close(io)
if Compat.Sys.iswindows()
if Sys.iswindows()
# don't use mmap on Windows, to avoid ERROR: unlink: operation not permitted (EPERM)
@test haskey(JSON.parsefile(tmppath; use_mmap=false), "data")
else
Expand Down
7 changes: 3 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using JSON
using Compat.Test
using Compat
using Compat.Dates
using Compat.Distributed: RemoteChannel
using Test
using Dates
using Distributed: RemoteChannel
using OffsetArrays

import DataStructures
Expand Down
2 changes: 1 addition & 1 deletion test/serializer.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TestSerializer

using JSON
using Compat.Test
using Test

# to define a new serialization behaviour, import these first
import JSON.Serializations: CommonSerialization, StandardSerialization
Expand Down
10 changes: 4 additions & 6 deletions test/standard-serializer.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Nullables

@testset "Symbol" begin
symtest = Dict(:symbolarray => [:apple, :pear], :symbolsingleton => :hello)
@test (JSON.json(symtest) == "{\"symbolarray\":[\"apple\",\"pear\"],\"symbolsingleton\":\"hello\"}"
Expand All @@ -11,10 +9,10 @@ end
@test sprint(JSON.print, [Inf]) == "[null]"
end

@testset "Nullable" begin
@test sprint(JSON.print, [Nullable()]) == "[null]"
@test sprint(JSON.print, [Nullable{Int64}()]) == "[null]"
@test sprint(JSON.print, [Nullable{Int64}(Int64(1))]) == "[1]"
@testset "Union{Nothing,T} (old Nullable)" begin
@test sprint(JSON.print, Union{Any,Nothing}[nothing]) == "[null]"
@test sprint(JSON.print, Union{Int64,Nothing}[nothing]) == "[null]"
@test sprint(JSON.print, Union{Int64,Nothing}[1]) == "[1]"
end

@testset "Char" begin
Expand Down

0 comments on commit a822864

Please sign in to comment.