Skip to content
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

Provide defaults for ParameterValue fields #18

Merged
merged 3 commits into from Aug 22, 2017
Merged

Conversation

dhood
Copy link
Member

@dhood dhood commented Aug 16, 2017

Even though only one field for a particular parameter is intended to be used at a time, to prevent serialisation of uninitialised fields we put defaults for all of them.

This is an alternative to ros2/rclcpp#358, both designed to fix the valgrind error referenced in that PR.

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Even though only one field for a particular parameter is intended to be used, to prevent serialisation of uninitialised fields we put defaults for all of them
@dhood dhood added the in review Waiting for review (Kanban column) label Aug 16, 2017
@dhood dhood self-assigned this Aug 16, 2017
int64 integer_value 0
float64 double_value 0.0
string string_value ""
byte[] bytes_value []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for the array is unnecessary. An array is always empty by default.

int64 integer_value
float64 double_value
string string_value
bool bool_value False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use false(lowercase) to match the design specification

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to clarify, is your comment just for style? or is False not supposed to work? (it seems to work)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not supposed to work given that our specification defines true, false, 1 and 0 as the only allowed valued for bool. It happens to work because we account for user error in our parser by lowercasing the value. But it is an implementation detail and would not work for any other parser written following the spec so I think we should not use it in our messages

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks for the explanation -- just wanted to check we know why it's working as is. fixed in 43081b3

Copy link
Member

@mikaelarguedas mikaelarguedas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -6,8 +6,8 @@
uint8 type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually should we initialize this too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good point, I guess that PARAMETER_NOT_SET would be a good default. Not sure how we refer to message constants from another msg file though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I guess we can't at the moment...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning for not putting a default for this was that, while all-but-one of the _value fields will be unused, the type is not "optional" so the client library should always initialise it itself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I guess we can't at the moment...

Should we open a ticket for this somewhere (rosidl?) that would be a useful feature

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got two thumbs up on my last comment so will consider this question resolved. (in the future, reactions don't send notifications (at least not to me!) so comments would be appreciated)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 sorry forgot about that, yeah it would be great if github allowed to enable notification for "reactions"

@dhood
Copy link
Member Author

dhood commented Aug 22, 2017

I was running some tests on other PRs and wanted to know that this wasn't on master for the CI. I'll merge this now.

Since @mikaelarguedas pointed out that the default values we specify here are the same as the defaults for those message types in general, I've opened #19 to track that this can be reverted if/when default-initialised messages can be created in client libraries

@dhood dhood merged commit d25c83b into master Aug 22, 2017
@dhood dhood deleted the param_value_defaults branch August 22, 2017 17:20
@dhood dhood removed the in review Waiting for review (Kanban column) label Aug 22, 2017
mikaelarguedas added a commit that referenced this pull request Nov 1, 2017
mikaelarguedas added a commit that referenced this pull request Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants