Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework iio_context_get_xml() #1133

Merged
merged 6 commits into from
Jan 31, 2024
Merged

Rework iio_context_get_xml() #1133

merged 6 commits into from
Jan 31, 2024

Conversation

pcercuei
Copy link
Contributor

Instead of returning a string allocated alongside the IIO context, it
will now return a string allocated on the heap, that has to be freed
with free() afterwards. The function can now also return errors.

The advantage of this change is multiple:

  • IIO contexts now don't have a huge XML string allocated during their
    whole lifetime;
  • If the application does not call iio_context_get_xml(), then all the
    internal functions used to generate the XML string in the first place
    are dead code, and when building statically, can be garbage-collected.

C# bindings will be updated by @AlexandraTrifan in #1122.

@@ -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"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail in Windows. Need to use something like ctypes.util.find_msvcrt

Probably need to fix the _cdll call above as well since that breaks Windows too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Python bindings were broken on Windows before, and they are still broken on Windows after, then I'd argue it's not a problem of this commit and it can be fixed later in a subsequent PR. I'm kind of running against time here :)

Instead of returning a string allocated alongside the IIO context, it
will now return a string allocated on the heap, that has to be freed
with free() afterwards. The function can now also return errors.

The advantage of this change is multiple:
- IIO contexts now don't have a huge XML string allocated during their
  whole lifetime;
- If the application does not call iio_context_get_xml(), then all the
  internal functions used to generate the XML string in the first place
  are dead code, and when building statically, can be garbage-collected.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Emulate the v0.x behaviour of iio_context_get_xml() by allocating the
XML string when the Libiio context is created; which means that the
compatibility layer's iio_context_get_xml() is still a "pure" function.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Now that iio_context_get_xml() returns a heap-allocated string, we need
to de-allocate it with free() after use.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
@tfcollins tfcollins self-requested a review January 30, 2024 22:42
Now that iio_context_get_xml() returns a heap-allocated string, we need
to de-allocate it with free() after use.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Now that iio_context_get_xml() returns a heap-allocated string, we need
to de-allocate it with free() after use.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Now that iio_context_get_xml() returns a heap-allocated string, we need
to de-allocate it with free() after use.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
@pcercuei pcercuei merged commit 0973e72 into main Jan 31, 2024
21 of 25 checks passed
@pcercuei pcercuei deleted the pcercuei/iio_context_get_xml branch January 31, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants