Skip to content

Commit

Permalink
reorganize uv-related exports
Browse files Browse the repository at this point in the history
remove camelCase names
don't export globalEventLoop
remove flipbits since it is identical to ~ and !
  • Loading branch information
JeffBezanson committed Feb 9, 2013
1 parent 28a2107 commit 8ccc861
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 48 deletions.
5 changes: 2 additions & 3 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ imag(B::BitArray) = falses(size(B))
conj!(B::BitArray) = B
conj(B::BitArray) = copy(B)

function flipbits(B::BitArray)
function (~)(B::BitArray)
C = similar(B)
Bc = B.chunks
if !isempty(Bc)
Expand All @@ -913,8 +913,7 @@ function flipbits!(B::BitArray)
return B
end

(~)(B::BitArray) = flipbits(B)
!(B::BitArray) = flipbits(B)
!(B::BitArray) = ~B

## Binary arithmetic operators ##

Expand Down
1 change: 1 addition & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ end
@deprecate map_to map!
@deprecate rotl rol
@deprecate rotr ror
@deprecate flipbits ~

export grow!
function grow!(a, d)
Expand Down
45 changes: 20 additions & 25 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export
AbstractVector,
Array,
Associative,
AsyncStream,
BitArray,
BigFloat,
BigInt,
Expand Down Expand Up @@ -84,6 +85,7 @@ export
RopeString,
Set,
SparseMatrixCSC,
SpawnNullStream,
StridedArray,
StridedMatrix,
StridedVecOrMat,
Expand All @@ -93,7 +95,9 @@ export
SubOrDArray,
SubString,
SymTridiagonal,
TcpSocket,
Tridiagonal,
UVError,
VecOrMat,
Vector,
VersionNumber,
Expand Down Expand Up @@ -602,7 +606,6 @@ export
bitpack,
bitunpack,
falses,
flipbits,
flipbits!,
rol,
ror,
Expand Down Expand Up @@ -942,6 +945,9 @@ export
tty_rows,

# I/O and events
accept,
listen,
bind,
close,
countlines,
readcsv,
Expand Down Expand Up @@ -972,6 +978,7 @@ export
munmap,
nb_available,
open,
open_any_tcp_port,
position,
read,
readall,
Expand All @@ -984,9 +991,14 @@ export
seek_end,
serialize,
skip,
start_reading,
stop_reading,
start_timer,
stop_timer,
takebuf_array,
takebuf_string,
truncate,
uv_error,
write,

# multiprocessing
Expand Down Expand Up @@ -1082,6 +1094,7 @@ export
connect,
getpid,
ignorestatus,
kill,
pipeline_error,
process_exit_status,
process_exited,
Expand All @@ -1095,6 +1108,7 @@ export
readsfrom,
run,
spawn,
spawn_nostdin,
success,
writesto,

Expand All @@ -1113,15 +1127,16 @@ export
unsafe_assign,

# Macros
@v_str,
@unexpected,
@assert,
@r_str,
@str,
@I_str,
@E_str,
@B_str,
@b_str,
@L_str,
@r_str,
@v_str,
@unexpected,
@assert,
@cmd,
@time,
@timed,
Expand All @@ -1141,28 +1156,8 @@ export
@eval,
@task,
@thunk,
@L_str,
@vectorize_1arg,
@vectorize_2arg,
@show,
@printf,
@sprintf

export
# libuv branch stuff
accept,
listen,
bind,
AsyncStream,
SpawnNullStream,
TcpSocket,
open_any_tcp_port,
spawn_nostdin,
start_reading,
stop_reading,
globalEventLoop,
uv_error,
UVError,
kill,
startTimer,
stopTimer
10 changes: 5 additions & 5 deletions base/fs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export File,
S_IROTH, S_IWOTH, S_IXOTH, S_IRWXO

#import Base.show, Base.open, Base.close, Base.write
import Base.uvtype, Base.uvhandle
import Base.uvtype, Base.uvhandle, Base.eventloop

include("file_constants.jl")

