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

Use File(RawFD(fd)) in preference to fdio(fd). #15091

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ end
# Obtain a temporary directory's path.
tempdir() = dirname(tempname())

# Create and return the name of a temporary file along with an IOStream
# Create and return the name of a temporary file along with an IO
function mktemp(parent=tempdir())
b = joinpath(parent, "tmpXXXXXX")
p = ccall(:mkstemp, Int32, (Cstring,), b) # modifies b
systemerror(:mktemp, p == -1)
return (b, fdio(p, true))
return (b, File(RawFD(p)))
end

# Create and return the name of a temporary directory
Expand Down
1 change: 1 addition & 0 deletions base/mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function settings(s::Int, shared::Bool)
end
return prot, flags, (prot & PROT_WRITE) > 0
end
settings(fd::RawFD, shared::Bool) = settings(Int(fd.fd), shared)

# Before mapping, grow the file to sufficient size
# Note: a few mappable streams do not support lseek. When Julia
Expand Down
2 changes: 1 addition & 1 deletion base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ function _shm_mmap_array(T, dims, shm_seg_name, mode)
fd_mem = shm_open(shm_seg_name, mode, S_IRUSR | S_IWUSR)
systemerror("shm_open() failed for " * shm_seg_name, fd_mem < 0)

s = fdio(fd_mem, true)
s = File(RawFD(fd_mem))

# On OSX, ftruncate must to used to set size of segment, just lseek does not work.
# and only at creation time
Expand Down
4 changes: 1 addition & 3 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ disassociate_julia_struct(handle::Ptr{Void}) =
function init_stdio(handle::Ptr{Void})
t = ccall(:jl_uv_handle_type, Int32, (Ptr{Void},), handle)
if t == UV_FILE
return fdio(ccall(:jl_uv_file_handle, Int32, (Ptr{Void},), handle))
# Replace ios.c file with libuv file?
# return File(RawFD(ccall(:jl_uv_file_handle,Int32,(Ptr{Void},),handle)))
return File(RawFD(ccall(:jl_uv_file_handle,Int32,(Ptr{Void},),handle)))
else
if t == UV_TTY
ret = TTY(handle)
Expand Down
13 changes: 8 additions & 5 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,23 @@ let exename = `$(Base.julia_cmd()) --precompiled=yes`
# FIXME these should also be run on windows once the bug causing them to hang gets fixed
@unix_only let out = Pipe(),
proc = spawn(pipeline(`$exename -E "$code" --depwarn=yes`, stderr=out))

wait(proc)
close(out.in)
result = UInt8[]
@async append!(result, read(out))
wait(proc)
@test success(proc)
@test readchomp(out) == "WARNING: Foo.Deprecated is deprecated.\n likely near no file:5"
@test UTF8String(result) == "WARNING: Foo.Deprecated is deprecated.\n likely near no file:5\n"
end

@unix_only let out = Pipe(),
proc = spawn(pipeline(`$exename -E "$code" --depwarn=no`, stderr=out))

close(out.in)
result = UInt8[]
@async append!(result, read(out))
wait(proc)
close(out.in)
@test success(proc)
@test isempty(readstring(out))
@test isempty(result)
end
end

Expand Down