-
Notifications
You must be signed in to change notification settings - Fork 863
lfs_crc should be static if LFS_CRC is defined #1095
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
Conversation
Tests passed ✓, Code: 17116 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 812 B (+0.0%)
|
I think a more consistent approach would be to get rid of the |
I kept it in the same style as Changing how one can provide their own CRC function, for example in the way you described, might perhaps also be a improvement but one I think that would best be discussed in a separete PR since that would mean a more significant change in the interface which I assume was designed and discussed at the time this feature was added. I don't have an opinion on what would in the end be the superior interface; but perhaps others do. For that reason I would prefer that a simpler fix (like this one, but any other that solves the stated issue is fine too) would be considered for merging first, since it doesn't change the existing interface and thus can presumably be merged with less discussion so current use cases are no longer blocked. That still leaves room for a bigger change that changes the interface later. |
@DvdGiessen, good points, and it does have me questioning whether my suggestion is better overall. However...
What you have here is not quite the same as those, since |
Wow! Who let this get merged (it was me). Thanks @DvdGiessen for the fix, will bring this in on the next patch release. Sorry about the late response. @bmcdonnell-fb I agree with @DvdGiessen, feel free to create an issue or PR if you think it needs to change. But the reason for the It at least avoids a warning pile if user's malloc returns W.r.t. |
But that's all this PR does...? Also, |
I'm assuming no one is putting an entire CRC implementation directly inside the LFS_CRC macro. I would expect LFS_CRC to just be the name of your own If we wanted to be perfectly consistent, we could do this: #ifndef LFS_CRC
uint32_t lfs_crc_(uint32_t crc, const void *buffer, size_t size);
#endif
static inline uint32_t lfs_crc_(uint32_t crc, const void *buffer, size_t size) {
#ifdef LFS_CRC
return LFS_CRC(crc, buffer, size);
#else
return lfs_crc_(crc, buffer, size);
#endif
} But that's a bit silly. |
@geky, I see what you mean. However, FWIW, the intent and usage seems clearer to me from your "perfectly consistent" example. If you merge this as is, might it be worth adding a comment to indicate, as you said,
? OK, that's enough from me on this. Thanks for all your work on the project. |
Bringing this in, hopefully better late than never, thanks for the PR! |
If
LFS_CRC
is defined, we define a wrapper function in the header file itself instead of referring to a function implemented later inlfs_utils.c
. In that case we should declare that wrapper function to bestatic
so that we don't end up with multiple definitions of thelfs_crc
function if the header file (as is quite usual) gets included in multiple compile units.Additionally it can also be declared
inline
to match the other functions. And, there was a missing semicolon meaning one would have to include an extra semicolon in their#define
macro to make everything compile without errors. Adding in the semicolon won't break any existing users that already included it themselves.