@@ -1245,7 +1245,15 @@ function _redirect_io_libc(stream, unix_fd::Int)
1245
1245
- 10 - unix_fd, Libc. _get_osfhandle (posix_fd))
1246
1246
end
1247
1247
end
1248
- dup (posix_fd, RawFD (unix_fd))
1248
+ GC. @preserve stream dup (posix_fd, RawFD (unix_fd))
1249
+ nothing
1250
+ end
1251
+ function _redirect_io_cglobal (handle:: Union{LibuvStream, IOStream, Nothing} , unix_fd:: Int )
1252
+ c_sym = unix_fd == 0 ? cglobal (:jl_uv_stdin , Ptr{Cvoid}) :
1253
+ unix_fd == 1 ? cglobal (:jl_uv_stdout , Ptr{Cvoid}) :
1254
+ unix_fd == 2 ? cglobal (:jl_uv_stderr , Ptr{Cvoid}) :
1255
+ C_NULL
1256
+ c_sym == C_NULL || unsafe_store! (c_sym, handle === nothing ? Ptr {Cvoid} (unix_fd) : handle. handle)
1249
1257
nothing
1250
1258
end
1251
1259
function _redirect_io_global (io, unix_fd:: Int )
@@ -1256,11 +1264,7 @@ function _redirect_io_global(io, unix_fd::Int)
1256
1264
end
1257
1265
function (f:: RedirectStdStream )(handle:: Union{LibuvStream, IOStream} )
1258
1266
_redirect_io_libc (handle, f. unix_fd)
1259
- c_sym = f. unix_fd == 0 ? cglobal (:jl_uv_stdin , Ptr{Cvoid}) :
1260
- f. unix_fd == 1 ? cglobal (:jl_uv_stdout , Ptr{Cvoid}) :
1261
- f. unix_fd == 2 ? cglobal (:jl_uv_stderr , Ptr{Cvoid}) :
1262
- C_NULL
1263
- c_sym == C_NULL || unsafe_store! (c_sym, handle. handle)
1267
+ _redirect_io_cglobal (handle, f. unix_fd)
1264
1268
_redirect_io_global (handle, f. unix_fd)
1265
1269
return handle
1266
1270
end
@@ -1269,6 +1273,7 @@ function (f::RedirectStdStream)(::DevNull)
1269
1273
handle = open (nulldev, write= f. writable)
1270
1274
_redirect_io_libc (handle, f. unix_fd)
1271
1275
close (handle) # handle has been dup'ed in _redirect_io_libc
1276
+ _redirect_io_cglobal (nothing , f. unix_fd)
1272
1277
_redirect_io_global (devnull , f. unix_fd)
1273
1278
return devnull
1274
1279
end
0 commit comments