Skip to content

Commit

Permalink
Merge pull request #153 from JuliaInterop/yyc/0.7
Browse files Browse the repository at this point in the history
Fix most depwarns on 0.7
  • Loading branch information
yuyichao authored Sep 18, 2017
2 parents b1ed616 + 10b28c0 commit d2c5a18
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/ZMQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ type Message <: AbstractArray{UInt8,1}
function Message()
zmsg = new()
zmsg.handle = C_NULL
rc = ccall((:zmq_msg_init, zmq), Cint, (Ptr{Message},), &zmsg)
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
rc = ccall((:zmq_msg_init, zmq), Cint, (Any,), zmsg)
if rc != 0
throw(StateError(jl_zmq_error_str()))
end
Expand All @@ -335,7 +336,8 @@ type Message <: AbstractArray{UInt8,1}
function Message(len::Integer)
zmsg = new()
zmsg.handle = C_NULL
rc = ccall((:zmq_msg_init_size, zmq), Cint, (Ptr{Message}, Csize_t), &zmsg, len)
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
rc = ccall((:zmq_msg_init_size, zmq), Cint, (Any, Csize_t), zmsg, len)
if rc != 0
throw(StateError(jl_zmq_error_str()))
end
Expand All @@ -350,7 +352,9 @@ type Message <: AbstractArray{UInt8,1}
function Message{T}(origin::Any, m::Ptr{T}, len::Integer)
zmsg = new()
zmsg.handle = gc_protect_handle(origin)
rc = ccall((:zmq_msg_init_data, zmq), Cint, (Ptr{Message}, Ptr{T}, Csize_t, Ptr{Void}, Ptr{Void}), &zmsg, m, len, gc_free_fn_c::Ptr{Void}, zmsg.handle)
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
rc = ccall((:zmq_msg_init_data, zmq), Cint, (Any, Ptr{T}, Csize_t, Ptr{Void}, Ptr{Void}),
zmsg, m, len, gc_free_fn_c[], zmsg.handle)
if rc != 0
throw(StateError(jl_zmq_error_str()))
end
Expand Down Expand Up @@ -379,9 +383,11 @@ isfreed(m::Message) = haskey(gc_protect, m.handle)

# AbstractArray behaviors:
similar(a::Message, T, dims::Dims) = Array{T}(dims) # ?
length(zmsg::Message) = Int(ccall((:zmq_msg_size, zmq), Csize_t, (Ptr{Message},), &zmsg))
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
length(zmsg::Message) = Int(ccall((:zmq_msg_size, zmq), Csize_t, (Any,), zmsg))
size(zmsg::Message) = (length(zmsg),)
unsafe_convert(::Type{Ptr{UInt8}}, zmsg::Message) = ccall((:zmq_msg_data, zmq), Ptr{UInt8}, (Ptr{Message},), &zmsg)
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
unsafe_convert(::Type{Ptr{UInt8}}, zmsg::Message) = ccall((:zmq_msg_data, zmq), Ptr{UInt8}, (Any,), zmsg)
function getindex(a::Message, i::Integer)
if i < 1 || i > length(a)
throw(BoundsError())
Expand All @@ -408,21 +414,24 @@ end
# Close a message. You should not need to call this manually (let the
# finalizer do it).
function close(zmsg::Message)
rc = ccall((:zmq_msg_close, zmq), Cint, (Ptr{Message},), &zmsg)
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
rc = ccall((:zmq_msg_close, zmq), Cint, (Any,), zmsg)
if rc != 0
throw(StateError(jl_zmq_error_str()))
end
end

function get(zmsg::Message, property::Integer)
val = ccall((:zmq_msg_get, zmq), Cint, (Ptr{Message}, Cint), &zmsg, property)
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
val = ccall((:zmq_msg_get, zmq), Cint, (Any, Cint), zmsg, property)
if val < 0
throw(StateError(jl_zmq_error_str()))
end
val
end
function set(zmsg::Message, property::Integer, value::Integer)
rc = ccall((:zmq_msg_set, zmq), Cint, (Ptr{Message}, Cint, Cint), &zmsg, property, value)
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
rc = ccall((:zmq_msg_set, zmq), Cint, (Any, Cint, Cint), zmsg, property, value)
if rc < 0
throw(StateError(jl_zmq_error_str()))
end
Expand All @@ -442,8 +451,9 @@ const ZMQ_SNDMORE = 2

function send(socket::Socket, zmsg::Message, SNDMORE::Bool=false)
while true
rc = ccall((:zmq_msg_send, zmq), Cint, (Ptr{Message}, Ptr{Void}, Cint),
&zmsg, socket.data, (ZMQ_SNDMORE*SNDMORE) | ZMQ_DONTWAIT)
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
rc = ccall((:zmq_msg_send, zmq), Cint, (Any, Ptr{Void}, Cint),
zmsg, socket.data, (ZMQ_SNDMORE*SNDMORE) | ZMQ_DONTWAIT)
if rc == -1
zmq_errno() == EAGAIN || throw(StateError(jl_zmq_error_str()))
while (get_events(socket) & POLLOUT) == 0
Expand Down Expand Up @@ -477,8 +487,9 @@ function recv(socket::Socket)
zmsg = Message()
rc = -1
while true
rc = ccall((:zmq_msg_recv, zmq), Cint, (Ptr{Message}, Ptr{Void}, Cint),
&zmsg, socket.data, ZMQ_DONTWAIT)
# TODO: change `Any` to `Ref{Message}` when 0.6 support is dropped.
rc = ccall((:zmq_msg_recv, zmq), Cint, (Any, Ptr{Void}, Cint),
zmsg, socket.data, ZMQ_DONTWAIT)
if rc == -1
zmq_errno() == EAGAIN || throw(StateError(jl_zmq_error_str()))
while (get_events(socket) & POLLIN) == 0
Expand Down Expand Up @@ -531,6 +542,8 @@ const STREAMER = 1
const FORWARDER = 2
const QUEUE = 3

const gc_free_fn_c = Ref{Ptr{Void}}()

function __init__()
major = Ref{Cint}()
minor = Ref{Cint}()
Expand All @@ -540,7 +553,7 @@ function __init__()
if version < v"3"
error("ZMQ version $version < 3 is not supported")
end
global const gc_free_fn_c = cfunction(gc_free_fn, Cint, (Ptr{Void}, Ptr{Void}))
gc_free_fn_c[] = cfunction(gc_free_fn, Cint, Tuple{Ptr{Void}, Ptr{Void}})
end

end

0 comments on commit d2c5a18

Please sign in to comment.