Expand Down Expand Up @@ -64,7 +64,7 @@ _uv_fs_result(req) = ccall(:jl_uv_fs_result,Int32,(Ptr{Void},),req)
function open(f::File,flags::Integer,mode::Integer)
req = Base.Intrinsics.box(Ptr{Void},Intrinsics.jl_alloca(Base.Intrinsics.unbox(Int32,_sizeof_uv_fs_t)))
ret = ccall(:uv_fs_open,Int32,(Ptr{Void},Ptr{Void},Ptr{Uint8},Int32,Int32,Ptr{Void}),
globalEventLoop(),req,bytestring(f.path),flags,mode,C_NULL)
eventloop(),req,bytestring(f.path),flags,mode,C_NULL)
uv_error(:open,ret==-1)
f.handle = _uv_fs_result(req)
f.open = true
Expand All @@ -80,7 +80,7 @@ function close(f::File)
end
req = Intrinsics.box(Ptr{Void},Intrinsics.jl_alloca(Intrinsics.unbox(Int32,_sizeof_uv_fs_t)))
err = ccall(:uv_fs_close,Int32,(Ptr{Void},Ptr{Void},Int32,Ptr{Void}),
globalEventLoop(),req,f.handle,C_NULL)
eventloop(),req,f.handle,C_NULL)
uv_error(err)
f.handle = -1
f.open = false
Expand All @@ -91,7 +91,7 @@ end
function unlink(p::String)
req = box(Ptr{Void},Intrinsics.jl_alloca(unbox(Int32,_sizeof_uv_fs_t)))
err = ccall(:uv_fs_unlink,Int32,(Ptr{Void},Ptr{Void},Ptr{Uint8},Ptr{Void}),
globalEventLoop(),req,bytestring(p),C_NULL)
eventloop(),req,bytestring(p),C_NULL)
uv_error(err)
end
function unlink(f::File)
Expand All @@ -108,7 +108,7 @@ function write(f::File,buf::Ptr{Uint8},len::Int32,offset::Int64)
end
req = box(Ptr{Void},Intrinsics.jl_alloca(unbox(Int32,_sizeof_uv_fs_t)))
err = ccall(:uv_fs_close,Int32,(Ptr{Void},Ptr{Void},Int32,Ptr{Uint8},Int32,Int64,Ptr{Void}),
globalEventLoop(),req,f.handle,buf,len,offset,C_NULL)
eventloop(),req,f.handle,buf,len,offset,C_NULL)
uv_error(err)
f
end
Expand Down
4 changes: 2 additions & 2 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1373,8 +1373,8 @@ function _jl_work_cb(args...)
end

function event_loop(isclient)
global work_cb = SingleAsyncWork(globalEventLoop(),_jl_work_cb)
global fgcm_cb = SingleAsyncWork(globalEventLoop(),(args...)->flush_gc_msgs());
global work_cb = SingleAsyncWork(eventloop(), _jl_work_cb)
global fgcm_cb = SingleAsyncWork(eventloop(), (args...)->flush_gc_msgs());
queueAsync(work_cb::SingleAsyncWork)
iserr, lasterr = false, ()
while true
Expand Down
2 changes: 1 addition & 1 deletion base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function _uv_hook_close(proc::Process)
end

