diff --git a/README.md b/README.md index 8728fe250..3c114cdfa 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `Compat.names` supporting keyword arguments for `all` and `imported` ([#25647]). +* `Compat.IOBuffer` supporting keyword arguments ([#25873]). + ## Renaming @@ -571,5 +573,6 @@ includes this fix. Find the minimum version from there. [#25738]: https://github.com/JuliaLang/julia/issues/25738 [#25780]: https://github.com/JuliaLang/julia/issues/25780 [#25819]: https://github.com/JuliaLang/julia/issues/25819 +[#25873]: https://github.com/JuliaLang/julia/issues/25873 [#25990]: https://github.com/JuliaLang/julia/issues/25990 [#26089]: https://github.com/JuliaLang/julia/issues/26089 diff --git a/src/Compat.jl b/src/Compat.jl index 9aa74e09d..3b5a24f91 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1304,7 +1304,7 @@ enable_debug(x::Bool) = DEBUG[] = x @static if !isdefined(Base, Symbol("@debug")) function debug(msg) DEBUG[] || return - buf = IOBuffer() + buf = Base.IOBuffer() iob = Base.redirect(IOContext(buf, STDERR), Base.log_info_to, :debug) print_with_color(:blue, iob, "Debug: "; bold = true) Base.println_with_color(:blue, iob, chomp(string(msg))) @@ -1319,7 +1319,7 @@ else end @static if !isdefined(Base, Symbol("@error")) function _error(msg) - buf = IOBuffer() + buf = Base.IOBuffer() iob = Base.redirect(IOContext(buf, STDERR), Base.log_error_to, :error) print_with_color(Base.error_color(), iob, "Error: "; bold = true) Base.println_with_color(Base.error_color(), iob, chomp(string(msg))) @@ -1513,7 +1513,7 @@ else Base.findnext(t::AbstractString, s::AbstractString, i::Integer) = search(s, t, i) Base.findfirst(t::AbstractString, s::AbstractString) = search(s, t) - Base.findfirst(delim::EqualTo{UInt8}, buf::IOBuffer) = search(buf, delim.x) + Base.findfirst(delim::EqualTo{UInt8}, buf::Base.IOBuffer) = search(buf, delim.x) Base.findprev(c::EqualTo{Char}, s::AbstractString, i::Integer) = rsearch(s, c.x, i) Base.findlast(c::EqualTo{Char}, s::AbstractString) = rsearch(s, c.x) @@ -1559,6 +1559,37 @@ else end end +# https://github.com/JuliaLang/julia/pull/25872 +if VERSION < v"0.7.0-DEV.3734" + function IOBuffer( + data::Union{AbstractVector{UInt8},Nothing}=nothing; + read::Union{Bool,Nothing}=nothing, + write::Union{Bool,Nothing}=nothing, + truncate::Union{Bool,Nothing}=nothing, + maxsize::Integer=typemax(Int), + sizehint::Union{Integer,Nothing}=nothing) + write === nothing && (write = false) + read === nothing && (read = !write) + truncate === nothing && (truncate = false) + if maxsize < 0 + throw(ArgumentError("negative maxsize: $(maxsize)")) + end + if sizehint !== nothing + sizehint!(data, sizehint) + end + buf = if data !== nothing + Base.IOBuffer(data, read, write, Int(maxsize)) + else + size = maxsize == typemax(Int) ? 32 : Int(maxsize) + Base.IOBuffer(StringVector(size), read, write, Int(maxsize)) + end + if truncate + buf.size = 0 + end + return buf + end +end + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 6edf79b78..4ee5dc414 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1427,4 +1427,11 @@ end @test :foo in Compat.names(TestNames) @test :bar in Compat.names(TestNames, all=true) +# 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 + nothing