Skip to content

Commit 0de9164

Browse files
authored
Don't throw an error in raw! if the stream is closed (JuliaLang#56589)
This was added in JuliaLang#12568 to protect against a segfault after `close(stdin)`. However, the API is not great, because the stdin closing is an asynchronous event, so there isn't really any way to use this API without inccurring an error. Further, it already returns an error code of whether or not the action suceeded, and it's bad practice to have two ways for an operation to fail. Remove the error check and handle a closed stream gracefully returning an EOF error. In all users in Base, this EOF error is ignored, but we will gracefully check for EOF later and shut down the REPL, which is the desired behavior. Fixes timholy/Revise.jl#859
1 parent b6eeef2 commit 0de9164

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/jl_uv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,8 @@ JL_DLLEXPORT uv_handle_type jl_uv_handle_type(uv_handle_t *handle)
11601160

11611161
JL_DLLEXPORT int jl_tty_set_mode(uv_tty_t *handle, int mode)
11621162
{
1163+
if (!handle)
1164+
return UV__EOF;
11631165
if (handle->type != UV_TTY) return 0;
11641166
uv_tty_mode_t mode_enum = UV_TTY_MODE_NORMAL;
11651167
if (mode)

stdlib/REPL/src/Terminals.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,17 @@ cmove_col(t::UnixTerminal, n) = (write(t.out_stream, '\r'); n > 1 && cmove_right
122122

123123
if Sys.iswindows()
124124
function raw!(t::TTYTerminal,raw::Bool)
125-
check_open(t.in_stream)
126125
if Base.ispty(t.in_stream)
127126
run((raw ? `stty raw -echo onlcr -ocrnl opost` : `stty sane`),
128127
t.in_stream, t.out_stream, t.err_stream)
129128
true
130129
else
131-
ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), t.in_stream.handle::Ptr{Cvoid}, raw) != -1
130+
ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), t.in_stream.handle::Ptr{Cvoid}, raw) == 0
132131
end
133132
end
134133
else
135134
function raw!(t::TTYTerminal, raw::Bool)
136-
check_open(t.in_stream)
137-
ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), t.in_stream.handle::Ptr{Cvoid}, raw) != -1
135+
ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), t.in_stream.handle::Ptr{Cvoid}, raw) == 0
138136
end
139137
end
140138

0 commit comments

Comments
 (0)