Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ async def test_poll_leak():


async def test_draft_asyncio():
if not zmq.has("draft"):
if not zmq.DRAFT_API:
pytest.skip("draft API")
if zmq.zmq_version_info() < (4, 3, 2):
pytest.skip("requires libzmq 4.3.2 for zmq_poller_fd")
Expand Down
5 changes: 4 additions & 1 deletion zmq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def get_library_dirs():


COPY_THRESHOLD = 65536
DRAFT_API = backend.has("draft")
# zmq.DRAFT_API represents _both_ the current runtime-loaded libzmq
# and pyzmq were built with drafts,
# which is required for pyzmq draft support
DRAFT_API: bool = backend.has('draft') and backend.PYZMQ_DRAFT_API

__all__ = (
[
Expand Down
1 change: 1 addition & 0 deletions zmq/backend/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Context:
def term(self) -> None: ...

IPC_PATH_MAX_LEN: int
PYZMQ_DRAFT_API: bool

def has(capability: str) -> bool: ...
def curve_keypair() -> tuple[bytes, bytes]: ...
Expand Down
2 changes: 2 additions & 0 deletions zmq/backend/cffi/_cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ int zmq_wrap_msg_init_data(zmq_msg_t *msg,
void *data,
size_t size,
void *hint);

#define PYZMQ_DRAFT_API ...
2 changes: 1 addition & 1 deletion zmq/backend/cffi/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def get(self, option):
and self.get(SocketOption.THREAD_SAFE)
):
_check_version((4, 3, 2), "draft socket FD support via zmq_poller_fd")
if not zmq.has('draft'):
if not zmq.DRAFT_API:
raise RuntimeError("libzmq must be built with draft support")
warnings.warn(zmq.error.DraftFDWarning(), stacklevel=2)

Expand Down
4 changes: 3 additions & 1 deletion zmq/backend/cffi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ def _retry_sys_call(f, *args, **kwargs):
return rc


__all__ = ['has', 'curve_keypair', 'curve_public']
PYZMQ_DRAFT_API: bool = bool(C.PYZMQ_DRAFT_API)

__all__ = ['has', 'curve_keypair', 'curve_public', 'PYZMQ_DRAFT_API']
18 changes: 12 additions & 6 deletions zmq/backend/cython/_zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
from cython.cimports.libc.stdio import stderr as cstderr
from cython.cimports.libc.stdlib import free, malloc
from cython.cimports.libc.string import memcpy
from cython.cimports.zmq.backend.cython import libzmq
from cython.cimports.zmq.backend.cython._externs import (
get_ipc_path_max_len,
getpid,
Expand Down Expand Up @@ -163,6 +164,8 @@

IPC_PATH_MAX_LEN: int = get_ipc_path_max_len()

PYZMQ_DRAFT_API: bool = bool(libzmq.PYZMQ_DRAFT_API)


@cfunc
@inline
Expand Down Expand Up @@ -929,8 +932,10 @@ def get(self, option: C.int):
_check_version(
(4, 3, 2), "draft socket FD support via zmq_poller_fd"
)
if not zmq.has('draft'):
raise RuntimeError("libzmq must be built with draft support")
if not zmq.DRAFT_API:
raise RuntimeError(
"libzmq and pyzmq must be built with draft support"
)
warnings.warn(zmq.error.DraftFDWarning(), stacklevel=2)

# create a poller and retrieve its fd
Expand Down Expand Up @@ -1120,8 +1125,8 @@ def join(self, group: str | bytes):
.. versionadded:: 17
"""
_check_version((4, 2), "RADIO-DISH")
if not zmq.has('draft'):
raise RuntimeError("libzmq must be built with draft support")
if not zmq.DRAFT_API:
raise RuntimeError("libzmq and pyzmq must be built with draft support")
if isinstance(group, str):
group = group.encode('utf8')
c_group: bytes = group
Expand All @@ -1139,8 +1144,8 @@ def leave(self, group):
.. versionadded:: 17
"""
_check_version((4, 2), "RADIO-DISH")
if not zmq.has('draft'):
raise RuntimeError("libzmq must be built with draft support")
if not zmq.DRAFT_API:
raise RuntimeError("libzmq and pyzmq must be built with draft support")
rc: C.int = zmq_leave(self.handle, group)
_check_rc(rc)

Expand Down Expand Up @@ -2027,6 +2032,7 @@ def monitored_queue(

__all__ = [
'IPC_PATH_MAX_LEN',
'PYZMQ_DRAFT_API',
'Context',
'Socket',
'Frame',
Expand Down
1 change: 1 addition & 0 deletions zmq/backend/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'curve_public',
'zmq_version_info',
'IPC_PATH_MAX_LEN',
'PYZMQ_DRAFT_API',
]


Expand Down
4 changes: 4 additions & 0 deletions zmq/utils/zmq_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@

// libzmq 4.2 draft API
#ifdef ZMQ_BUILD_DRAFT_API
#define PYZMQ_DRAFT_API 1
#if ZMQ_VERSION >= 40200
#define PYZMQ_DRAFT_42
#endif
#if ZMQ_VERSION >= 40302
#define PYZMQ_DRAFT_432
#endif
#else
#define PYZMQ_DRAFT_API 0
#endif

#ifndef PYZMQ_DRAFT_42
#define zmq_join(s, group) _missing
#define zmq_leave(s, group) _missing
Expand Down
Loading