From 8defdea50bd8b4da539ab65187e59473c742142b Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Sat, 22 Jul 2017 21:45:24 -0400 Subject: [PATCH] Fix most of 0.7 depwarns Drop 0.4 support Remove `bytestring(::Message)` --- .travis.yml | 2 +- REQUIRE | 4 +-- appveyor.yml | 4 +-- deps/build.jl | 4 +-- src/ZMQ.jl | 88 +++++++++++------------------------------------- test/runtests.jl | 24 ------------- 6 files changed, 27 insertions(+), 99 deletions(-) diff --git a/.travis.yml b/.travis.yml index 804c96c..d74c8a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ os: - linux - osx julia: - - 0.4 - 0.5 + - 0.6 - nightly notifications: email: false diff --git a/REQUIRE b/REQUIRE index f65bfa3..6593f7f 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,5 +1,5 @@ -julia 0.4 +julia 0.5 BinDeps 0.3.21 @osx Homebrew -Compat 0.17.0 +Compat 0.27.0 @windows WinRPM diff --git a/appveyor.yml b/appveyor.yml index 923632c..2d44a87 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,9 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe" - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" diff --git a/deps/build.jl b/deps/build.jl index cf5e778..2620800 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -24,10 +24,10 @@ provides(BuildProcess, Autotools(libtarget = "src/.libs/libzmq." * Libdl.dlext), provides(AptGet, "libzmq3", zmq, os = :Linux) provides(Yum, "czmq", zmq, os = :Linux) -if is_windows() +if Compat.Sys.iswindows() using WinRPM provides(WinRPM.RPM, "zeromq", [zmq], os = :Windows) -elseif is_apple() +elseif Compat.Sys.isapple() using Homebrew provides(Homebrew.HB, "staticfloat/juliadeps/zeromq32", zmq, os = :Darwin) end diff --git a/src/ZMQ.jl b/src/ZMQ.jl index 7b3e877..ee14d9f 100644 --- a/src/ZMQ.jl +++ b/src/ZMQ.jl @@ -4,20 +4,11 @@ __precompile__(true) module ZMQ using Compat -import Compat: String, unsafe_string -import Base.unsafe_convert +import Base: unsafe_convert, unsafe_string using Base.Libdl, Base.Libc using Base.Libdl: dlopen_e using Base.Libc: EAGAIN - -if VERSION >= v"0.5.0-dev+1229" - import Base.Filesystem: UV_READABLE, uv_pollcb -else - import Base: UV_READABLE - if isdefined(Base, :uv_pollcb) - import Base: uv_pollcb - end -end +import Base.Filesystem: UV_READABLE, uv_pollcb const depfile = joinpath(dirname(@__FILE__),"..","deps","deps.jl") if isfile(depfile) @@ -63,25 +54,10 @@ function jl_zmq_error_str() end end -if VERSION >= v"0.5-" && isdefined(Base, :Filesystem) - if is_windows() - using Base.Libc: WindowsRawSocket - end - const _FDWatcher = Base.Filesystem._FDWatcher - const _have_good_fdwatcher = true -elseif VERSION >= v"0.4-" && isdefined(Base, :_FDWatcher) - if is_windows() - using Base.Libc: WindowsRawSocket - end - const _FDWatcher = Base._FDWatcher - const _have_good_fdwatcher = true -else - if is_windows() - using Base: WindowsRawSocket - end - const _FDWatcher = Base.FDWatcher - const _have_good_fdwatcher = false +if Compat.Sys.iswindows() + using Base.Libc: WindowsRawSocket end +const _FDWatcher = Base.Filesystem._FDWatcher ## Sockets ## type Socket @@ -95,11 +71,7 @@ type Socket throw(StateError(jl_zmq_error_str())) end socket = new(p) - if _have_good_fdwatcher - socket.pollfd = _FDWatcher(fd(socket), #=readable=#true, #=writable=#false) - else - socket.pollfd = _FDWatcher(fd(socket)) - end + socket.pollfd = _FDWatcher(fd(socket), #=readable=#true, #=writable=#false) finalizer(socket, close) push!(ctx.sockets, socket) return socket @@ -110,12 +82,7 @@ function close(socket::Socket) if socket.data != C_NULL data = socket.data socket.data = C_NULL - if _have_good_fdwatcher - close(socket.pollfd, #=readable=#true, #=writable=#false) - else - notify(socket.pollfd.notify) - Base.stop_watching(socket.pollfd) - end + close(socket.pollfd, #=readable=#true, #=writable=#false) rc = ccall((:zmq_close, zmq), Cint, (Ptr{Void},), data) if rc != 0 throw(StateError(jl_zmq_error_str())) @@ -210,7 +177,7 @@ for (fset, fget, k, p) in [ (:set_tcp_keepalive_intvl, :get_tcp_keepalive_intvl, 37, ip) (:set_rcvtimeo, :get_rcvtimeo, 27, ip) (:set_sndtimeo, :get_sndtimeo, 28, ip) - (nothing, :get_fd, 14, is_windows() ? pp : ip) + (nothing, :get_fd, 14, Compat.Sys.iswindows() ? pp : ip) ] if fset != nothing @eval function ($fset)(socket::Socket, option_val::Integer) @@ -232,20 +199,20 @@ for (fset, fget, k, p) in [ if rc != 0 throw(StateError(jl_zmq_error_str())) end - return @compat Int(($p)[1]) + return Int(($p)[1]) end end end # For some functions, the publicly-visible versions should require & # return boolean: -get_rcvmore(socket::Socket) = @compat Bool(_zmq_getsockopt_rcvmore(socket)) +get_rcvmore(socket::Socket) = Bool(_zmq_getsockopt_rcvmore(socket)) # And a convenience function ismore(socket::Socket) = get_rcvmore(socket) # subscribe/unsubscribe options take an arbitrary byte array for (f,k) in ((:subscribe,6), (:unsubscribe,7)) - f_ = @compat Symbol(string(f, "_")) + f_ = Symbol(f, "_") @eval begin function $f_{T}(socket::Socket, filter::Ptr{T}, len::Integer) rc = ccall((:zmq_setsockopt, zmq), Cint, @@ -255,29 +222,22 @@ for (f,k) in ((:subscribe,6), (:unsubscribe,7)) throw(StateError(jl_zmq_error_str())) end end - @compat $f(socket::Socket, filter::Union{Array,AbstractString}) = + $f(socket::Socket, filter::Union{Array,AbstractString}) = $f_(socket, pointer(filter), sizeof(filter)) $f(socket::Socket) = $f_(socket, C_NULL, 0) end end # Raw FD access -if is_unix() +if Compat.Sys.isunix() fd(socket::Socket) = RawFD(get_fd(socket)) end -if is_windows() +if Compat.Sys.iswindows() fd(socket::Socket) = WindowsRawSocket(convert(Ptr{Void}, get_fd(socket))) end -if _have_good_fdwatcher - wait(socket::Socket) = wait(socket.pollfd, readable=true, writable=false) - notify(socket::Socket) = uv_pollcb(socket.pollfd.handle, Int32(0), - Int32(UV_READABLE)) -else - wait(socket::Socket) = Base._wait(socket.pollfd, #=readable=#true, #=writable=#false) - notify(socket::Socket) = Base._uv_hook_pollcb(socket.pollfd, int32(0), - int32(UV_READABLE)) -end +wait(socket::Socket) = wait(socket.pollfd, readable=true, writable=false) +notify(socket::Socket) = uv_pollcb(socket.pollfd.handle, Int32(0), Int32(UV_READABLE)) # Socket options of string type const u8ap = zeros(UInt8, 255) @@ -310,7 +270,7 @@ for (fset, fget, k) in [ if rc != 0 throw(StateError(jl_zmq_error_str())) end - return unsafe_string(unsafe_convert(Ptr{UInt8}, $u8ap), @compat Int(($sz)[1])) + return unsafe_string(unsafe_convert(Ptr{UInt8}, $u8ap), Int(($sz)[1])) end end end @@ -341,7 +301,7 @@ close_handle(work) = Base.close(work) gc_protect_cb(work) = (pop!(gc_protect, work.handle, nothing); close_handle(work)) function gc_protect_handle(obj::Any) - work = Compat.AsyncCondition(gc_protect_cb) + work = Base.AsyncCondition(gc_protect_cb) gc_protect[work.handle] = (work,obj) work.handle end @@ -419,7 +379,7 @@ isfreed(m::Message) = haskey(gc_protect, m.handle) # AbstractArray behaviors: similar(a::Message, T, dims::Dims) = Array{T}(dims) # ? -length(zmsg::Message) = @compat Int(ccall((:zmq_msg_size, zmq), Csize_t, (Ptr{Message},), &zmsg)) +length(zmsg::Message) = Int(ccall((:zmq_msg_size, zmq), Csize_t, (Ptr{Message},), &zmsg)) size(zmsg::Message) = (length(zmsg),) unsafe_convert(::Type{Ptr{UInt8}}, zmsg::Message) = ccall((:zmq_msg_data, zmq), Ptr{UInt8}, (Ptr{Message},), &zmsg) function getindex(a::Message, i::Integer) @@ -436,15 +396,7 @@ function setindex!(a::Message, v, i::Integer) end # Convert message to string (copies data) -unsafe_string(zmsg::Message) = Compat.unsafe_string(pointer(zmsg), length(zmsg)) -if isdefined(Base, :bytestring) - import Base: bytestring - if VERSION < v"0.5-dev+4341" - bytestring(zmsg::Message) = unsafe_string(zmsg) - else - @deprecate bytestring(zmsg::Message) unsafe_string(zmsg::Message) - end -end +unsafe_string(zmsg::Message) = unsafe_string(pointer(zmsg), length(zmsg)) # Build an IOStream from a message # Copies the data diff --git a/test/runtests.jl b/test/runtests.jl index 3223c6a..0d12caf 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,4 @@ using ZMQ, Compat -using Compat.String println("Testing with ZMQ version $(ZMQ.version)") @@ -82,26 +81,3 @@ seek(o, 0) ZMQ.close(s1) ZMQ.close(s2) ZMQ.close(ctx2) - -# deprecate bytestring(::Message), removed on 0.6 -isdefined(Base, :bytestring) && let olderr = STDERR - old_have_color = Base.have_color - eval(Base, :(have_color = false)) # avoid control characters in output - local rderr, wrerr, reader - try - rderr, wrerr = redirect_stderr() - reader = @async readstring(rderr) - @assert bytestring(Message("hello")) == "hello" - finally - # Switch the stderr back before letting the error propagate so that - # the error output won't be swallowed. - redirect_stderr(olderr) - close(wrerr) - eval(Base, :(have_color = $old_have_color)) # avoid control characters in output - end - if VERSION < v"0.5-dev+4341" - @assert isempty(wait(reader)) - else - @assert contains(wait(reader), "WARNING: bytestring(zmsg::Message) is deprecated") - end -end