From a822864725f431a1084d314af7834eda9c72d86a Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Mon, 2 Jul 2018 08:21:49 +0200 Subject: [PATCH] Fixes for v0.7 (#252) * 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 --- .travis.yml | 2 +- README.md | 6 +++--- REQUIRE | 4 +--- appveyor.yml | 4 ++-- src/Common.jl | 5 +---- src/JSON.jl | 2 -- src/Parser.jl | 9 ++++----- src/Writer.jl | 18 +++--------------- src/bytes.jl | 6 +----- src/specialized.jl | 6 +----- test/REQUIRE | 1 - test/async.jl | 4 +--- test/lowering.jl | 4 ++-- test/parser/parsefile.jl | 2 +- test/runtests.jl | 7 +++---- test/serializer.jl | 2 +- test/standard-serializer.jl | 10 ++++------ 17 files changed, 29 insertions(+), 63 deletions(-) diff --git a/.travis.yml b/.travis.yml index 868e9a2..2550a73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ os: - osx - linux julia: - - 0.6 + - 0.7 - nightly notifications: email: false diff --git a/README.md b/README.md index e44cca3..eac6839 100644 --- a/README.md +++ b/README.md @@ -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}) ``` @@ -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. diff --git a/REQUIRE b/REQUIRE index d71c8f0..cdbb2dc 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1 @@ -julia 0.6 -Compat 0.61.0 -Nullables 0.0.1 +julia 0.7-alpha diff --git a/appveyor.yml b/appveyor.yml index fde4cb5..de914ec 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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" diff --git a/src/Common.jl b/src/Common.jl index 0e85706..55b1fe5 100644 --- a/src/Common.jl +++ b/src/Common.jl @@ -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") diff --git a/src/JSON.jl b/src/JSON.jl index b5f9e5b..4e5a01e 100644 --- a/src/JSON.jl +++ b/src/JSON.jl @@ -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 diff --git a/src/Parser.jl b/src/Parser.jl index ac6ef2d..147d675 100644 --- a/src/Parser.jl +++ b/src/Parser.jl @@ -1,8 +1,6 @@ module Parser # JSON -using Compat -using Compat.Mmap -using Nullables +using Mmap using ..Common """ @@ -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 """ @@ -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 diff --git a/src/Writer.jl b/src/Writer.jl index 7335f5b..d60dcbd 100644 --- a/src/Writer.jl +++ b/src/Writer.jl @@ -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 """ @@ -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 @@ -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) diff --git a/src/bytes.jl b/src/bytes.jl index a5f2768..57b92a8 100644 --- a/src/bytes.jl +++ b/src/bytes.jl @@ -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 diff --git a/src/specialized.jl b/src/specialized.jl index f796e4e..dee81ba 100644 --- a/src/specialized.jl +++ b/src/specialized.jl @@ -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 diff --git a/test/REQUIRE b/test/REQUIRE index 4878360..d0dacdd 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,4 +1,3 @@ DataStructures FixedPointNumbers OffsetArrays -Compat 0.37.0 diff --git a/test/async.jl b/test/async.jl index 6ef44e7..1612a6e 100644 --- a/test/async.jl +++ b/test/async.jl @@ -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) diff --git a/test/lowering.jl b/test/lowering.jl index bf52c4b..388cff1 100644 --- a/test/lowering.jl +++ b/test/lowering.jl @@ -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\"" diff --git a/test/parser/parsefile.jl b/test/parser/parsefile.jl index 07cc589..f5b9f6c 100644 --- a/test/parser/parsefile.jl +++ b/test/parser/parsefile.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index fb4d1a1..e732e5d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 diff --git a/test/serializer.jl b/test/serializer.jl index 24b0b2e..87927fe 100644 --- a/test/serializer.jl +++ b/test/serializer.jl @@ -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 diff --git a/test/standard-serializer.jl b/test/standard-serializer.jl index 07e37ab..034bfc4 100644 --- a/test/standard-serializer.jl +++ b/test/standard-serializer.jl @@ -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\"}" @@ -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