diff --git a/bindings/python/iio.py b/bindings/python/iio.py index e289f56bf..0923f2369 100644 --- a/bindings/python/iio.py +++ b/bindings/python/iio.py @@ -31,6 +31,7 @@ c_double, cast, sizeof, + string_at, POINTER as _POINTER, CDLL as _cdll, memmove as _memmove, @@ -300,6 +301,7 @@ class ChannelType(Enum): _iiolib = "iio" _lib = _cdll("libiio.so.1", use_errno=True, use_last_error=True) +_libc = _cdll(find_library("c")) _get_backends_count = _lib.iio_get_builtin_backends_count _get_backends_count.restype = c_uint @@ -357,7 +359,7 @@ class ChannelType(Enum): _get_description.argtypes = (_ContextPtr,) _get_xml = _lib.iio_context_get_xml -_get_xml.restype = c_char_p +_get_xml.restype = c_void_p _get_xml.argtypes = (_ContextPtr,) _get_version_major = _lib.iio_context_get_version_major @@ -697,6 +699,9 @@ class ChannelType(Enum): _ev_get_channel.argtypes = (_EventPtr, _DevicePtr, c_bool) _ev_get_channel.errcheck = _check_null +_libc_free = _libc.free +_libc_free.argtypes = (c_void_p,) + # pylint: enable=invalid-name @@ -1419,13 +1424,15 @@ def __init__(self, _context=None): self._name = _get_name(self._context).decode("ascii") self._description = _get_description(self._context).decode("ascii") - self._xml = _get_xml(self._context).decode("ascii") + self._xml_hdl = _get_xml(self._context) + self._xml = bytes(string_at(self._xml_hdl)).decode("ascii") self._version = _get_lib_version(self._context) def __del__(self): """Destroy this context.""" if self._context is not None: _destroy(self._context) + _libc_free(cast(self._xml_hdl, c_void_p)) def set_timeout(self, timeout): """