Skip to content

Commit

Permalink
Merge pull request #3874 from stevengj/writable
Browse files Browse the repository at this point in the history
spelling consistency: writeable -> writable; deprecate iswriteable
  • Loading branch information
Keno committed Jul 30, 2013
2 parents 1ffed5d + 7491030 commit 783b822
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 34 deletions.
1 change: 1 addition & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export PipeString

# 0.2

@deprecate iswriteable iswritable
@deprecate localize localpart
@deprecate logb exponent
@deprecate ilogb exponent
Expand Down
4 changes: 2 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ export
fdio,
isreadonly,
UV_READABLE,
UV_WRITEABLE,
UV_WRITABLE,
flush,
getaddrinfo,
gethostname,
Expand Down Expand Up @@ -1177,7 +1177,7 @@ export
issetgid,
issticky,
isreadable,
iswriteable,
iswritable,
isexecutable,
uperm,
gperm,
Expand Down
4 changes: 2 additions & 2 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ else
error("seriously? what is this machine?")
end

isreadonly(s) = isreadable(s) && !iswriteable(s)
isreadonly(s) = isreadable(s) && !iswritable(s)

## binary I/O ##

Expand Down Expand Up @@ -245,7 +245,7 @@ close(s::IOStream) = ccall(:ios_close, Void, (Ptr{Void},), s.ios)
isopen(s::IOStream) = bool(ccall(:ios_isopen, Cint, (Ptr{Void},), s.ios))
flush(s::IOStream) = ccall(:ios_flush, Void, (Ptr{Void},), s.ios)
isreadonly(s::IOStream) = bool(ccall(:ios_get_readonly, Cint, (Ptr{Void},), s.ios))
iswriteable(s::IOStream) = !isreadonly(s)
iswritable(s::IOStream) = !isreadonly(s)
isreadable(s::IOStream) = true

truncate(s::IOStream, n::Integer) =
Expand Down
2 changes: 1 addition & 1 deletion base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ end
read{T}(from::IOBuffer, ::Type{Ptr{T}}) = convert(Ptr{T}, read(from, Uint))

isreadable(io::IOBuffer) = io.readable
iswriteable(io::IOBuffer) = io.writable
iswritable(io::IOBuffer) = io.writable

# TODO: IOBuffer is not iterable, so doesn't really have a length.
# This should maybe be sizeof() instead.
Expand Down
24 changes: 12 additions & 12 deletions base/poll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
close(t::FileMonitor) = ccall(:jl_close_uv,Void,(Ptr{Void},),t.handle)

const UV_READABLE = 1
const UV_WRITEABLE = 2
const UV_WRITABLE = 2

convert(::Type{Int32},fd::RawFD) = fd.fd

Expand Down Expand Up @@ -107,9 +107,9 @@ function fdw_wait_cb(fdw::FDWatcher,status,events)
end
end

function _wait(fdw::FDWatcher,readable,writeable)
function _wait(fdw::FDWatcher,readable,writable)
events = (readable ? UV_READABLE : 0) |
(writeable ? UV_WRITEABLE : 0)
(writable ? UV_WRITABLE : 0)
if events == 0
error("Must be watching for at least one event")
end
Expand All @@ -121,7 +121,7 @@ function _wait(fdw::FDWatcher,readable,writeable)
while true
events = wait(fdw.notify)
if (readable && (events & UV_READABLE) != 0) ||
(writeable && (events & UV_WRITEABLE) != 0)
(writable && (events & UV_WRITABLE) != 0)
break
end
end
Expand All @@ -145,7 +145,7 @@ let
fdwatcher_array = Array(FDWatcher,0)
end

function wait(fd::RawFD; readable=false, writeable=false)
function wait(fd::RawFD; readable=false, writable=false)
old_length = length(fdwatcher_array)
if fd.fd+1 > old_length
resize!(fdwatcher_array,fd.fd+1)
Expand All @@ -154,7 +154,7 @@ let
if is(fdwatcher_array[fd.fd+1],empty_watcher)
fdwatcher_array[fd.fd+1] = FDWatcher(fd)
end
_wait(fdwatcher_array[fd.fd+1],readable,writeable)
_wait(fdwatcher_array[fd.fd+1],readable,writable)
end
end
@windows_only begin
Expand All @@ -163,15 +163,15 @@ let
fdwatcher_array = Dict{WindowsRawSocket,FDWatcher}()
end

