Skip to content

Commit

Permalink
Drop compat code for IOBuffer from #501 and #504
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Oct 8, 2019
1 parent 5508df6 commit 3333603
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 68 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* Three-argument methods `prevind(s,i,n)`, `nextind(s,i,n)` ([#23805]), and `length(s,i,j)` ([#24999]); the latter two replace `chr2ind` and `ind2chr` in Julia 0.7, respectively.

* `Compat.IOBuffer` supporting keyword arguments ([#25873]).

* `Compat.range` supporting positional and keyword arguments flavors ([#25896]), ([#28708]).

* `Compat.mv` and `Compat.cp` with `force` keyword argument ([#26069]).
Expand Down
51 changes: 0 additions & 51 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,57 +76,6 @@ end
end
end

# https://github.com/JuliaLang/julia/pull/25872
if VERSION < v"0.7.0-DEV.3734"
if isdefined(Base, :open_flags)
import Base.open_flags
else
# copied from Base:
function open_flags(; read=nothing, write=nothing, create=nothing, truncate=nothing, append=nothing)
if write === true && read !== true && append !== true
create === nothing && (create = true)
truncate === nothing && (truncate = true)
end
if truncate === true || append === true
write === nothing && (write = true)
create === nothing && (create = true)
end
write === nothing && (write = false)
read === nothing && (read = !write)
create === nothing && (create = false)
truncate === nothing && (truncate = false)
append === nothing && (append = false)
return (read, write, create, truncate, append)
end
end
function IOBuffer(
data::Union{AbstractVector{UInt8},Nothing}=nothing;
read::Union{Bool,Nothing}=data === nothing ? true : nothing,
write::Union{Bool,Nothing}=data === nothing ? true : nothing,
truncate::Union{Bool,Nothing}=data === nothing ? true : nothing,
maxsize::Integer=typemax(Int),
sizehint::Union{Integer,Nothing}=nothing)
flags = open_flags(read=read, write=write, append=nothing, truncate=truncate)
if maxsize < 0
throw(ArgumentError("negative maxsize: $(maxsize)"))
end
if data !== nothing
if sizehint !== nothing
sizehint!(data, sizehint)
end
buf = Base.IOBuffer(data, flags[1], flags[2], Int(maxsize))
else
size = sizehint !== nothing ? Int(sizehint) : maxsize != typemax(Int) ? Int(maxsize) : 32
buf = Base.IOBuffer(Base.StringVector(size), flags[1], flags[2], Int(maxsize))
buf.data[:] = 0
end
if flags[4] # flags.truncate
buf.size = 0
end
return buf
end
end

@static if VERSION < v"0.7.0-DEV.3986"
const LinRange = Base.LinSpace
export LinRange
Expand Down
15 changes: 15 additions & 0 deletions test/old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,18 @@ end
@test Compat.ceil(pi, digits = 3, base = 2) == 3.25
@test Compat.round(pi, digits = 3, base = 2) == 3.125
@test Compat.round(pi, sigdigits = 5, base = 2) == 3.125

# 0.7.0-DEV.3734
let buf = Compat.IOBuffer(read=true, write=false, maxsize=25)
@test buf.readable
@test !buf.writable
@test buf.maxsize == 25
end
let buf = Compat.IOBuffer(zeros(UInt8, 4), write=true) # issue #502
write(buf, 'a')
@test take!(buf) == [0x61]
end
let buf = Compat.IOBuffer(sizehint=20)
println(buf, "Hello world.")
@test String(take!(buf)) == "Hello world.\n"
end
15 changes: 0 additions & 15 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ end

@test codeunit("foo") == codeunit(SubString("fooαβγ",1,3)) == UInt8

# 0.7.0-DEV.3734
let buf = Compat.IOBuffer(read=true, write=false, maxsize=25)
@test buf.readable
@test !buf.writable
@test buf.maxsize == 25
end
let buf = Compat.IOBuffer(zeros(UInt8, 4), write=true) # issue #502
write(buf, 'a')
@test take!(buf) == [0x61]
end
let buf = Compat.IOBuffer(sizehint=20)
println(buf, "Hello world.")
@test String(take!(buf)) == "Hello world.\n"
end

# 0.7.0-DEV.3986
@test_throws ArgumentError Compat.range(1)
@test_throws ArgumentError Compat.range(nothing)
Expand Down

0 comments on commit 3333603

Please sign in to comment.