diff --git a/base/LineEdit.jl b/base/LineEdit.jl index 9298c4dee2bc2c..704dc146965f33 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -267,7 +267,7 @@ function refresh_multi_line(terminal::UnixTerminal, args...; kwargs...) termbuf = TerminalBuffer(outbuf) ret = refresh_multi_line(termbuf, terminal, args...;kwargs...) # Output the entire refresh at once - write(terminal, takebuf_array(outbuf)) + write(terminal, take!(outbuf)) flush(terminal) return ret end @@ -668,7 +668,7 @@ function normalize_key(key::AbstractString) write(buf, c) end end - return takebuf_string(buf) + return String(take!(buf)) end function normalize_keys(keymap::Dict) @@ -1501,7 +1501,7 @@ end activate(m::ModalInterface, s::MIState, termbuf, term::TextTerminal) = activate(s.current_mode, s, termbuf, term) -commit_changes(t::UnixTerminal, termbuf) = write(t, takebuf_array(termbuf.out_stream)) +commit_changes(t::UnixTerminal, termbuf) = write(t, take!(termbuf.out_stream)) function transition(f::Function, s::MIState, mode) if mode === :abort s.aborted = true diff --git a/base/REPL.jl b/base/REPL.jl index 02c1e147f925f3..0841d7c74ff858 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -646,7 +646,7 @@ function respond(f, repl, main; pass_empty = false) if !ok return transition(s, :abort) end - line = takebuf_string(buf) + line = String(take!(buf)) if !isempty(line) || pass_empty reset(repl) val, bt = send_to_backend(f(line), backend(repl)) @@ -840,7 +840,7 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep return end edit_insert(sbuffer, input) - input = takebuf_string(sbuffer) + input = String(take!(sbuffer)) oldpos = start(input) firstline = true isprompt_paste = false diff --git a/base/REPLCompletions.jl b/base/REPLCompletions.jl index 70443f478ab087..f4c98ef50011b2 100644 --- a/base/REPLCompletions.jl +++ b/base/REPLCompletions.jl @@ -331,7 +331,7 @@ function complete_methods(ex_org::Expr) # Check if the method's type signature intersects the input types if typeintersect(Tuple{method.sig.parameters[1 : min(na, end)]...}, t_in) != Union{} show(io, method, kwtype=kwtype) - push!(out, takebuf_string(io)) + push!(out, String(take!(io))) end end return out diff --git a/base/base64.jl b/base/base64.jl index f36f78cc492f3d..8315613fd33602 100644 --- a/base/base64.jl +++ b/base/base64.jl @@ -176,7 +176,7 @@ function base64encode(f::Function, args...) b = Base64EncodePipe(s) f(b, args...) close(b) - takebuf_string(s) + String(take!(s)) end base64encode(x...) = base64encode(write, x...) diff --git a/base/c.jl b/base/c.jl index 9b50629ffdec88..031e004663d7db 100644 --- a/base/c.jl +++ b/base/c.jl @@ -167,7 +167,7 @@ transcode{T<:Union{Int32,UInt32}}(::Type{T}, src::Vector{UInt8}) = transcode(T, function transcode{S<:Union{Int32,UInt32}}(::Type{UInt8}, src::Vector{S}) buf = IOBuffer() for c in src; print(buf, Char(c)); end - takebuf_array(buf) + take!(buf) end transcode(::Type{String}, src::String) = src transcode(T, src::String) = transcode(T, src.data) diff --git a/base/datafmt.jl b/base/datafmt.jl index 13efa2c337277a..b702442d428cb9 100644 --- a/base/datafmt.jl +++ b/base/datafmt.jl @@ -643,9 +643,9 @@ function writedlm(io::IO, a::AbstractMatrix, dlm; opts...) writedlm_cell(pb, a[i, j], dlm, quotes) j == lastc ? write(pb,'\n') : print(pb,dlm) end - (nb_available(pb) > (16*1024)) && write(io, takebuf_array(pb)) + (nb_available(pb) > (16*1024)) && write(io, take!(pb)) end - write(io, takebuf_array(pb)) + write(io, take!(pb)) nothing end @@ -677,9 +677,9 @@ function writedlm(io::IO, itr, dlm; opts...) pb = PipeBuffer() for row in itr writedlm_row(pb, row, dlm, quotes) - (nb_available(pb) > (16*1024)) && write(io, takebuf_array(pb)) + (nb_available(pb) > (16*1024)) && write(io, take!(pb)) end - write(io, takebuf_array(pb)) + write(io, take!(pb)) nothing end diff --git a/base/deprecated.jl b/base/deprecated.jl index 8dbbb86a349b0d..878f4dcf48a241 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1109,4 +1109,8 @@ end) @deprecate den denominator @deprecate num numerator +# #19088 +@deprecate takebuf_array take! +@deprecate takebuf_string(b) String(take!(b)) + # End deprecations scheduled for 0.6 diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index 63925579e22e0d..a6377356921ebc 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -52,14 +52,6 @@ Compute the inverse sine of `x`, where the output is in radians. """ asin -""" - takebuf_array(b::IOBuffer) - -Obtain the contents of an `IOBuffer` as an array, without copying. Afterwards, the -`IOBuffer` is reset to its initial state. -""" -takebuf_array - """ pointer(array [, index]) diff --git a/base/exports.jl b/base/exports.jl index 65c8768280371d..56a0af9a333537 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1166,8 +1166,7 @@ export serialize, skip, skipchars, - takebuf_array, - takebuf_string, + take!, truncate, unmark, watch_file, diff --git a/base/io.jl b/base/io.jl index 4eef9cfedd980d..4e6f157d490d0a 100644 --- a/base/io.jl +++ b/base/io.jl @@ -400,7 +400,7 @@ function readuntil(s::IO, delim::Char) break end end - return takebuf_string(out) + return String(take!(out)) end function readuntil{T}(s::IO, delim::T) @@ -445,7 +445,7 @@ function readuntil(s::IO, t::AbstractString) break end end - return takebuf_string(out) + return String(take!(out)) end readline() = readline(STDIN) diff --git a/base/iobuffer.jl b/base/iobuffer.jl index d55b2aa7e2b2a7..f4515bcc84cdb8 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -253,7 +253,13 @@ function String(io::AbstractIOBuffer) return String(copy!(Array{UInt8}(io.size), 1, io.data, 1, io.size)) end -function takebuf_array(io::AbstractIOBuffer) +""" + take!(b::IOBuffer) + +Obtain the contents of an `IOBuffer` as an array, without copying. Afterwards, the +`IOBuffer` is reset to its initial state. +""" +function take!(io::AbstractIOBuffer) ismarked(io) && unmark(io) if io.seekable nbytes = io.size @@ -268,7 +274,7 @@ function takebuf_array(io::AbstractIOBuffer) end return data end -function takebuf_array(io::IOBuffer) +function take!(io::IOBuffer) ismarked(io) && unmark(io) if io.seekable data = io.data @@ -291,14 +297,6 @@ function takebuf_array(io::IOBuffer) return data end -""" - takebuf_string(b::IOBuffer) - -Obtain the contents of an `IOBuffer` as a string, without copying. -Afterwards, the `IOBuffer` is reset to its initial state. -""" -takebuf_string(io::AbstractIOBuffer) = String(takebuf_array(io)) - function write(to::AbstractIOBuffer, from::AbstractIOBuffer) if to === from from.ptr = from.size + 1 diff --git a/base/iostream.jl b/base/iostream.jl index 7c1cde05eaf2f0..0ab86c1005d1d2 100644 --- a/base/iostream.jl +++ b/base/iostream.jl @@ -13,7 +13,7 @@ type IOStream <: IO IOStream(name::AbstractString, buf::Array{UInt8,1}) = new(pointer(buf), buf, name, -1) end # TODO: delay adding finalizer, e.g. for memio with a small buffer, or -# in the case where we takebuf it. +# in the case where we take! it. function IOStream(name::AbstractString, finalize::Bool) buf = zeros(UInt8,sizeof_ios_t) x = IOStream(name, buf) @@ -218,11 +218,8 @@ function write(s::IOStream, c::Char) end read(s::IOStream, ::Type{Char}) = Char(ccall(:jl_getutf8, UInt32, (Ptr{Void},), s.ios)) -takebuf_string(s::IOStream) = - ccall(:jl_takebuf_string, Ref{String}, (Ptr{Void},), s.ios) - -takebuf_array(s::IOStream) = - ccall(:jl_takebuf_array, Vector{UInt8}, (Ptr{Void},), s.ios) +take!(s::IOStream) = + ccall(:jl_take_buffer, Vector{UInt8}, (Ptr{Void},), s.ios) function takebuf_raw(s::IOStream) sz = position(s) diff --git a/base/markdown/Common/block.jl b/base/markdown/Common/block.jl index 52a470b2241e9c..56c2e2c705c4ea 100644 --- a/base/markdown/Common/block.jl +++ b/base/markdown/Common/block.jl @@ -115,7 +115,7 @@ function indentcode(stream::IO, block::MD) break end end - code = takebuf_string(buffer) + code = String(take!(buffer)) !isempty(code) && (push!(block, Code(rstrip(code))); return true) return false end @@ -179,7 +179,7 @@ function blockquote(stream::IO, block::MD) end empty && return false - md = takebuf_string(buffer) + md = String(take!(buffer)) push!(block, BlockQuote(parse(md, flavor = config(block)).content)) return true end @@ -237,7 +237,7 @@ function admonition(stream::IO, block::MD) end end # Parse the nested block as markdown and create a new Admonition block. - nested = parse(takebuf_string(buffer), flavor = config(block)) + nested = parse(String(take!(buffer)), flavor = config(block)) push!(block, Admonition(category, title, nested.content)) return true end @@ -326,7 +326,7 @@ function list(stream::IO, block::MD) return true end end -pushitem!(list, buffer) = push!(list.items, parse(takebuf_string(buffer)).content) +pushitem!(list, buffer) = push!(list.items, parse(String(take!(buffer))).content) # –––––––––––––– # HorizontalRule diff --git a/base/markdown/GitHub/GitHub.jl b/base/markdown/GitHub/GitHub.jl index 319d5938aa49c4..591634d8e50b58 100644 --- a/base/markdown/GitHub/GitHub.jl +++ b/base/markdown/GitHub/GitHub.jl @@ -21,9 +21,9 @@ function fencedcode(stream::IO, block::MD) if startswith(stream, string(ch) ^ n) if !startswith(stream, string(ch)) if flavor == "math" - push!(block, LaTeX(takebuf_string(buffer) |> chomp)) + push!(block, LaTeX(String(take!(buffer)) |> chomp)) else - push!(block, Code(flavor, takebuf_string(buffer) |> chomp)) + push!(block, Code(flavor, String(take!(buffer)) |> chomp)) end return true else diff --git a/base/markdown/parse/parse.jl b/base/markdown/parse/parse.jl index 5df7ff71884b5e..0b22c8306e8ea8 100644 --- a/base/markdown/parse/parse.jl +++ b/base/markdown/parse/parse.jl @@ -56,7 +56,7 @@ function parseinline(stream::IO, md::MD, config::Config) char = Char(peek(stream)) if haskey(config.inner, char) && (inner = parseinline(stream, md, config.inner[char])) !== nothing - c = takebuf_string(buffer) + c = String(take!(buffer)) !isempty(c) && push!(content, c) buffer = IOBuffer() push!(content, inner) @@ -64,7 +64,7 @@ function parseinline(stream::IO, md::MD, config::Config) write(buffer, read(stream, Char)) end end - c = takebuf_string(buffer) + c = String(take!(buffer)) !isempty(c) && push!(content, c) return content end diff --git a/base/markdown/parse/util.jl b/base/markdown/parse/util.jl index 71efddb507d1e9..023b598e63709e 100644 --- a/base/markdown/parse/util.jl +++ b/base/markdown/parse/util.jl @@ -143,7 +143,7 @@ function readuntil(stream::IO, delimiter; newlines = false, match = nothing) while !eof(stream) if startswith(stream, delimiter) if count == 0 - return takebuf_string(buffer) + return String(take!(buffer)) else count -= 1 write(buffer, delimiter) @@ -190,7 +190,7 @@ function parse_inline_wrapper(stream::IO, delimiter::AbstractString; rep = false if !(char in whitespace || char == '\n' || char in delimiter) && startswith(stream, delimiter^n) trailing = 0 while startswith(stream, delimiter); trailing += 1; end - trailing == 0 && return takebuf_string(buffer) + trailing == 0 && return String(take!(buffer)) write(buffer, delimiter ^ (n + trailing)) end end diff --git a/base/multimedia.jl b/base/multimedia.jl index dab8043d57d007..598b4d6bd16062 100644 --- a/base/multimedia.jl +++ b/base/multimedia.jl @@ -63,7 +63,7 @@ _textreprmime(m::MIME"text/plain", x::AbstractString) = function _binreprmime(m::MIME, x) s = IOBuffer() verbose_show(s, m, x) - takebuf_array(s) + take!(s) end _binreprmime(m::MIME, x::Vector{UInt8}) = x diff --git a/base/precompile.jl b/base/precompile.jl index 7e1ddd550ec4b0..ee70a0744a4e0a 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -389,7 +389,7 @@ precompile(Base.systemerror, (Symbol, Bool)) precompile(Base.take!, (Base.RemoteValue,)) precompile(Base.take!, (RemoteChannel,)) precompile(Base.take_ref, (Tuple{Int,Int},)) -precompile(Base.takebuf_string, (IOBuffer,)) +precompile(Base.take!, (IOBuffer,)) precompile(Base.task_local_storage, ()) precompile(Base.terminate_all_workers, ()) precompile(Base.try_include, (String,)) diff --git a/base/printf.jl b/base/printf.jl index 6cb8998eb9f4c8..912c24f0a8b880 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -723,7 +723,7 @@ function gen_g(flags::String, width::Int, precision::Int, c::Char) # need to compute value before left-padding since trailing zeros are elided push!(blk.args, :(tmpout = IOBuffer())) push!(blk.args, :(print_fixed(tmpout,fprec,pt,len,$('#' in flags)))) - push!(blk.args, :(tmpstr = takebuf_string(tmpout))) + push!(blk.args, :(tmpstr = String(take!(tmpout)))) push!(blk.args, :(width -= length(tmpstr))) if '+' in flags || ' ' in flags push!(blk.args, :(width -= 1)) @@ -1111,7 +1111,7 @@ function bigfloat_printf(out, d, flags::String, width::Int, precision::Int, c::C write(fmt, 'R') write(fmt, c) write(fmt, UInt8(0)) - printf_fmt = takebuf_array(fmt) + printf_fmt = take!(fmt) @assert length(printf_fmt) == fmt_len bufsiz = length(DIGITS) - 1 lng = ccall((:mpfr_snprintf,:libmpfr), Int32, (Ptr{UInt8}, Culong, Ptr{UInt8}, Ptr{BigFloat}...), DIGITS, bufsiz, printf_fmt, &d) @@ -1221,7 +1221,7 @@ macro sprintf(args...) isa(args[1], AbstractString) || is_str_expr(args[1]) || throw(ArgumentError("@sprintf: first argument must be a format string")) letexpr = _printf("@sprintf", :(IOBuffer()), args[1], args[2:end]) - push!(letexpr.args[1].args, :(takebuf_string(out))) + push!(letexpr.args[1].args, :(String(take!(out)))) letexpr end diff --git a/base/replutil.jl b/base/replutil.jl index 978b3946d33794..09c99d1ba9bd44 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -553,7 +553,7 @@ function show_method_candidates(io::IO, ex::MethodError, kwargs::Vector=Any[]) break end i += 1 - print(io, takebuf_string(line[1])) + print(io, String(take!(line[1]))) end end end diff --git a/base/stream.jl b/base/stream.jl index c8d39e443943a3..1153ab3cb43eb4 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -696,7 +696,7 @@ end function read(stream::LibuvStream) wait_readnb(stream, typemax(Int)) - return takebuf_array(stream.buffer) + return take!(stream.buffer) end function unsafe_read(s::LibuvStream, p::Ptr{UInt8}, nb::UInt) @@ -741,7 +741,7 @@ function readavailable(this::LibuvStream) wait_readnb(this, 1) buf = this.buffer @assert buf.seekable == false - return takebuf_array(buf) + return take!(buf) end function readuntil(this::LibuvStream, c::UInt8) @@ -801,7 +801,7 @@ function flush(s::LibuvStream) end buf = get(s.sendbuf) if nb_available(buf) > 0 - arr = takebuf_array(buf) # Array of UInt8s + arr = take!(buf) # Array of UInt8s uv_write(s, arr) end return diff --git a/base/strings/basic.jl b/base/strings/basic.jl index d2a49641db6a20..1ac5660378cdc3 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -442,7 +442,7 @@ function map(f, s::AbstractString) end write(out, c2::Char) end - String(takebuf_array(out)) + String(take!(out)) end function filter(f, s::AbstractString) @@ -453,5 +453,5 @@ function filter(f, s::AbstractString) write(out, c) end end - takebuf_string(out) + String(take!(out)) end diff --git a/base/strings/io.jl b/base/strings/io.jl index a99cf403309f7c..8879a0b28c43d7 100644 --- a/base/strings/io.jl +++ b/base/strings/io.jl @@ -126,7 +126,7 @@ Create a string from any value using the [`showall`](:func:`showall`) function. function repr(x) s = IOBuffer() showall(s, x) - takebuf_string(s) + String(take!(s)) end # IOBuffer views of a (byte)string: @@ -397,7 +397,7 @@ function unindent(str::AbstractString, indent::Int; tabwidth=8) write(buf, ' ') end end - takebuf_string(buf) + String(take!(buf)) end function convert(::Type{String}, chars::AbstractVector{Char}) diff --git a/base/strings/util.jl b/base/strings/util.jl index 0b8cb08b9f2454..4c866f0efeb2f0 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -358,7 +358,7 @@ function replace(str::String, pattern, repl, limit::Integer) n += 1 end write(out, SubString(str,i)) - takebuf_string(out) + String(take!(out)) end """ diff --git a/base/util.jl b/base/util.jl index b21a58654e298a..32a3300fe8a132 100644 --- a/base/util.jl +++ b/base/util.jl @@ -309,7 +309,7 @@ function with_output_color(f::Function, color::Union{Int, Symbol}, io::IO, args. try f(IOContext(buf, io), args...) finally have_color && print(buf, color_normal) - print(io, takebuf_string(buf)) + print(io, String(take!(buf))) end end diff --git a/doc/genstdlib.jl b/doc/genstdlib.jl index 9be91f56c5a439..a0a671763dd5b2 100644 --- a/doc/genstdlib.jl +++ b/doc/genstdlib.jl @@ -150,7 +150,7 @@ function getdoc(state::State, file::AbstractString, input::Vector) println(b, line[(n + 1):end]) end # The signature may contain `\` characaters, which must be unescaped. - signature = unescape_string(rstrip(takebuf_string(b))) + signature = unescape_string(rstrip(String(take!(b)))) # Splice the correct docstring into the output after the signature. if haskey(state.validdocs, signature) # Push the rst text for the docstring into the output. @@ -189,7 +189,7 @@ function indent(str::AbstractString, indent = 4) for line in split(str, '\n') println(buf, " "^indent, line) end - takebuf_string(buf) + String(take!(buf)) end function validdocstr(markdown::Base.Markdown.MD) diff --git a/doc/stdlib/io-network.rst b/doc/stdlib/io-network.rst index 9f91cd4f3e75d4..9ec16bd7b96aab 100644 --- a/doc/stdlib/io-network.rst +++ b/doc/stdlib/io-network.rst @@ -97,18 +97,12 @@ General I/O Create an ``IOBuffer``\ , which may optionally operate on a pre-existing array. If the readable/writable arguments are given, they restrict whether or not the buffer may be read from or written to respectively. By default the buffer is readable but not writable. The last argument optionally specifies a size beyond which the buffer may not be grown. -.. function:: takebuf_array(b::IOBuffer) +.. function:: take!(b::IOBuffer) .. Docstring generated from Julia source Obtain the contents of an ``IOBuffer`` as an array, without copying. Afterwards, the ``IOBuffer`` is reset to its initial state. -.. function:: takebuf_string(b::IOBuffer) - - .. Docstring generated from Julia source - - Obtain the contents of an ``IOBuffer`` as a string, without copying. Afterwards, the ``IOBuffer`` is reset to its initial state. - .. function:: fdio([name::AbstractString, ]fd::Integer[, own::Bool=false]) -> IOStream .. Docstring generated from Julia source diff --git a/src/dump.c b/src/dump.c index d9e5414163a2ef..1acde727d2760f 100644 --- a/src/dump.c +++ b/src/dump.c @@ -2372,7 +2372,7 @@ JL_DLLEXPORT jl_array_t *jl_compress_ast(jl_method_t *m, jl_array_t *ast) //jl_printf(JL_STDERR, "%d bytes, %d values\n", dest.size, vals->length); - jl_array_t *v = jl_takebuf_array(&dest); + jl_array_t *v = jl_take_buffer(&dest); if (jl_array_len(m->roots) == 0) { m->roots = NULL; } diff --git a/src/flisp/iostream.c b/src/flisp/iostream.c index 015c150aec9fe9..efcbd024f3ccf3 100644 --- a/src/flisp/iostream.c +++ b/src/flisp/iostream.c @@ -382,7 +382,7 @@ value_t stream_to_string(fl_context_t *fl_ctx, value_t *ps) ios_trunc(st, 0); } else { - char *b = ios_takebuf(st, &n); n--; + char *b = ios_take_buffer(st, &n); n--; b[n] = '\0'; str = cvalue_from_ref(fl_ctx, fl_ctx->stringtype, b, n, fl_ctx->NIL); cv_autorelease(fl_ctx, (cvalue_t*)ptr(str)); diff --git a/src/julia.h b/src/julia.h index 7619a5e0632dd5..29146e1456668b 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1584,8 +1584,7 @@ JL_DLLEXPORT int jl_tcp_bind(uv_tcp_t *handle, uint16_t port, uint32_t host, JL_DLLEXPORT int jl_sizeof_ios_t(void); -JL_DLLEXPORT jl_array_t *jl_takebuf_array(ios_t *s); -JL_DLLEXPORT jl_value_t *jl_takebuf_string(ios_t *s); +JL_DLLEXPORT jl_array_t *jl_take_buffer(ios_t *s); JL_DLLEXPORT void *jl_takebuf_raw(ios_t *s); JL_DLLEXPORT jl_value_t *jl_readuntil(ios_t *s, uint8_t delim); diff --git a/src/support/ios.c b/src/support/ios.c index 385a24258bfebd..650a8690c08883 100644 --- a/src/support/ios.c +++ b/src/support/ios.c @@ -683,7 +683,7 @@ static void _buf_init(ios_t *s, bufmode_t bm) s->size = s->bpos = 0; } -char *ios_takebuf(ios_t *s, size_t *psize) +char *ios_take_buffer(ios_t *s, size_t *psize) { char *buf; @@ -1137,7 +1137,7 @@ char *ios_readline(ios_t *s) ios_mem(&dest, 0); ios_copyuntil(&dest, s, '\n'); size_t n; - return ios_takebuf(&dest, &n); + return ios_take_buffer(&dest, &n); } extern int vasprintf(char **strp, const char *fmt, va_list ap); diff --git a/src/support/ios.h b/src/support/ios.h index 7f86dcac4133ed..6acd52fb018382 100644 --- a/src/support/ios.h +++ b/src/support/ios.h @@ -85,7 +85,7 @@ JL_DLLEXPORT int ios_eof_blocking(ios_t *s); JL_DLLEXPORT int ios_flush(ios_t *s); JL_DLLEXPORT void ios_close(ios_t *s); JL_DLLEXPORT int ios_isopen(ios_t *s); -JL_DLLEXPORT char *ios_takebuf(ios_t *s, size_t *psize); // release buffer to caller +JL_DLLEXPORT char *ios_take_buffer(ios_t *s, size_t *psize); // release buffer to caller // set buffer space to use JL_DLLEXPORT int ios_setbuf(ios_t *s, char *buf, size_t size, int own); JL_DLLEXPORT int ios_bufmode(ios_t *s, bufmode_t mode); diff --git a/src/sys.c b/src/sys.c index d842c921f9fce0..c2c23803ac71c0 100644 --- a/src/sys.c +++ b/src/sys.c @@ -233,7 +233,7 @@ JL_DLLEXPORT double jl_stat_ctime(char *statbuf) // --- buffer manipulation --- -JL_DLLEXPORT jl_array_t *jl_takebuf_array(ios_t *s) +JL_DLLEXPORT jl_array_t *jl_take_buffer(ios_t *s) { size_t n; jl_array_t *a; @@ -244,21 +244,12 @@ JL_DLLEXPORT jl_array_t *jl_takebuf_array(ios_t *s) ios_trunc(s, 0); } else { - char *b = ios_takebuf(s, &n); + char *b = ios_take_buffer(s, &n); a = jl_ptr_to_array_1d(jl_array_uint8_type, b, n-1, 1); } return a; } -JL_DLLEXPORT jl_value_t *jl_takebuf_string(ios_t *s) -{ - jl_array_t *a = jl_takebuf_array(s); - JL_GC_PUSH1(&a); - jl_value_t *str = jl_array_to_string(a); - JL_GC_POP(); - return str; -} - // the returned buffer must be manually freed. To determine the size, // call position(s) before using this function. JL_DLLEXPORT void *jl_takebuf_raw(ios_t *s) @@ -286,7 +277,7 @@ JL_DLLEXPORT jl_value_t *jl_readuntil(ios_t *s, uint8_t delim) ios_setbuf(&dest, (char*)a->data, 80, 0); size_t n = ios_copyuntil(&dest, s, delim); if (dest.buf != a->data) { - a = jl_takebuf_array(&dest); + a = jl_take_buffer(&dest); } else { #ifdef STORE_ARRAY_LEN diff --git a/test/ambiguous.jl b/test/ambiguous.jl index 834f4c2b4f5ff0..299cdfd7f3b676 100644 --- a/test/ambiguous.jl +++ b/test/ambiguous.jl @@ -55,7 +55,7 @@ let err = try end io = IOBuffer() Base.showerror(io, err) - lines = split(takebuf_string(io), '\n') + lines = split(String(take!(io)), '\n') ambig_checkline(str) = startswith(str, " ambig(x, y::Integer) in $curmod_str at") || startswith(str, " ambig(x::Integer, y) in $curmod_str at") @test ambig_checkline(lines[2]) diff --git a/test/asmvariant.jl b/test/asmvariant.jl index dcc5f26c1573c3..bf1b9116d37e09 100644 --- a/test/asmvariant.jl +++ b/test/asmvariant.jl @@ -15,18 +15,18 @@ if Sys.ARCH === :x86_64 || ismatch(ix86, string(Sys.ARCH)) output="" #test that the string output is at&t syntax by checking for occurrences of '%'s code_native(buf,linear_foo,(),:att) - output=takebuf_string(buf) + output=String(take!(buf)) @test ismatch(rgx,output) #test that the code output is intel syntax by checking it has no occurrences of '%' code_native(buf,linear_foo,(),:intel) - output=takebuf_string(buf) + output=String(take!(buf)) @test !(ismatch(rgx,output)) code_native(buf,linear_foo,()) - output=takebuf_string(buf) + output=String(take!(buf)) @test ismatch(rgx, output) end diff --git a/test/broadcast.jl b/test/broadcast.jl index 9e1db315d8683f..21cee3fed274a3 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -315,7 +315,7 @@ let f17314 = x -> x < 0 ? false : x end let io = IOBuffer() broadcast(x->print(io,x), 1:5) # broadcast with side effects - @test takebuf_array(io) == [0x31,0x32,0x33,0x34,0x35] + @test take!(io) == [0x31,0x32,0x33,0x34,0x35] end # Issue 18176 diff --git a/test/datafmt.jl b/test/datafmt.jl index 4b97da3a32ef3b..4b29e876380ce5 100644 --- a/test/datafmt.jl +++ b/test/datafmt.jl @@ -117,10 +117,10 @@ end let x = ["\"hello\"", "world\""], io = IOBuffer() writedlm(io, x, quotes=false) - @test takebuf_string(io) == "\"hello\"\nworld\"\n" + @test String(take!(io)) == "\"hello\"\nworld\"\n" writedlm(io, x) - @test takebuf_string(io) == "\"\"\"hello\"\"\"\n\"world\"\"\"\n" + @test String(take!(io)) == "\"\"\"hello\"\"\"\n\"world\"\"\"\n" end # test comments diff --git a/test/dict.jl b/test/dict.jl index 8725f781cefc6a..b613013b85c1a7 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -270,7 +270,7 @@ for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"), s = IOBuffer() io = Base.IOContext(s, limit=true, displaysize=(rows, cols)) Base.show(io, MIME("text/plain"), d) - out = split(takebuf_string(s),'\n') + out = split(String(take!(s)),'\n') for line in out[2:end] @test strwidth(line) <= cols end @@ -280,7 +280,7 @@ for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"), s = IOBuffer() io = Base.IOContext(s, limit=true, displaysize=(rows, cols)) Base.show(io, MIME("text/plain"), f(d)) - out = split(takebuf_string(s),'\n') + out = split(String(take!(s)),'\n') for line in out[2:end] @test strwidth(line) <= cols end diff --git a/test/docs.jl b/test/docs.jl index 2e73ceffce74a6..33de105b5e665a 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -12,7 +12,7 @@ function docstrings_equal(d1, d2) io2 = IOBuffer() show(io1, MIME"text/markdown"(), d1) show(io2, MIME"text/markdown"(), d2) - takebuf_string(io1) == takebuf_string(io2) + String(take!(io1)) == String(take!(io2)) end docstrings_equal(d1::DocStr, d2) = docstrings_equal(parsedoc(d1), d2) @@ -21,7 +21,7 @@ function docstring_startswith(d1, d2) io2 = IOBuffer() show(io1, MIME"text/markdown"(), d1) show(io2, MIME"text/markdown"(), d2) - startswith(takebuf_string(io1), takebuf_string(io2)) + startswith(String(take!(io1)), String(take!(io2))) end docstring_startswith(d1::DocStr, d2) = docstring_startswith(parsedoc(d1), d2) @@ -783,7 +783,7 @@ three :: Float64 let d = @doc Undocumented.f io = IOBuffer() show(io, MIME"text/markdown"(), d) - @test startswith(takebuf_string(io),""" + @test startswith(String(take!(io)),""" No documentation found. `$(curmod_prefix)Undocumented.f` is a `Function`. @@ -793,7 +793,7 @@ end let d = @doc Undocumented.undocumented io = IOBuffer() show(io, MIME"text/markdown"(), d) - @test startswith(takebuf_string(io), """ + @test startswith(String(take!(io)), """ No documentation found. `$(curmod_prefix)Undocumented.undocumented` is a `Function`. diff --git a/test/env.jl b/test/env.jl index 030fe3cf9b5903..86eb0ba9b89c61 100644 --- a/test/env.jl +++ b/test/env.jl @@ -46,7 +46,7 @@ withenv(k1=>k1, k2=>k2) do @test b_k1 && b_k2 io = IOBuffer() show(io, ENV) - s = takebuf_string(io) + s = String(take!(io)) @test contains(s, "$k1=$k1") @test contains(s, "$k2=$k2") diff --git a/test/file.jl b/test/file.jl index 67b566f7533277..ce9a885ddbd014 100644 --- a/test/file.jl +++ b/test/file.jl @@ -22,7 +22,7 @@ let err = nothing catch err io = IOBuffer() showerror(io, err) - @test startswith(takebuf_string(io), "SystemError (with $file): mkdir:") + @test startswith(String(take!(io)), "SystemError (with $file): mkdir:") end end diff --git a/test/functional.jl b/test/functional.jl index 91da29567333ce..170ebb84c4d7cb 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -16,7 +16,7 @@ end # map on ranges should evaluate first value only once (#4453) let io=IOBuffer(3) map(x->print(io,x), 1:2) - @test takebuf_string(io)=="12" + @test String(take!(io))=="12" end # map over Bottom[] should return Bottom[] diff --git a/test/iobuffer.jl b/test/iobuffer.jl index 1f6d3c62d249b7..8792e3c5928a9b 100644 --- a/test/iobuffer.jl +++ b/test/iobuffer.jl @@ -37,8 +37,8 @@ io.readable = false @test_throws ArgumentError read!(io,UInt8[0]) truncate(io, 0) @test write(io,"boston\ncambridge\n") > 0 -@test takebuf_string(io) == "boston\ncambridge\n" -@test takebuf_string(io) == "" +@test String(take!(io)) == "boston\ncambridge\n" +@test String(take!(io)) == "" @test write(io, Complex{Float64}(0)) == 16 @test write(io, Rational{Int64}(1//2)) == 16 close(io) @@ -57,8 +57,8 @@ seek(io,0) @test_throws ArgumentError truncate(io,0) @test_throws ArgumentError write(io,UInt8(0)) @test_throws ArgumentError write(io,UInt8[0]) -@test takebuf_string(io) == "hamster\nguinea pig\nturtle" -@test takebuf_string(io) == "hamster\nguinea pig\nturtle" #should be unchanged +@test String(take!(io)) == "hamster\nguinea pig\nturtle" +@test String(take!(io)) == "hamster\nguinea pig\nturtle" #should be unchanged close(io) end @@ -118,8 +118,8 @@ write(io,'e') @test length(io.data) == 75 @test position(io) == 0 skip(io,72) -@test takebuf_string(io) == "\0ab" -@test takebuf_string(io) == "" +@test String(take!(io)) == "\0ab" +@test String(take!(io)) == "" # issues 4021 print(io, true) @@ -166,13 +166,13 @@ let io=IOBuffer(SubString("***αhelloworldω***",4,16)), io2 = IOBuffer(b"goodni @test readstring(io) == "dω" @test String(io) == "αhelloworldω" @test_throws ArgumentError write(io,"!") - @test takebuf_array(io) == b"αhelloworldω" + @test take!(io) == b"αhelloworldω" seek(io, 2) seekend(io2) write(io2, io) @test readstring(io) == "" @test readstring(io2) == "" - @test takebuf_string(io) == "αhelloworldω" + @test String(take!(io)) == "αhelloworldω" seek(io2, 0) truncate(io2, io2.size - 2) @test readstring(io2) == "goodnightmoonhelloworld" diff --git a/test/misc.jl b/test/misc.jl index 250ea56b675576..8364a8762987f5 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -468,7 +468,7 @@ let eval(Base, :(have_color = true)) buf = IOBuffer() print_with_color(:red, buf, "foo") - @test startswith(takebuf_string(buf), Base.text_colors[:red]) + @test startswith(String(take!(buf)), Base.text_colors[:red]) finally eval(Base, :(have_color = $(old_have_color))) end diff --git a/test/nullable.jl b/test/nullable.jl index 5ab29f1f8d9421..f79040674e22f3 100644 --- a/test/nullable.jl +++ b/test/nullable.jl @@ -83,24 +83,24 @@ for (i, T) in enumerate(types) x2 = Nullable(zero(T)) x3 = Nullable(one(T)) show(io1, x1) - @test takebuf_string(io1) == @sprintf("Nullable{%s}()", T) + @test String(take!(io1)) == @sprintf("Nullable{%s}()", T) show(io1, x2) showcompact(io2, get(x2)) - @test takebuf_string(io1) == @sprintf("Nullable{%s}(%s)", T, takebuf_string(io2)) + @test String(take!(io1)) == @sprintf("Nullable{%s}(%s)", T, String(take!(io2))) show(io1, x3) showcompact(io2, get(x3)) - @test takebuf_string(io1) == @sprintf("Nullable{%s}(%s)", T, takebuf_string(io2)) + @test String(take!(io1)) == @sprintf("Nullable{%s}(%s)", T, String(take!(io2))) a1 = [x2] show(IOContext(io1, compact=false), a1) show(IOContext(io2, compact=false), x2) - @test takebuf_string(io1) == - @sprintf("Nullable{%s}[%s]", string(T), takebuf_string(io2)) + @test String(take!(io1)) == + @sprintf("Nullable{%s}[%s]", string(T), String(take!(io2))) show(io1, a1) show(IOContext(io2, compact=true), x2) - @test takebuf_string(io1) == - @sprintf("Nullable{%s}[%s]", string(T), takebuf_string(io2)) + @test String(take!(io1)) == + @sprintf("Nullable{%s}[%s]", string(T), String(take!(io2))) end module NullableTestEnum @@ -110,8 +110,7 @@ const curmod_prefix = "$(["$m." for m in curmod_name]...)" io = IOBuffer() @enum TestEnum a b show(io, Nullable(a)) -Base.Test.@test takebuf_string(io) == "Nullable{$(curmod_prefix)TestEnum}(a)" -end +Base.Test.@test String(take!(io)) == "Nullable{$(curmod_prefix)TestEnum}(a)" # showcompact(io::IO, x::Nullable) io1 = IOBuffer() @@ -121,19 +120,19 @@ for (i, T) in enumerate(types) x2 = Nullable(zero(T)) x3 = Nullable(one(T)) showcompact(io1, x1) - @test takebuf_string(io1) == "#NULL" + @test String(take!(io1)) == "#NULL" showcompact(io1, x2) showcompact(io2, get(x2)) - @test takebuf_string(io1) == takebuf_string(io2) + @test String(take!(io1)) == String(take!(io2)) showcompact(io1, x3) showcompact(io2, get(x3)) - @test takebuf_string(io1) == takebuf_string(io2) + @test String(take!(io1)) == String(take!(io2)) a1 = [x2] showcompact(io1, a1) showcompact(io2, x2) - @test takebuf_string(io1) == - @sprintf("Nullable{%s}[%s]", string(T), takebuf_string(io2)) + @test String(take!(io1)) == + @sprintf("Nullable{%s}[%s]", string(T), String(take!(io2))) end # get(x::Nullable) diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 254e2caaac0ee9..5698aa34cef0f2 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -117,33 +117,33 @@ end # show io = IOBuffer() show(io, v) -str = takebuf_string(io) +str = String(take!(io)) show(io, v0) -@test str == takebuf_string(io) +@test str == String(take!(io)) show(io, A) -str = takebuf_string(io) +str = String(take!(io)) @test str == "[1 3; 2 4]" show(io, S) -str = takebuf_string(io) +str = String(take!(io)) @test str == "[1 3; 2 4]" show(io, MIME("text/plain"), A) -strs = split(strip(takebuf_string(io)), '\n') +strs = split(strip(String(take!(io))), '\n') @test strs[2] == " 1 3" @test strs[3] == " 2 4" v = OffsetArray(rand(3), (-2,)) show(io, v) -str = takebuf_string(io) +str = String(take!(io)) show(io, parent(v)) -@test str == takebuf_string(io) +@test str == String(take!(io)) smry = summary(v) @test contains(smry, "OffsetArray{Float64,1") @test contains(smry, "with indices -1:1") function cmp_showf(printfunc, io, A) ioc = IOContext(io, limit=true, compact=true) printfunc(ioc, A) - str1 = takebuf_string(io) + str1 = String(take!(io)) printfunc(ioc, parent(A)) - str2 = takebuf_string(io) + str2 = String(take!(io)) @test str1 == str2 end cmp_showf(Base.print_matrix, io, OffsetArray(rand(5,5), (10,-9))) # rows&cols fit @@ -163,9 +163,9 @@ targets2 = ["(1.0,1.0)", for n = 0:4 a = OffsetArray(ones(Float64,ntuple(d->1,n)), ntuple(identity,n)) show(IOContext(io, limit=true), MIME("text/plain"), a) - @test takebuf_string(io) == targets1[n+1] + @test String(take!(io)) == targets1[n+1] show(IOContext(io, limit=true), MIME("text/plain"), (a,a)) - @test takebuf_string(io) == targets2[n+1] + @test String(take!(io)) == targets2[n+1] end # Similar diff --git a/test/pkg.jl b/test/pkg.jl index 1b47ed74c3707d..92530cd9cc1d82 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -112,17 +112,17 @@ temp_pkg_dir() do iob = IOBuffer() Pkg.checkout("Example") Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) + str = chomp(String(take!(iob))) @test startswith(str, " - Example") @test endswith(str, "master") Pkg.free("Example") Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) + str = chomp(String(take!(iob))) @test endswith(str, string(Pkg.installed("Example"))) Pkg.checkout("Example") Pkg.free(("Example",)) Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) + str = chomp(String(take!(iob))) @test endswith(str, string(Pkg.installed("Example"))) Pkg.rm("Example") @test isempty(Pkg.installed()) @@ -135,17 +135,17 @@ temp_pkg_dir() do Pkg.clone("https://github.com/JuliaLang/Example.jl.git") @test [keys(Pkg.installed())...] == ["Example"] Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) + str = chomp(String(take!(iob))) @test startswith(str, " - Example") @test endswith(str, "master") Pkg.free("Example") Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) + str = chomp(String(take!(iob))) @test endswith(str, string(Pkg.installed("Example"))) Pkg.checkout("Example") Pkg.free(("Example",)) Pkg.status("Example", iob) - str = chomp(takebuf_string(iob)) + str = chomp(String(take!(iob))) @test endswith(str, string(Pkg.installed("Example"))) @test isempty(Pkg.dependents("Example")) diff --git a/test/profile.jl b/test/profile.jl index 6358b65e3c5d47..f9a731c1c54277 100644 --- a/test/profile.jl +++ b/test/profile.jl @@ -13,22 +13,22 @@ Profile.clear() @profile busywait(1, 20) let iobuf = IOBuffer() Profile.print(iobuf, format=:tree, C=true) - str = takebuf_string(iobuf) + str = String(take!(iobuf)) @test !isempty(str) truncate(iobuf, 0) Profile.print(iobuf, format=:tree, maxdepth=2) - str = takebuf_string(iobuf) + str = String(take!(iobuf)) @test !isempty(str) truncate(iobuf, 0) Profile.print(iobuf, format=:flat, C=true) - str = takebuf_string(iobuf) + str = String(take!(iobuf)) @test !isempty(str) truncate(iobuf, 0) Profile.print(iobuf) - @test !isempty(takebuf_string(iobuf)) + @test !isempty(String(take!(iobuf))) truncate(iobuf, 0) Profile.print(iobuf, format=:flat, sortedby=:count) - @test !isempty(takebuf_string(iobuf)) + @test !isempty(String(take!(iobuf))) Profile.clear() @test isempty(Profile.fetch()) end diff --git a/test/ranges.jl b/test/ranges.jl index 0b0c10cd81b5c3..425ac8aa50d668 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -566,7 +566,7 @@ end # Issue #11245 let io = IOBuffer() show(io, linspace(1, 2, 3)) - str = takebuf_string(io) + str = String(take!(io)) @test str == "linspace(1.0,2.0,3)" end @@ -784,5 +784,5 @@ r2 = Base.OneTo(7) @test findin(2:length(r2)-1, r2) === 1:length(r2)-2 io = IOBuffer() show(io, r) -str = takebuf_string(io) +str = String(take!(io)) @test str == "Base.OneTo(3)" diff --git a/test/read.jl b/test/read.jl index ac73232b8fcd00..d753c8bdd33b25 100644 --- a/test/read.jl +++ b/test/read.jl @@ -298,7 +298,7 @@ for (name, f) in l verbose && println("$name write(::IOBuffer, ...)") to = IOBuffer(copy(text.data), false, true) write(to, io()) - @test takebuf_string(to) == text + @test String(take!(to)) == text cleanup() end diff --git a/test/reflection.jl b/test/reflection.jl index 5b1d4600984f0c..28ddb97d2f0639 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -15,7 +15,7 @@ end function test_bin_reflection(freflect, f, types) iob = IOBuffer() freflect(iob, f, types) - str = takebuf_string(iob) + str = String(take!(iob)) @test !isempty(str) nothing end @@ -60,7 +60,7 @@ using Base.Test function warntype_hastag(f, types, tag) iob = IOBuffer() code_warntype(iob, f, types) - str = takebuf_string(iob) + str = String(take!(iob)) return !isempty(search(str, tag)) end @@ -89,7 +89,7 @@ tag = Base.have_color ? Base.text_colors[:red] : "ARRAY{FLOAT64,N}" tag = Base.have_color ? Base.text_colors[:red] : "ANY" iob = IOBuffer() show(iob, expand(:(x->x^2))) -str = takebuf_string(iob) +str = String(take!(iob)) @test isempty(search(str, tag)) module ImportIntrinsics15819 diff --git a/test/repl.jl b/test/repl.jl index 41ccb5df3ed6a7..95fe7e3e8cc0e5 100644 --- a/test/repl.jl +++ b/test/repl.jl @@ -484,7 +484,7 @@ if !is_windows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER if !ok LineEdit.transition(s,:abort) end - line = strip(takebuf_string(buf)) + line = strip(String(take!(buf))) LineEdit.reset_state(s) return notify(c,line) end @@ -546,5 +546,5 @@ let io = IOBuffer() catch e e end, []) - @test length(takebuf_string(io)) < 1500 + @test length(String(take!(io))) < 1500 end diff --git a/test/replutil.jl b/test/replutil.jl index 30f8c4c725edca..654c099d6a7e9e 100644 --- a/test/replutil.jl +++ b/test/replutil.jl @@ -7,9 +7,9 @@ const curmod_prefix = "$(["$m." for m in curmod_name]...)" function test_have_color(buf, color, no_color) if Base.have_color - @test takebuf_string(buf) == color + @test String(take!(buf)) == color else - @test takebuf_string(buf) == no_color + @test String(take!(buf)) == no_color end end @@ -43,7 +43,7 @@ test_have_color(buf, "", "") # matches the implicit constructor -> convert method Base.show_method_candidates(buf, Base.MethodError(Tuple{}, (1, 1, 1))) -let mc = takebuf_string(buf) +let mc = String(take!(buf)) @test contains(mc, "\nClosest candidates are:\n Tuple{}{T}(") @test !contains(mc, cfile) end @@ -114,10 +114,10 @@ method_c6(; x=1) = x method_c6(a; y=1) = y m_error = try method_c6(y=1) catch e; e; end showerror(buf, m_error) -error_out = takebuf_string(buf) +error_out = String(take!(buf)) m_error = try method_c6(1, x=1) catch e; e; end showerror(buf, m_error) -error_out1 = takebuf_string(buf) +error_out1 = String(take!(buf)) c6mline = @__LINE__ module TestKWError @@ -126,10 +126,10 @@ method_c6_in_module(a; y=1) = y end m_error = try TestKWError.method_c6_in_module(y=1) catch e; e; end showerror(buf, m_error) -error_out2 = takebuf_string(buf) +error_out2 = String(take!(buf)) m_error = try TestKWError.method_c6_in_module(1, x=1) catch e; e; end showerror(buf, m_error) -error_out3 = takebuf_string(buf) +error_out3 = String(take!(buf)) if Base.have_color @test contains(error_out, "method_c6(; x)$cfile$(c6line + 1)\e[1m\e[31m got unsupported keyword argument \"y\"\e[0m") @@ -175,9 +175,9 @@ macro except_str(expr, err_type) end err === nothing && error("expected failure, but no exception thrown") @test typeof(err) === $(esc(err_type)) - buff = IOBuffer() - showerror(buff, err) - takebuf_string(buff) + buf = IOBuffer() + showerror(buf, err) + String(take!(buf)) end end end @@ -191,9 +191,9 @@ macro except_strbt(expr, err_type) end err === nothing && error("expected failure, but no exception thrown") @test typeof(err) === $(esc(err_type)) - buff = IOBuffer() - showerror(buff, err, catch_backtrace()) - takebuf_string(buff) + buf = IOBuffer() + showerror(buf, err, catch_backtrace()) + String(take!(buf)) end end end @@ -311,11 +311,11 @@ end # issue 11845 let - buff = IOBuffer() - showerror(buff, MethodError(convert, (3, 1.0))) - showerror(buff, MethodError(convert, (Int, 1.0))) - showerror(buff, MethodError(convert, Tuple{Type, Float64})) - showerror(buff, MethodError(convert, Tuple{DataType, Float64})) + buf = IOBuffer() + showerror(buf, MethodError(convert, (3, 1.0))) + showerror(buf, MethodError(convert, (Int, 1.0))) + showerror(buf, MethodError(convert, Tuple{Type, Float64})) + showerror(buf, MethodError(convert, Tuple{DataType, Float64})) end # Issue #14884 diff --git a/test/serialize.jl b/test/serialize.jl index 0a805e3a37df29..18218720d08452 100644 --- a/test/serialize.jl +++ b/test/serialize.jl @@ -16,17 +16,17 @@ end # Tags create_serialization_stream() do s Serializer.writetag(s, Serializer.sertag(Bool)) - @test takebuf_array(s)[end] == UInt8(Serializer.sertag(Bool)) + @test take!(s)[end] == UInt8(Serializer.sertag(Bool)) end create_serialization_stream() do s Serializer.write_as_tag(s, Serializer.sertag(Bool)) - @test takebuf_array(s)[end] == UInt8(Serializer.sertag(Bool)) + @test take!(s)[end] == UInt8(Serializer.sertag(Bool)) end create_serialization_stream() do s Serializer.write_as_tag(s, Serializer.sertag(Symbol)) - data = takebuf_array(s) + data = take!(s) @test data[end-1] == 0x00 @test data[end] == UInt8(Serializer.sertag(Symbol)) end @@ -387,7 +387,7 @@ end using .Shell, .Instance1 io = IOBuffer() serialize(io, foo) -str = takebuf_string(io) +str = String(take!(io)) @test isempty(search(str, "Instance1")) @test !isempty(search(str, "Shell")) diff --git a/test/show.jl b/test/show.jl index 20e944646f667a..8b139da81e7b01 100644 --- a/test/show.jl +++ b/test/show.jl @@ -365,7 +365,7 @@ function f13127() buf = IOBuffer() f() = 1 show(buf, f) - takebuf_string(buf) + String(take!(buf)) end @test f13127() == "$(curmod_prefix)f" @@ -468,7 +468,7 @@ function test_mt(f, str) defs = first(mt) io = IOBuffer() show(io, defs) - strio = takebuf_string(io) + strio = String(take!(io)) strio = split(strio, " at")[1] @test strio[1:length(str)] == str end @@ -521,9 +521,9 @@ end let io = IOBuffer() x = [1, 2] showcompact(io, x) - @test takebuf_string(io) == "[1,2]" + @test String(take!(io)) == "[1,2]" showcompact(IOContext(io, :compact=>true), x) - @test takebuf_string(io) == "[1,2]" + @test String(take!(io)) == "[1,2]" end # PR 17117 diff --git a/test/staged.jl b/test/staged.jl index d806300ccd5b9b..3a763891f9e1cc 100644 --- a/test/staged.jl +++ b/test/staged.jl @@ -31,29 +31,29 @@ end const intstr = @sprintf("%s", Int) splat2(1) -@test takebuf_string(stagediobuf) == "($intstr,)" +@test String(take!(stagediobuf)) == "($intstr,)" splat2(1,3) -@test takebuf_string(stagediobuf) == "($intstr,$intstr)" +@test String(take!(stagediobuf)) == "($intstr,$intstr)" splat2(5,2) -@test takebuf_string(stagediobuf) == "" +@test String(take!(stagediobuf)) == "" splat2(1:3,5.2) -@test takebuf_string(stagediobuf) == "(UnitRange{$intstr},Float64)" +@test String(take!(stagediobuf)) == "(UnitRange{$intstr},Float64)" splat2(3,5:2:7) -@test takebuf_string(stagediobuf) == "($intstr,StepRange{$intstr,$intstr})" +@test String(take!(stagediobuf)) == "($intstr,StepRange{$intstr,$intstr})" splat2(1,2,3,4) -@test takebuf_string(stagediobuf) == "($intstr,$intstr,$intstr,$intstr)" +@test String(take!(stagediobuf)) == "($intstr,$intstr,$intstr,$intstr)" splat2(1,2,3) -@test takebuf_string(stagediobuf) == "($intstr,$intstr,$intstr)" +@test String(take!(stagediobuf)) == "($intstr,$intstr,$intstr)" splat2(1:5, 3, 3:3) -@test takebuf_string(stagediobuf) == "(UnitRange{$intstr},$intstr,UnitRange{$intstr})" +@test String(take!(stagediobuf)) == "(UnitRange{$intstr},$intstr,UnitRange{$intstr})" splat2(1:5, 3, 3:3) -@test takebuf_string(stagediobuf) == "" +@test String(take!(stagediobuf)) == "" splat2(1:5, 3:3, 3) -@test takebuf_string(stagediobuf) == "(UnitRange{$intstr},UnitRange{$intstr},$intstr)" +@test String(take!(stagediobuf)) == "(UnitRange{$intstr},UnitRange{$intstr},$intstr)" splat2(1:5, 3:3) -@test takebuf_string(stagediobuf) == "(UnitRange{$intstr},UnitRange{$intstr})" +@test String(take!(stagediobuf)) == "(UnitRange{$intstr},UnitRange{$intstr})" splat2(3, 3:5) -@test takebuf_string(stagediobuf) == "($intstr,UnitRange{$intstr})" +@test String(take!(stagediobuf)) == "($intstr,UnitRange{$intstr})" # varargs specialization with parametric @generated functions (issue #8944) @generated function splat3{T,N}(A::AbstractArray{T,N}, indx::RangeIndex...) @@ -62,9 +62,9 @@ splat2(3, 3:5) end A = rand(5,5,3) splat3(A, 1:2, 1:2, 1) -@test takebuf_string(stagediobuf) == "(UnitRange{$intstr},UnitRange{$intstr},$intstr)" +@test String(take!(stagediobuf)) == "(UnitRange{$intstr},UnitRange{$intstr},$intstr)" splat3(A, 1:2, 1, 1:2) -@test takebuf_string(stagediobuf) == "(UnitRange{$intstr},$intstr,UnitRange{$intstr})" +@test String(take!(stagediobuf)) == "(UnitRange{$intstr},$intstr,UnitRange{$intstr})" B = view(A, 1:3, 2, 1:3) @generated function mygetindex(S::SubArray, indexes::Real...) diff --git a/test/strings/basic.jl b/test/strings/basic.jl index e37371cb48fb4c..b95289f21594b3 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -75,9 +75,9 @@ end let f =IOBuffer(), x = split("1 2 3") @test write(f, x) == 3 - @test takebuf_string(f) == "123" + @test String(take!(f)) == "123" @test invoke(write, Tuple{IO, AbstractArray}, f, x) == 3 - @test takebuf_string(f) == "123" + @test String(take!(f)) == "123" end # issue #7248 diff --git a/test/strings/io.jl b/test/strings/io.jl index 1ab6be0035c442..dee71b655cc187 100644 --- a/test/strings/io.jl +++ b/test/strings/io.jl @@ -161,7 +161,7 @@ arr = ["a","b","c"] # join with empty input myio = IOBuffer() join(myio, "", "", 1) -@test isempty(takebuf_array(myio)) +@test isempty(take!(myio)) # unescape_chars @test Base.unescape_chars("\\t","t") == "t" diff --git a/test/strings/types.jl b/test/strings/types.jl index 10e8ca406682b9..c4584e803323b2 100644 --- a/test/strings/types.jl +++ b/test/strings/types.jl @@ -52,7 +52,7 @@ u = SubString(str, 3, 6) @test length(u)==2 b = IOBuffer() write(b, u) -@test takebuf_string(b) == "\u2200\u2222" +@test String(take!(b)) == "\u2200\u2222" @test_throws ArgumentError SubString(str, 4, 5) @test_throws BoundsError next(u, 0) @@ -70,14 +70,14 @@ u = SubString(str, 4, 3) @test length(u)==0 b = IOBuffer() write(b, u) -@test takebuf_string(b) == "" +@test String(take!(b)) == "" str = "føøbar" u = SubString(str, 10, 10) @test length(u)==0 b = IOBuffer() write(b, u) -@test takebuf_string(b) == "" +@test String(take!(b)) == "" # search and SubString (issue #5679) str = "Hello, world!" diff --git a/test/unicode/UnicodeError.jl b/test/unicode/UnicodeError.jl index 6ec6d0a936ec6f..f342617e9df9a9 100644 --- a/test/unicode/UnicodeError.jl +++ b/test/unicode/UnicodeError.jl @@ -3,5 +3,5 @@ let io = IOBuffer() show(io, UnicodeError(Base.UTF_ERR_SHORT, 1, 10)) check = "UnicodeError: invalid UTF-8 sequence starting at index 1 (0xa missing one or more continuation bytes)" - @test takebuf_string(io) == check + @test String(take!(io)) == check end diff --git a/test/unicode/utf8proc.jl b/test/unicode/utf8proc.jl index 3078f05fce0808..c88cc61632fd3c 100644 --- a/test/unicode/utf8proc.jl +++ b/test/unicode/utf8proc.jl @@ -297,5 +297,5 @@ let str = ascii("This is a test") io = IOBuffer() show(io, g) check = "length-14 GraphemeIterator{String} for \"$str\"" - @test takebuf_string(io) == check + @test String(take!(io)) == check end diff --git a/test/version.jl b/test/version.jl index a89f4efa82a010..34616bc72089aa 100644 --- a/test/version.jl +++ b/test/version.jl @@ -80,7 +80,7 @@ # show io = IOBuffer() show(io,v"4.3.2+1.a") -@test length(takebuf_string(io)) == 12 +@test length(String(take!(io))) == 12 # conversion from Int @test convert(VersionNumber, 2) == v"2.0.0" @@ -225,7 +225,7 @@ import Base.check_new_version import Base.banner io = IOBuffer() @test banner(io) === nothing -@test length(takebuf_string(io)) > 50 +@test length(String(take!(io))) > 50 # julia_version.h version test @test VERSION.major == ccall(:jl_ver_major, Cint, ()) diff --git a/test/workspace.jl b/test/workspace.jl index d4d9c4168158f8..6fe618486a7022 100644 --- a/test/workspace.jl +++ b/test/workspace.jl @@ -10,7 +10,7 @@ LastMain.f(2) # PR #12990 io = IOBuffer() show(io, Pair) -@assert takebuf_string(io) == "Pair{A,B}" +@assert String(take!(io)) == "Pair{A,B}" @assert !Base.inbase(LastMain) """ exename = Base.julia_cmd()