function wait(fd::RawFD; readable=false, writeable=false)
wait(_get_osfhandle(fd); readable=readable, writeable=writeable)
function wait(fd::RawFD; readable=false, writable=false)
wait(_get_osfhandle(fd); readable=readable, writable=writable)
end

function wait(socket::WindowsRawSocket; readable=false, writeable=false)
function wait(socket::WindowsRawSocket; readable=false, writable=false)
if !has(fdwatcher_array,socket.handle)
fdwatcher_array[fd.handle] = FDWatcher(socket)
end
_wait(fdwatcher_array[fd.handle],readable,writeable)
_wait(fdwatcher_array[fd.handle],readable,writable)
end
end
end
Expand Down Expand Up @@ -258,10 +258,10 @@ end
_uv_hook_close(uv::FileMonitor) = (uv.handle = 0; nothing)
_uv_hook_close(uv::UVPollingWatcher) = (uv.handle = 0; nothing)

function poll_fd(s, seconds::Real; readable=false, writeable=false)
function poll_fd(s, seconds::Real; readable=false, writable=false)
wt = Condition()

@schedule (args = wait(s; readable=readable, writeable=writeable); notify(wt,(:poll,args)))
@schedule (args = wait(s; readable=readable, writable=writable); notify(wt,(:poll,args)))
@schedule (sleep(seconds); notify(wt,(:timeout,0)))

_, ret = wait(wt)
Expand Down
4 changes: 2 additions & 2 deletions base/stat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ issetgid(mode::Unsigned) = (mode & 0o2000) > 0
issticky(mode::Unsigned) = (mode & 0o1000) > 0

isreadable(mode::Unsigned) = (mode & 0o444) > 0
iswriteable(mode::Unsigned) = (mode & 0o222) > 0
iswritable(mode::Unsigned) = (mode & 0o222) > 0
isexecutable(mode::Unsigned) = (mode & 0o111) > 0

uperm(mode::Unsigned) = uint8(mode >> 6) & 0x7
Expand All @@ -94,7 +94,7 @@ for f in {
:issetgid
:issticky
:isreadable
:iswriteable
:iswritable
:isexecutable
:uperm
:gperm
Expand Down
24 changes: 12 additions & 12 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ type PipeServer <: UVServer
false,Condition())
end

function init_pipe!(pipe::Union(NamedPipe,PipeServer);readable::Bool=false,writeable=false,julia_only=true)
function init_pipe!(pipe::Union(NamedPipe,PipeServer);readable::Bool=false,writable=false,julia_only=true)
if pipe.handle == C_NULL || pipe.status != StatusUninit
error("Failed to initialize pipe")
end
uv_error("init_pipe",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), pipe.handle, writeable,readable,julia_only,pipe))
uv_error("init_pipe",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), pipe.handle, writable,readable,julia_only,pipe))
pipe.status = StatusInit
pipe
end
Expand Down Expand Up @@ -177,11 +177,11 @@ function TTY(fd::RawFD; readable::Bool = false)
ret
end

# note that uv_is_readable/writeable work for any subtype of
# note that uv_is_readable/writable work for any subtype of
# uv_stream_t, including uv_tty_t and uv_pipe_t
isreadable(io::Union(NamedPipe,PipeServer,TTY)) =
bool(ccall(:uv_is_readable, Cint, (Ptr{Void},), io.handle))
iswriteable(io::Union(NamedPipe,PipeServer,TTY)) =
iswritable(io::Union(NamedPipe,PipeServer,TTY)) =
bool(ccall(:uv_is_writable, Cint, (Ptr{Void},), io.handle))

