From 87e45fcc6add84c7f86df7c7464f9a8a4b297b94 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Sat, 8 Jun 2024 18:58:54 +0200 Subject: [PATCH] Implement `lib_version()` This is a slightly nicer API than looking up the undocumented (and mutable) `ZMQ.version`, though `ZMQ.version` is left as a const global for backwards compatibility. --- docs/src/_changelog.md | 5 +++++ docs/src/reference.md | 8 ++++++++ src/ZMQ.jl | 16 +++++++++++++--- test/runtests.jl | 4 ++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/src/_changelog.md b/docs/src/_changelog.md index 5ac219f..1baff64 100644 --- a/docs/src/_changelog.md +++ b/docs/src/_changelog.md @@ -7,6 +7,11 @@ CurrentModule = ZMQ This documents notable changes in ZMQ.jl. The format is based on [Keep a Changelog](https://keepachangelog.com). +## Unreleased + +### Added + +- [`lib_version()`](@ref) to get the libzmq version ([#240]). ## [v1.2.5] - 2024-05-28 diff --git a/docs/src/reference.md b/docs/src/reference.md index a654da5..daf8aac 100644 --- a/docs/src/reference.md +++ b/docs/src/reference.md @@ -1,5 +1,13 @@ +```@meta +CurrentModule = ZMQ +``` + # Reference +```@docs +lib_version +``` + ## Sockets The ZMQ Socket type: diff --git a/src/ZMQ.jl b/src/ZMQ.jl index 3bf8118..8805754 100644 --- a/src/ZMQ.jl +++ b/src/ZMQ.jl @@ -29,13 +29,23 @@ include("sockopts.jl") include("message.jl") include("comm.jl") -function __init__() +""" + lib_version() + +Get the libzmq version number. +""" +function lib_version() major = Ref{Cint}() minor = Ref{Cint}() patch = Ref{Cint}() ccall((:zmq_version, libzmq), Cvoid, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), major, minor, patch) - global version = VersionNumber(major[], minor[], patch[]) - if version < v"3" + return VersionNumber(major[], minor[], patch[]) +end + +const version = lib_version() + +function __init__() + if lib_version() < v"3" error("ZMQ version $version < 3 is not supported") end atexit() do diff --git a/test/runtests.jl b/test/runtests.jl index cc79f7d..8668cfa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -164,6 +164,10 @@ end @test !isopen(leaked_ctx) end +@testset "Utilities" begin + @test ZMQ.lib_version() isa VersionNumber +end + @testset "Aqua.jl" begin Aqua.test_all(ZMQ) end