function spawn(pc::ProcessChainOrNot,cmd::Cmd,stdios::StdIOSet,exitcb::Callback,closecb::Callback)
loop = globalEventLoop()
loop = eventloop()
close_in,close_out,close_err = false,false,false
pp = Process(cmd,C_NULL,stdios[1],stdios[2],stdios[3]);
in,out,err=stdios
Expand Down
6 changes: 3 additions & 3 deletions base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type TcpSocket <: Socket
function TcpSocket()
this = TcpSocket(C_NULL,false)
this.handle = ccall(:jl_make_tcp,Ptr{Void},(Ptr{Void},Any),
globalEventLoop(),this)
eventloop(),this)
if (this.handle == C_NULL)
error("Failed to start reading: ",_uv_lasterror())
end
Expand All @@ -109,7 +109,7 @@ type UdpSocket <: Socket
function UdpSocket()
this = UdpSocket(C_NULL,false)
this.handle = ccall(:jl_make_tcp,Ptr{Void},(Ptr{Void},Any),
globalEventLoop(),this)
eventloop(),this)
this
end
end
Expand Down Expand Up @@ -216,7 +216,7 @@ jl_getaddrinfo(loop::Ptr{Void}, host::ByteString, service::Ptr{Void},

getaddrinfo(cb::Function,host::ASCIIString) = begin
callback_dict[cb] = cb
jl_getaddrinfo(globalEventLoop(),host,C_NULL,cb)
jl_getaddrinfo(eventloop(),host,C_NULL,cb)
end

function getaddrinfo(host::ASCIIString)
Expand Down
2 changes: 1 addition & 1 deletion base/stat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ macro stat_call(sym,arg)
quote
fill!(stat_buf,0)
r = ccall($(expr(:quote,sym)), Int32, (Ptr{Uint8},Ptr{Uint8}), $arg, stat_buf)
uv_errno = _uv_lasterror(globalEventLoop())
uv_errno = _uv_lasterror(eventloop())
ENOENT = 34
system_error(:stat, r!=0 && uv_errno!=ENOENT)
st = Stat(stat_buf)
Expand Down
12 changes: 6 additions & 6 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ _uv_hook_close(uv::AsyncWork) = (uv.handle = 0; nothing)
# This serves as a common callback for all async classes
_uv_hook_asynccb(async::AsyncWork, status::Int32) = async.cb(status)

function startTimer(timer::TimeoutAsyncWork,timeout::Int64,repeat::Int64)
function start_timer(timer::TimeoutAsyncWork,timeout::Int64,repeat::Int64)
ccall(:jl_timer_start,Int32,(Ptr{Void},Int64,Int64),timer.handle,timeout,repeat)
end

function stopTimer(timer::TimeoutAsyncWork)
function stop_timer(timer::TimeoutAsyncWork)
ccall(:jl_timer_stop,Int32,(Ptr{Void},),timer.handle)
end

Expand All @@ -326,13 +326,13 @@ function queueAsync(work::SingleAsyncWork)
end

## event loop ##
globalEventLoop() = ccall(:jl_global_event_loop,Ptr{Void},())
eventloop() = ccall(:jl_global_event_loop,Ptr{Void},())
#mkNewEventLoop() = ccall(:jl_new_event_loop,Ptr{Void},()) # this would be fine, but is nowhere supported

function run_event_loop(loop::Ptr{Void})
ccall(:jl_run_event_loop,Void,(Ptr{Void},),loop)
end
run_event_loop() = run_event_loop(globalEventLoop())
run_event_loop() = run_event_loop(eventloop())

##pipe functions
malloc_pipe() = c_malloc(_sizeof_uv_pipe)
Expand Down Expand Up @@ -451,9 +451,9 @@ _write(s::AsyncStream, p::Ptr{Void}, nb::Integer) =

## Libuv error handling
_uv_lasterror(loop::Ptr{Void}) = ccall(:jl_last_errno,Int32,(Ptr{Void},),loop)
_uv_lasterror() = _uv_lasterror(globalEventLoop())
_uv_lasterror() = _uv_lasterror(eventloop())
_uv_lastsystemerror(loop::Ptr{Void}) = ccall(:jl_last_errno,Int32,(Ptr{Void},),loop)
_uv_lastsystemerror() = _uv_lasterror(globalEventLoop())
_uv_lastsystemerror() = _uv_lasterror(eventloop())

type UVError <: Exception
prefix::String
Expand Down
4 changes: 2 additions & 2 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ b1 = randbool(v1)
for m = [rand(1:v1)-1 0 1 63 64 65 191 192 193 v1-1]
@test isequal(b1 << m, [ b1[m+1:end]; falses(m) ])
@test isequal(b1 >>> m, [ falses(m); b1[1:end-m] ])
@test isequal(rotl(b1, m), [ b1[m+1:end]; b1[1:m] ])
@test isequal(rotr(b1, m), [ b1[end-m+1:end]; b1[1:end-m] ])
@test isequal(rol(b1, m), [ b1[m+1:end]; b1[1:m] ])
@test isequal(ror(b1, m), [ b1[end-m+1:end]; b1[1:end-m] ])
end

timesofar("datamove")
Expand Down

0 comments on commit 8ccc861

Please sign in to comment.