-
Notifications
You must be signed in to change notification settings - Fork 119
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
Clean up Magic Numbers #140
Conversation
@@ -732,30 +733,34 @@ size_t TypeSupport<MembersType>::calculateMaxSerializedSize( | |||
case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_UINT8: | |||
case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_CHAR: | |||
case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_INT8: | |||
current_alignment += 1; | |||
current_alignment += sizeof(int8_t); |
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 those actually dependent on the system or is the alignment coming from the DDS spec? In the latter case the literal number makes more sense imo.
Same below.
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.
That's a good question, and one I do not know the answer to. Perhaps it would be ok to say this?
current_alignment += 1; /* sizeof(int8_t) */
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.
@allenh1 Did we come to a final answer on this ? should this use sizeof or should this be kept a hardcoded value based on the specs ?
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 think we agreed upon the sizeof, but I'll defer the call, as I am no expert.
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 didnt look at the spec. If you checked both specifications (DDS and RTPS) and that nothing specifies the padding I'm fine with merging this as is
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.
In DDS, the only statement about padding was dealing with the required 4 bytes. I'm not sure about RTPS, I'll have to get back to you.
@mikaelarguedas I just tested this branch (locally) with your new tests, and all seems to be ok.
Do you know the answer to this question? I don't know enough about DDS to make a claim there. |
cool!
No I don't, if it's in the spec I would expect it to be in the RTPS spec. I guess the other unknown is what we can do about the |
Maybe. Is that preferred?
I totally spaced on that one. I'll fix that. |
TL;DR I think that if the If the alignment if not specified in the spec, I think we should use Though I didn't look at how this |
I think you're right. Unfortunately, we just don't know what it is supposed to be. So, I think the best idea is to change it to |
I would check the RTPS and CDR specs first though as suggested in #140 (comment) |
Ok, sounds like a plan. |
CI (updated after f9dcf15) |
0df786c
to
f9dcf15
Compare
void * subros_message = nullptr; | ||
size_t array_size = 0; | ||
size_t sub_members_size = sub_members->size_of_; | ||
size_t max_align = calculateMaxAlign(sub_members); | ||
size_t space = 100; | ||
size_t space = 1; /* start with 1 byte */ |
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.
Can you please clarify why 1
is being used here? The comment doesn't provide much information.
The comment should also be //
instead of /* ... */
.
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 picked 1
since everything in the system is based on octets, so that's the smallest unit of space one can have. That's the most sensible value I could come up with -- does this makes sense? I'm not very confident with it at 1
, but I think it's better than having it set to 100
.
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.
As far as I can see the variable is being used as an "upper limit" on how much alignment can accumulate. I don't see why 1
would make sense for this?
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.
Btw. there is a second location where that constant is being used:
size_t space = 100; |
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.
As far as I can see the variable is being used as an "upper limit" on how much alignment can accumulate. I don't see why 1 would make sense for this?
In that case, the value should be 4
. I'll update it as such.
Btw. there is a second location where that constant is being used.
I'll update that as well. Thanks.
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.
In that case, the value should be
4
. I'll update it as such.
Why?
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.
If I'm understanding how DDS serialization works (which is a big if), that's how something of size 0 would be aligned.
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.
If I'm understanding how DDS serialization works (which is a big if), that's how something of size 0 would be aligned.
As far as I read the code this is not how this variable is being used.
@allenh1 any update on this ? |
…variable, encapsulation, to keep track of the magic number four added in several places.
f9dcf15
to
cb88ff3
Compare
@allenh1 If there is no obvious path forward here (figuring out if we can get rid of space completely or a default that makes more sense than the current one), please change (or split) this PR so that the removal of the other magic numbers can be merged while we decide what to do with the space variable |
@mikaelarguedas sounds good to me |
8c7d1a1
to
27e85f2
Compare
Yes the failure is unrelated, this is a test known to be flaky on windows. Can you please address / answer the comments ? |
@mikaelarguedas Ok, after looking at the RTPS spec, things are still fine (the sizes are recorded within the header). Good to merge? |
👍 please squash and merge ;) |
This is still in progress, but opening this for visibility.
connects to #72