Skip to content

Commit

Permalink
deprecate String(io::IOBuffer). fixes #21438
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 13, 2017
1 parent 9c1d1b8 commit 47c3fd7
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ Deprecated or removed
* The forms of `read`, `readstring`, and `eachline` that accepted both a `Cmd` object and an
input stream are deprecated. Use e.g. `read(pipeline(stdin, cmd))` instead ([#22762]).

* The method `String(io::IOBuffer)` is deprecated to `String(take!(copy(io)))` ([#21438]).


Julia v0.6.0 Release Notes
==========================
Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,8 @@ end
@deprecate readstring(cmd::AbstractCmd, stdin::Redirectable) readstring(pipeline(stdin, cmd))
@deprecate eachline(cmd::AbstractCmd, stdin; chomp::Bool=true) eachline(pipeline(stdin, cmd), chomp=chomp)

@deprecate String(io::AbstractIOBuffer) String(take!(copy(io)))

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
6 changes: 0 additions & 6 deletions base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,6 @@ end

isopen(io::AbstractIOBuffer) = io.readable || io.writable || io.seekable || nb_available(io) > 0

function String(io::AbstractIOBuffer)
io.readable || throw(ArgumentError("IOBuffer is not readable"))
io.seekable || throw(ArgumentError("IOBuffer is not seekable"))
return unsafe_string(pointer(io.data), io.size)
end

"""
take!(b::IOBuffer)
Expand Down
2 changes: 1 addition & 1 deletion test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ let d = Dict((1=>2) => (3=>45), (3=>10) => (10=>11))

# Check explicitly for the expected strings, since the CPU bitness effects
# dictionary ordering.
result = String(buf)
result = String(take!(buf))
@test contains(result, "Dict")
@test contains(result, "(1=>2)=>(3=>45)")
@test contains(result, "(3=>10)=>(10=>11)")
Expand Down
8 changes: 5 additions & 3 deletions test/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

ioslength(io::IOBuffer) = (io.seekable ? io.size : nb_available(io))

bufcontents(io::AbstractIOBuffer) = unsafe_string(pointer(io.data), io.size)

let io = IOBuffer()
@test eof(io)
@test_throws EOFError read(io,UInt8)
Expand All @@ -17,7 +19,7 @@ seek(io, 0)
a = Array{UInt8}(2)
@test read!(io, a) == a
@test a == UInt8['b','c']
@test String(io) == "abc"
@test bufcontents(io) == "abc"
seek(io, 1)
truncate(io, 2)
@test position(io) == 1
Expand Down Expand Up @@ -178,7 +180,7 @@ let io=IOBuffer(SubString("***αhelloworldω***",4,16)), io2 = IOBuffer(b"goodni
@test_throws EOFError read(io,UInt8)
skip(io, -3)
@test readstring(io) == ""
@test String(io) == "αhelloworldω"
@test bufcontents(io) == "αhelloworldω"
@test_throws ArgumentError write(io,"!")
@test take!(io) == b"αhelloworldω"
seek(io, 2)
Expand All @@ -193,7 +195,7 @@ let io=IOBuffer(SubString("***αhelloworldω***",4,16)), io2 = IOBuffer(b"goodni
seek(io2, 0)
write(io2, io2)
@test readstring(io2) == ""
@test String(io2) == "goodnightmoonhelloworld"
@test bufcontents(io2) == "goodnightmoonhelloworld"
end

# issue #11917
Expand Down
2 changes: 1 addition & 1 deletion test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ function history_move_prefix(s::LineEdit.MIState,
buf = LineEdit.buffer(s)
pos = position(buf)
prefix = REPL.beforecursor(buf)
allbuf = String(buf)
allbuf = String(take!(copy(buf)))
cur_idx = hist.cur_idx
# when searching forward, start at last_idx
if !backwards && hist.last_idx > 0
Expand Down
6 changes: 3 additions & 3 deletions test/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ let d = Dict(1 => 2, 3 => 45)
buf = IOBuffer()
td = TextDisplay(buf)
display(td, d)
result = String(td.io)
result = String(take!(td.io))

@test contains(result, summary(d))

Expand All @@ -466,13 +466,13 @@ let err, buf = IOBuffer()
try Array() catch err end
Base.show_method_candidates(buf,err)
@test isa(err, MethodError)
@test contains(String(buf), "Closest candidates are:")
@test contains(String(take!(buf)), "Closest candidates are:")
end

# Issue 20111
let K20111(x) = y -> x, buf = IOBuffer()
show(buf, methods(K20111(1)))
@test contains(String(buf), " 1 method for generic function")
@test contains(String(take!(buf)), " 1 method for generic function")
end

# @macroexpand tests
Expand Down

0 comments on commit 47c3fd7

Please sign in to comment.