Skip to content

Commit

Permalink
Implement lib_version()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JamesWrigley committed Jun 8, 2024
1 parent 83f7f33 commit 87e45fc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/src/_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
```@meta
CurrentModule = ZMQ
```

# Reference

```@docs
lib_version
```

## Sockets

The ZMQ Socket type:
Expand Down
16 changes: 13 additions & 3 deletions src/ZMQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 87e45fc

Please sign in to comment.