-
Notifications
You must be signed in to change notification settings - Fork 102
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
add rcutils_unsigned_char_array_t #125
Conversation
I'm not up to speed on this issue, but what about using |
I am open to new types and names here. I thought unsigned char is just a typedef to uint8_t and thus chose Is there any reason to prefer |
There is one (pretty pedantic) reason that @sloretz brought up; |
The question then becomes, if It's a bit academic, because I don't think it will "just" work on a machine where |
Is there any reason not to call this |
Not that it would require a change in the name of this struct, but MISRA requires that you use explicitly sized types, like |
@wjwwood that makes sense -- and +1 for the |
4f63b7e
to
d3e6938
Compare
@ros2/team friendly ping :) |
include/rcutils/types/uint8_array.h
Outdated
* Be aware, that this will deallocate the memory and therefore invalidates any | ||
* pointers to this storage. | ||
* If the new size is larger, new memory is getting allocated and the existing | ||
* content is copied over. |
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.
Are you using realloc
internally? And if so do you also use it when shrinking the data? And if so does that not also potentially mean the pointer address can change?
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 see now that you are, so this applies I believe:
the original pointer ptr is invalidated and any access to it is undefined behavior (even if reallocation was in-place).
-- https://en.cppreference.com/w/cpp/memory/c/realloc
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.
yes, the pointer might change. Is there any way around that?
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.
Is there any way around that?
In which case? In general, no I don't think so.
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 have it documented just before this sentence that all pointers to the underlying buffer will be invalidated. What do you advise to do here?
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.
It says that will only happen "if the new size is larger", which is not the only case and the reason I brought it up initially.
At least it should be stated that you should always assume the pointer is invalid after calling this, regardless of the input arguments and how they related to current values.
src/uint8_array.c
Outdated
"uint8 array pointer is null", | ||
return RCUTILS_RET_ERROR); | ||
|
||
if (!rcutils_allocator_is_valid(allocator)) { |
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.
RCUTILS_CHECK_ALLOCATOR(allocator, return RCUTILS_RET_INVALID_ARGUMENT);
Same for other occurrences below.
src/uint8_array.c
Outdated
rcutils_ret_t | ||
rcutils_uint8_array_fini(rcutils_uint8_array_t * uint8_array) | ||
{ | ||
RCUTILS_CHECK_FOR_NULL_WITH_MSG( |
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.
RCUTILS_CHECK_ARGUMENT_FOR_NULL(uint8_array, RCUTILS_RET_INVALID_ARGUMENT);
Same for other occurrences below.
thanks for the feedback. Given that this |
I think it doesn't make sense to merge this with known issues and fix it later, so I'd go with fix in place, retest and merge, then follow up on char array. Whether or not you follow up on char array in this pr or in a new one doesn't matter to me. |
Hopefully addressed all comments. I decided to iterate over the changes here at first and then apply the same to |
include/rcutils/types/uint8_array.h
Outdated
* Be aware, that this will deallocate the memory and therefore invalidates any | ||
* pointers to this storage. | ||
* If the new size is larger, new memory is getting allocated and the existing | ||
* content is copied over. |
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.
It says that will only happen "if the new size is larger", which is not the only case and the reason I brought it up initially.
At least it should be stated that you should always assume the pointer is invalid after calling this, regardless of the input arguments and how they related to current values.
Co-Authored-By: Karsten1987 <[email protected]>
Co-Authored-By: Karsten1987 <[email protected]>
Co-Authored-By: Karsten1987 <[email protected]>
@wjwwood do you mind checking it again? I would like to have this in soon so I can build on top of that for the serialized messages. |
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, sorry if I was holding it up.
thanks for the review! |
This data structure will eventually be used for serialized messages and replaces the
rcutils_char_array_t
for binary data buffers.initial issue here: ros2/demos#279
CI: