-
Notifications
You must be signed in to change notification settings - Fork 318
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
Philip/random clean up fixes #1184
base: main
Are you sure you want to change the base?
Philip/random clean up fixes #1184
Conversation
I'm debugging one more issue, which I'd like to resolve before removing the "Draft" label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nunojsa, would you mind sanity checking this commit? There is a fair amount of generic code here and although I can test my MCU setup I am not totally confident how this will impact other use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also thinking of adding a --debug
that will set the log level in params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nunojsa, would you mind sanity checking this commit? There is a fair amount of generic code here and although I can test my MCU setup I am not totally confident how this will impact other use cases.
I'm not super super familiar with libiio internals but looking at the code the change seems pretty harmless. The commit message is also very good in explaining the change (and it does make sense to me).
I was also thinking of adding a --debug that will set the log level in params
If the other option is to recompile libiio, then yes... that seems like an useful change. Maybe a follow up PR...
5a8480f
to
d70e3e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -359,7 +359,7 @@ struct iio_context * handle_common_opts(char * name, int argc, | |||
} else if (!arg && backend != IIO_LOCAL) | |||
fprintf(stderr, "argument parsing error\n"); | |||
else if (backend == IIO_URI) | |||
ctx = iio_create_context(NULL, arg); | |||
ctx = iio_create_context(¶ms, arg); | |||
else | |||
ctx = iio_create_context(NULL, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likely not needed if there's no real need for a re-spin but adding the params in here should not arm (I guess this is local context and timeout is unlikely - if possible at all)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that passing NULL
is functionally the same in Libiio as passing a zero-initialized params
.
Obviously if you want to keep testing CentOS 7 and whether those functions should be dropped is beyond my pay grade. I'm more than happy to drop them from the series, but figured I'd offer up the changes. 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still support centos 7, since some downstream users (MathWorks) still support Centos 7 - https://www.mathworks.com/support/requirements/matlab-linux.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the functionality for local - in that it ignores the timeout given on the command line, which will be a problem for slow devices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the free man page:
If ptr is NULL, no operation is performed.
meaning it is perfectly safe and valid.
Rearranging things to avoid this is unnecessary.
Hi @rgetz, thanks for taking a look! Unfortunately, it looks like the comments were made on the PR main thread rather than on a particular commit or diff, which can make it a bit harder to understand what you are referring to and I can't reply directly to the comments in a thread or mark them as resolved. If you have any follow-up review comments could you please comment on the code directly where possible?
Is this referring to adding I'm not sure why the flags you link to do not get applied. This is already a bit of a rabbit hole since enabling warnings has created numerous warnings across platforms and architectures. Any help debugging it would be appreciated. Otherwise I'll try to look into it when I have time.
👍 Will drop it the next time I push
This is also a bit hard to understand out of context of the code. The change I made is intended to do the opposite. The command-line timeout isn't currently applied until after the context is created, which created a problem for my setup with a MCU communicating at 9600 Baud.
Yup, it is definitely valid C, but given that the bug was related to a bug calling if (description) {
if (ctx->description) {
free(ctx->description);
} else {
...
}
} As opposed to this alternative based on how it is currently implemented: if (description) {
if (ctx->description) {
...
} else {
...
}
free(ctx->description);
} Of course it also saves a function call, although that's clearly not significant here. |
both - We (Paul and I) decided we only apply these things to the library - not the examples or the utils - which are managed in their own cmake files. |
Ok, but just so it is clear, doing so has meant that warnings have not been enabled in your builds for a significant amount of code. It is much harder to guarantee that Reading through the top level |
If you mean extra warnings - sure. But only the code that doesn't really matter... if you want to fix everything, and then pass down the CFLAGS to the appropriate target_compile - and then fix everything - that's up to you - there are lots of failing things when you do that that the CI found. As mentioned in the CMAKE - you can't turn on some flags on some architectures while Cmake is testing for specific functionality or capabilities. - it will cause false failures, and screw up the builds. see : https://github.com/analogdevicesinc/libiio/blob/main/CMakeLists.txt#L300 |
cb9ab56
to
aaa67e0
Compare
Add check when attempting to concatenate description strings. When description was NULL and ctx->description was a valid string then ctx->description was freed and replaced by NULL. This caused iio_info to not print the backend description string. Additionally, do not free(NULL) when ctx->description is NULL. Fixes analogdevicesinc#1121 Signed-off-by: Philip Molloy <[email protected]>
When a timeout is specified as a command-line argument then it is only applied after the final context is created. If the creation of the context requires transfering data then a default timeout is used. That default timeout might be too short for slow transfers, preventing the context from being created. For example, a serial backend without any devices needs to send a context XML string of roughly 1170 bytes, which when communicating at 9600 baud will take more than the default timeout of 1000 ms. Signed-off-by: Philip Molloy <[email protected]>
Signed-off-by: Philip Molloy <[email protected]>
Signed-off-by: Philip Molloy <[email protected]>
Signed-off-by: Philip Molloy <[email protected]>
Signed-off-by: Philip Molloy <[email protected]>
If iio_context_get_device() does not return a iio_device pointer then the uninitialized ret variable was passed as a code to iiod_io_send_response_code(). Signed-off-by: Philip Molloy <[email protected]>
Signed-off-by: Philip Molloy <[email protected]>
Signed-off-by: Philip Molloy <[email protected]>
Signed-off-by: Philip Molloy <[email protected]>
- Remove unused variables. A warning was only generated in the macOS and ARM Linux builds and not in x86 Linux. - The uninitialized variable should never be read since the example will exit() if an error occurs. A warning was only generated with the macOS builds, not the x86 or ARM Linux builds. Signed-off-by: Philip Molloy <[email protected]>
This was only caught in the macOS and ARM builds and not in Linux Signed-off-by: Philip Molloy <[email protected]>
- Remove unused variables - The uninitialized variable should never be read since the example will exit() if an error occurs. A warning was only generated with the macOS builds, not the x86 or ARM Linux builds. Signed-off-by: Philip Molloy <[email protected]>
aaa67e0
to
14ef974
Compare
I dropped the CentOS7 change and adding I assume the current build errors are related to #1183. |
I think this was removed from your patch set - but I would not do it in the CI scripts - do it in the CMAKE - so that all developers run with the same settings, and people don't notice problems only when submitting patches, they find it on their desktop first... but this was also the reason that we didn't add warn as error outside the library - if a userspace util warns on a new compiler for some reason - you shouldn't stop people from using the utils. -Robin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit doesn't have to be so complicated... even though the commit message helps to understand what it does.
The change could just be:
diff --git a/context.c b/context.c
index a202e80e..a836f5fd 100644
--- a/context.c
+++ b/context.c
@@ -641,8 +641,11 @@ iio_create_context_from_xml(const struct iio_context_params *params,
}
}
- free(ctx->description);
- ctx->description = new_description;
+ if (new_description) {
+ free(ctx->description);
+ ctx->description = new_description;
+ }
+
ctx->params = *params;
return ctx;
Note that free(NULL)
is perfectly valid C so there's no reason to work around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the two things I noted above, the rest of the changes look good! Thanks for the PR!
@@ -257,12 +257,12 @@ struct iio_context * handle_common_opts(char * name, int argc, | |||
int *err_code) | |||
{ | |||
struct iio_context *ctx = NULL; | |||
struct iio_context_params params = { .timeout_ms = -1 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1
would mean infinite timeout (IIRC), keep it zero-initialized and Libiio will set it to the default timeout that corresponds to the backend used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, -1
was used previously to prevent iio_context_set_timeout()
from being called if a timeout wasn't specified at the command-line. Thanks for catching that copy/paste mistake!
Right, I replied to a similar point in this comment. I'm proposing:
As I understand it you're suggesting the following?
|
Well, your comment did say "the bug was related to a bug calling free() incorrectly", but that's not the case, is it? From what I can see the bug is that the code unconditionally replaces |
Incorrectly in the sense of the logic of the program not the semantics of C. Maybe it would help if I rephrased Or I could split up the commit somehow to make the diff easier to read? |
No, I'm suggesting that you don't need anything else than the diff I pasted above to make it work. To be clear, what bothers me with your commit isn't the change in itself (although avoiding the Sure, the |
For me the actual code is always more important than what the diff looks like. Indenting code isn't exactly a complicated maneuver, but it does create a larger diff. And in my opinion the original bug was the result of the code being oddly complicated in the first place. So making code more complicated by moving statements into additional blocks because of ugly diffs is inviting the same kind of logical errors that this bug fix is trying to fix. I'm not trying to avoid
Why not move the Anyway, I'm not sure how to get around such a fundamental disagreement. 😆 I'd be happy to break out the oneline change of |
@pamolloy I lost a bit track of this but I guess you could still make @pcercuei happy and do your cleanup...
What I read of this is, make the fix as small as possible (diff speaking) so it's easy to understand what the fix is about. Then, there's nothing stopping you from adding a new patch only for code cleanup and improving readability. If the extra patch really does that, I don't see why Paul would disagree with it. In the end, what Paul is trying to say (I think) is that git history matters, a lot. TBH, I completely agree with this... You can still refactor the code as you want but in an incremental way. And when fixes are involved, it's even more important. For instance think about a fix that you want to backport. It's way easier to backport a tiny little patch with oneline diff than a bigger patch where it will be way difficult to understand what the fix is about. And when backporting, you just care about the fix and not code refactoring :) |
This seems totally reasonable to me! |
Was just watching So You Think You Know Git - FOSDEM 2024 and learned about |
And I just found out it is also possible to render something similar to |
PR Description
A few random fixes related to porting libiio to a MCU.
PR Type
PR Checklist