Closed ekigwana closed 4 months ago
@sternmull, want to chime in?
The idea is that the wrapper classes always refer to non-null pointers of the C-API object, just like C++ references would do. This is the general assumption that is checked by the assert
.
The problem is that I missed that some functions might not be able to return an object under all conditions. In that situations C-API returns NULL
.
My suggestion to fix this: I would go through all functions that return objects and read their documentation more carefully. If they can return NULL
for an object then I change their return type to std::optional<ObjectType>
.
If there is mixed style within iiopp.h then it was by accident. I did not came across a style guide or autoformatting settings for libiio. But I have to admit that I also was not looking actively for it.
Thanks you @sternmull
https://github.com/analogdevicesinc/libiio/blob/7ae483696affb64ab6e1766f55e47f00456593d0/bindings/cpp/iiopp.h#L256
The asserts as utilized especially in the example above result in the program terminating. This is reasonable for test program accessing a particular device but when the code is part of a larger system this is highly undesirable. There are a couple ways of dealing with this:
As an example of this undesirable behavior, if there is a hardware communication problem with a particular IIO device, it will not get enumerated by the kernel driver. Proceeding to then use the context to find the device by name then results in a terminal condition:
With above program producing the following output:
Please share your thoughts on this so I can work on a patch to resolve this issue. Also, is there a code format spec for libiio? Like a clang-format or something? I have noticed different styles within iiopp.h.