Skip to content

Commit

Permalink
a couple more changes to fix #12829
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 28, 2015
1 parent 462fd6e commit 334a2be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 44 deletions.
5 changes: 5 additions & 0 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,8 @@ function reset{T<:IO}(io::T)
end

ismarked(io::IO) = io.mark >= 0

# Generic IO stubs

lock(::IO) = nothing
unlock(::IO) = nothing
26 changes: 16 additions & 10 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ show(io::IO,stream::TTY) = print(io,"TTY(",uv_status_string(stream),", ",
nb_available(stream.buffer)," bytes waiting)")

function println(io::AsyncStream, xs...)
lock(io.lock)
lock(io)
try
invoke(println, Tuple{IO, map(typeof,xs)...}, io, xs...)
finally
unlock(io.lock)
unlock(io)
end
end

Expand Down Expand Up @@ -543,20 +543,24 @@ show(io::IO,stream::Pipe) = print(io,
uv_status_string(stream.in), " => ",
uv_status_string(stream.out), ", ",
nb_available(stream), " bytes waiting)")
isreadable(io::AbstractPipe) = isreadable(io.out)
iswritable(io::AbstractPipe) = iswritable(io.in)
read{T<:AbstractPipe}(io::T, args...) = read(io.out, args...)
write(io::AbstractPipe, byte::UInt8) = write(io.in, byte)
write(io::AbstractPipe, bytes::Vector{UInt8}) = write(io.in, bytes)
write{T<:AbstractPipe}(io::T, args...) = write(io.in, args...)
write{S<:AbstractPipe,T}(io::S, a::Array{T}) = write(io.in, a)
write{S<:AbstractPipe}(io::S, a::Array) = write(io.in, a)
buffer_or_write(io::AbstractPipe, p::Ptr, n::Integer) = buffer_or_write(io.in, p, n)
println{T<:AbstractPipe}(io::T, args...) = println(io.in, args...)
flush(io::AbstractPipe) = flush(io.in)
buffer_writes(io::AbstractPipe, args...) = buffer_writes(io.in, args...)
read{T<:AbstractPipe}(io::AbstractPipe, args...) = read(io.out, args)
readuntil{T<:AbstractPipe}(io::T, args...) = readuntil(io.out, args...)
flush(io::AbstractPipe) = flush(io.in)

read(io::AbstractPipe, byte::Type{UInt8}) = read(io.out, byte)
read!(io::AbstractPipe, bytes::Vector{UInt8}) = read!(io.out, bytes)
read{T<:AbstractPipe}(io::T, args...) = read(io.out, args...)
read!{T<:AbstractPipe}(io::T, args...) = read!(io.out, args...)
readuntil{T<:AbstractPipe}(io::T, args...) = readuntil(io.out, args...)
readbytes(io::AbstractPipe) = readbytes(io.out)
readavailable(io::AbstractPipe) = readavailable(io.out)

isreadable(io::AbstractPipe) = isreadable(io.out)
iswritable(io::AbstractPipe) = iswritable(io.in)
isopen(io::AbstractPipe) = isopen(io.in) || isopen(io.out)
close(io::AbstractPipe) = (close(io.in); close(io.out))
wait_readnb(io::AbstractPipe, nb::Int) = wait_readnb(io.out, nb)
Expand Down Expand Up @@ -1167,6 +1171,8 @@ type BufferStream <: AsyncStream
BufferStream() = new(PipeBuffer(), Condition(), Condition(), true, false, ReentrantLock())
end

lock(s::BufferStream) = lock(s.lock)
unlock(s::BufferStream) = unlock(s.unlock)

This comment has been minimized.

Copy link
@vtjnash

vtjnash Sep 6, 2015

Member

looks like these should have been ::AsyncStream

isopen(s::BufferStream) = s.is_open
close(s::BufferStream) = (s.is_open = false; notify(s.r_c; all=true); notify(s.close_c; all=true); nothing)

Expand Down
38 changes: 4 additions & 34 deletions test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,44 +248,14 @@ let bad = "bad\0name"
@test_throws ArgumentError run(setenv(`echo hello`, "good"=>bad))
end

# issue #12829
let out = Pipe()
@test_throws ArgumentError write(out, "not open error")
open(`cat -n`, "w", out) do in1
open(`cat -n`, "w", out) do in2
write(in1, 'h')
write(in2, UInt8['w'])
println(in1, "ello")
write(in2, "orld\n")
end
open(`cat`, "w", out) do io
println(io, 1)
end
show(out, out)
@test isreadable(out)
@test iswritable(out)
close(out.in)
@test_throws ArgumentError write(out, "now closed error")
@test isreadable(out)
@test !iswritable(out)
@test isopen(out)
@test endswith(readuntil(out, '1'), '1')
@test read(out, UInt8) == '\n'
c = UInt8[0]
@test c == read!(out, c)
@test nb_availble(out) == 0
wait_readnb(out, 1)
@test nb_availble(out) > 0
ln1 = readline(out)
ln2 = readline(out)
desc = readall(out)
@test !isreadable(out)
@test !iswritable(out)
@test !isopen(out)
@test nb_availble(out) == 0
@test c == ['w']
@test lstrip(ln2) == "1\thello\n"
@test ln1 == "orld\n"
@test isempty(readbytes(out))
@test eof(out)

This comment has been minimized.

Copy link
@vtjnash

vtjnash Aug 29, 2015

Member

I'm pretty sure "deleted all tests" is just cheating

This comment has been minimized.

Copy link
@JeffBezanson

JeffBezanson Aug 29, 2015

Author Member

The test I have confirms that the named issue is fixed. If there are other things that don't work, we can file issues about those.

@test desc == "Pipe(open => open, 0 bytes waiting)"
@test readline(out) == "1\n"
end

# issue #8529
Expand Down

0 comments on commit 334a2be

Please sign in to comment.