Skip to content

Commit

Permalink
Deprecate takebuf_string() and rename takebuf_array() to take!()
Browse files Browse the repository at this point in the history
takebuf_string(b) is now simply String(take!(b)). Also remove
jl_takebuf_string, which did the same conversion from array to string in C,
and rename {jl,ios}_takebuf_array() to {jl,ios}_take_buffer().
  • Loading branch information
nalimilan committed Nov 15, 2016
1 parent 069f6b0 commit 3c3d186
Show file tree
Hide file tree
Showing 63 changed files with 186 additions and 213 deletions.
6 changes: 3 additions & 3 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/base64.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand Down
2 changes: 1 addition & 1 deletion base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
3 changes: 1 addition & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,7 @@ export
serialize,
skip,
skipchars,
takebuf_array,
takebuf_string,
take!,
truncate,
unmark,
watch_file,
Expand Down
4 changes: 2 additions & 2 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 8 additions & 10 deletions base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions base/markdown/Common/block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base/markdown/GitHub/GitHub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base/markdown/parse/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ 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)
else
write(buffer, read(stream, Char))
end
end
c = takebuf_string(buffer)
c = String(take!(buffer))
!isempty(c) && push!(content, c)
return content
end
Expand Down
4 changes: 2 additions & 2 deletions base/markdown/parse/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,))
Expand Down
6 changes: 3 additions & 3 deletions base/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -453,5 +453,5 @@ function filter(f, s::AbstractString)
write(out, c)
end
end
takebuf_string(out)
String(take!(out))
end
Loading

0 comments on commit 3c3d186

Please sign in to comment.