Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up redirect_* APIs after Pipe -> PipeEndpoint rename #18253

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -946,11 +946,13 @@ for (x, writable, unix_fd, c_symbol) in
handle.handle)
handle
end
function ($f)(handle::Pipe)
link_pipe(handle, julia_only_read = $(writable), julia_only_write = $(!writable))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably needs to check whether the Pipe is already open, following logic from

julia/base/process.jl

Lines 410 to 412 in f06840e

if stdio.in.status == StatusUninit && stdio.out.status == StatusUninit
link_pipe(stdio)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the $f function on line 944 is also missing an isopen test

$(f)($(writable) ? handle.in : handle.out)
handle
end
function ($f)()
read,write = (PipeEndpoint(), PipeEndpoint())
link_pipe(read,$(writable),write,$(!writable))
($f)($(writable? :write : :read))
(read,write)
$(f)(Pipe())
end
end
end
Expand All @@ -959,17 +961,17 @@ end
redirect_stdout()

Create a pipe to which all C and Julia level `STDOUT` output will be redirected. Returns a
tuple `(rd,wr)` representing the pipe ends. Data written to `STDOUT` may now be read from
the rd end of the pipe. The wr end is given for convenience in case the old `STDOUT` object
was cached by the user and needs to be replaced elsewhere.
Pipe object representing the pipe ends. Data written to `STDOUT` may now be read from
the pipe. Note that `STDOUT` will be set to `pipe.in` (which is a `PipeEndpoint`), not the
pipe itself.
"""
redirect_stdout

"""
redirect_stdout(stream)

Replace `STDOUT` by stream for all C and Julia level output to `STDOUT`. Note that `stream`
must be a TTY, a `Pipe` or a `TCPSocket`.
must be a TTY, a `Pipe`, a `PipeEndpoint` or a `TCPSocket`.
"""
redirect_stdout(stream)

Expand All @@ -983,8 +985,8 @@ redirect_stderr
"""
redirect_stdin([stream])

Like redirect_stdout, but for STDIN. Note that the order of the return tuple is still
(rd,wr), i.e. data to be read from STDIN, may be written to wr.
Like redirect_stdout, but for STDIN. Note however, that in this case, STDIN will be `pipe.out`
(such that data written to `pipe` will be available to read from `STDIN`).
"""
redirect_stdin

Expand Down
3 changes: 2 additions & 1 deletion test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ tse_str = sprint(show, Test.TestSetException(1,2,3,4))

OLD_STDOUT = STDOUT
catch_out = IOStream("")
rd, wr = redirect_stdout()
# Capture a reference to make sure the read end doesn't get closed
pipe = redirect_stdout()

# Check that the fallback test set throws immediately
@test_throws ErrorException (@test 1 == 2)
Expand Down