Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/zmq/utils/interop.py: 17%
12 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""Utils for interoperability with other libraries.
3Just CFFI pointer casting for now.
4"""
6# Copyright (C) PyZMQ Developers
7# Distributed under the terms of the Modified BSD License.
9from typing import Any
12def cast_int_addr(n: Any) -> int:
13 """Cast an address to a Python int
15 This could be a Python integer or a CFFI pointer
16 """
17 if isinstance(n, int):
18 return n
19 try:
20 import cffi # type: ignore
21 except ImportError:
22 pass
23 else:
24 # from pyzmq, this is an FFI void *
25 ffi = cffi.FFI()
26 if isinstance(n, ffi.CData):
27 return int(ffi.cast("size_t", n))
29 raise ValueError("Cannot cast %r to int" % n)