Skip to content

Commit 334a2be

Browse files
committed
a couple more changes to fix #12829
1 parent 462fd6e commit 334a2be

File tree

3 files changed

+25
-44
lines changed

3 files changed

+25
-44
lines changed

base/io.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,8 @@ function reset{T<:IO}(io::T)
303303
end
304304

305305
ismarked(io::IO) = io.mark >= 0
306+
307+
# Generic IO stubs
308+
309+
lock(::IO) = nothing
310+
unlock(::IO) = nothing

base/stream.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ show(io::IO,stream::TTY) = print(io,"TTY(",uv_status_string(stream),", ",
235235
nb_available(stream.buffer)," bytes waiting)")
236236

237237
function println(io::AsyncStream, xs...)
238-
lock(io.lock)
238+
lock(io)
239239
try
240240
invoke(println, Tuple{IO, map(typeof,xs)...}, io, xs...)
241241
finally
242-
unlock(io.lock)
242+
unlock(io)
243243
end
244244
end
245245

@@ -543,20 +543,24 @@ show(io::IO,stream::Pipe) = print(io,
543543
uv_status_string(stream.in), " => ",
544544
uv_status_string(stream.out), ", ",
545545
nb_available(stream), " bytes waiting)")
546-
isreadable(io::AbstractPipe) = isreadable(io.out)
547-
iswritable(io::AbstractPipe) = iswritable(io.in)
548-
read{T<:AbstractPipe}(io::T, args...) = read(io.out, args...)
546+
write(io::AbstractPipe, byte::UInt8) = write(io.in, byte)
547+
write(io::AbstractPipe, bytes::Vector{UInt8}) = write(io.in, bytes)
549548
write{T<:AbstractPipe}(io::T, args...) = write(io.in, args...)
550-
write{S<:AbstractPipe,T}(io::S, a::Array{T}) = write(io.in, a)
549+
write{S<:AbstractPipe}(io::S, a::Array) = write(io.in, a)
551550
buffer_or_write(io::AbstractPipe, p::Ptr, n::Integer) = buffer_or_write(io.in, p, n)
552-
println{T<:AbstractPipe}(io::T, args...) = println(io.in, args...)
553-
flush(io::AbstractPipe) = flush(io.in)
554551
buffer_writes(io::AbstractPipe, args...) = buffer_writes(io.in, args...)
555-
read{T<:AbstractPipe}(io::AbstractPipe, args...) = read(io.out, args)
556-
readuntil{T<:AbstractPipe}(io::T, args...) = readuntil(io.out, args...)
552+
flush(io::AbstractPipe) = flush(io.in)
553+
554+
read(io::AbstractPipe, byte::Type{UInt8}) = read(io.out, byte)
555+
read!(io::AbstractPipe, bytes::Vector{UInt8}) = read!(io.out, bytes)
556+
read{T<:AbstractPipe}(io::T, args...) = read(io.out, args...)
557557
read!{T<:AbstractPipe}(io::T, args...) = read!(io.out, args...)
558+
readuntil{T<:AbstractPipe}(io::T, args...) = readuntil(io.out, args...)
558559
readbytes(io::AbstractPipe) = readbytes(io.out)
559560
readavailable(io::AbstractPipe) = readavailable(io.out)
561+
562+
isreadable(io::AbstractPipe) = isreadable(io.out)
563+
iswritable(io::AbstractPipe) = iswritable(io.in)
560564
isopen(io::AbstractPipe) = isopen(io.in) || isopen(io.out)
561565
close(io::AbstractPipe) = (close(io.in); close(io.out))
562566
wait_readnb(io::AbstractPipe, nb::Int) = wait_readnb(io.out, nb)
@@ -1167,6 +1171,8 @@ type BufferStream <: AsyncStream
11671171
BufferStream() = new(PipeBuffer(), Condition(), Condition(), true, false, ReentrantLock())
11681172
end
11691173

1174+
lock(s::BufferStream) = lock(s.lock)
1175+
unlock(s::BufferStream) = unlock(s.unlock)
11701176
isopen(s::BufferStream) = s.is_open
11711177
close(s::BufferStream) = (s.is_open = false; notify(s.r_c; all=true); notify(s.close_c; all=true); nothing)
11721178

test/spawn.jl

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -248,44 +248,14 @@ let bad = "bad\0name"
248248
@test_throws ArgumentError run(setenv(`echo hello`, "good"=>bad))
249249
end
250250

251+
# issue #12829
251252
let out = Pipe()
252253
@test_throws ArgumentError write(out, "not open error")
253-
open(`cat -n`, "w", out) do in1
254-
open(`cat -n`, "w", out) do in2
255-
write(in1, 'h')
256-
write(in2, UInt8['w'])
257-
println(in1, "ello")
258-
write(in2, "orld\n")
259-
end
254+
open(`cat`, "w", out) do io
255+
println(io, 1)
260256
end
261-
show(out, out)
262-
@test isreadable(out)
263-
@test iswritable(out)
264257
close(out.in)
265-
@test_throws ArgumentError write(out, "now closed error")
266-
@test isreadable(out)
267-
@test !iswritable(out)
268-
@test isopen(out)
269-
@test endswith(readuntil(out, '1'), '1')
270-
@test read(out, UInt8) == '\n'
271-
c = UInt8[0]
272-
@test c == read!(out, c)
273-
@test nb_availble(out) == 0
274-
wait_readnb(out, 1)
275-
@test nb_availble(out) > 0
276-
ln1 = readline(out)
277-
ln2 = readline(out)
278-
desc = readall(out)
279-
@test !isreadable(out)
280-
@test !iswritable(out)
281-
@test !isopen(out)
282-
@test nb_availble(out) == 0
283-
@test c == ['w']
284-
@test lstrip(ln2) == "1\thello\n"
285-
@test ln1 == "orld\n"
286-
@test isempty(readbytes(out))
287-
@test eof(out)
288-
@test desc == "Pipe(open => open, 0 bytes waiting)"
258+
@test readline(out) == "1\n"
289259
end
290260

291261
# issue #8529

0 commit comments

Comments
 (0)