show(io::IO,stream::TTY) = print(io,"TTY(",uv_status_string(stream),", ",
Expand Down Expand Up @@ -499,36 +499,36 @@ end

## pipe functions ##
malloc_pipe() = c_malloc(_sizeof_uv_named_pipe)
function link_pipe(read_end::Ptr{Void},readable_julia_only::Bool,write_end::Ptr{Void},writeable_julia_only::Bool,readpipe::AsyncStream,writepipe::AsyncStream)
function link_pipe(read_end::Ptr{Void},readable_julia_only::Bool,write_end::Ptr{Void},writable_julia_only::Bool,readpipe::AsyncStream,writepipe::AsyncStream)
#make the pipe an unbuffered stream for now
#TODO: this is probably not freeing memory properly after errors
uv_error("init_pipe",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), read_end, 0, 1, readable_julia_only, readpipe))
uv_error("init_pipe(2)",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), write_end, 1, 0, writeable_julia_only, writepipe))
uv_error("init_pipe(2)",ccall(:jl_init_pipe, Cint, (Ptr{Void},Int32,Int32,Int32,Any), write_end, 1, 0, writable_julia_only, writepipe))
uv_error("pipe_link",ccall(:uv_pipe_link, Int32, (Ptr{Void}, Ptr{Void}), read_end, write_end))
end

function link_pipe(read_end2::NamedPipe,readable_julia_only::Bool,write_end::Ptr{Void},writeable_julia_only::Bool)
function link_pipe(read_end2::NamedPipe,readable_julia_only::Bool,write_end::Ptr{Void},writable_julia_only::Bool)
if read_end2.handle == C_NULL
read_end2.handle = malloc_pipe()
end
link_pipe(read_end2.handle,readable_julia_only,write_end,writeable_julia_only,read_end2,read_end2)
link_pipe(read_end2.handle,readable_julia_only,write_end,writable_julia_only,read_end2,read_end2)
read_end2.status = StatusOpen
end
function link_pipe(read_end::Ptr{Void},readable_julia_only::Bool,write_end::NamedPipe,writeable_julia_only::Bool)
function link_pipe(read_end::Ptr{Void},readable_julia_only::Bool,write_end::NamedPipe,writable_julia_only::Bool)
if write_end.handle == C_NULL
write_end.handle = malloc_pipe()
end
link_pipe(read_end,readable_julia_only,write_end.handle,writeable_julia_only,write_end,write_end)
link_pipe(read_end,readable_julia_only,write_end.handle,writable_julia_only,write_end,write_end)
write_end.status = StatusOpen
end
function link_pipe(read_end::NamedPipe,readable_julia_only::Bool,write_end::NamedPipe,writeable_julia_only::Bool)
function link_pipe(read_end::NamedPipe,readable_julia_only::Bool,write_end::NamedPipe,writable_julia_only::Bool)
if write_end.handle == C_NULL
write_end.handle = malloc_pipe()
end
if read_end.handle == C_NULL
read_end.handle = malloc_pipe()
end
link_pipe(read_end.handle,readable_julia_only,write_end.handle,writeable_julia_only,read_end,write_end)
link_pipe(read_end.handle,readable_julia_only,write_end.handle,writable_julia_only,read_end,write_end)
write_end.status = StatusOpen
read_end.status = StatusOpen
nothing
Expand Down
4 changes: 2 additions & 2 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ touch(file)
@test isfile(file) == true
@test islink(file) == false
@test isreadable(file) == true
@test iswriteable(file) == true
@test iswritable(file) == true
# Here's something else that might be UNIX-specific?
run(`chmod -w $file`)
@test iswriteable(file) == false
@test iswritable(file) == false
run(`chmod +w $file`)
@test isexecutable(file) == false
@test filesize(file) == 0
Expand Down
2 changes: 1 addition & 1 deletion test/pollfd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function test_read(slval)
tr = consume(t)
t_elapsed = toq()

@test tr == UV_READABLE || (UV_READABLE | UV_WRITEABLE)
@test tr == UV_READABLE || (UV_READABLE | UV_WRITABLE)

dout = Array(Uint8, 1)
@test 1 == ccall(:read, Csize_t, (Cint, Ptr{Uint8},Csize_t), pipe_fds[1], dout, 1)
Expand Down

0 comments on commit 783b822

Please sign in to comment.