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

Refactor get topic names and types #110

Merged
merged 5 commits into from
Jun 17, 2017

Conversation

wjwwood
Copy link
Member

@wjwwood wjwwood commented Jun 15, 2017

Connects to ros2/ros2#361

@wjwwood wjwwood added the in progress Actively being worked on (Kanban column) label Jun 15, 2017
@wjwwood wjwwood self-assigned this Jun 15, 2017
@wjwwood wjwwood force-pushed the refactor_get_topic_names_and_types branch from faa6768 to afe8c40 Compare June 15, 2017 10:13
@wjwwood wjwwood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jun 16, 2017
rmw_ret_t
rmw_get_service_names_and_types(
const rmw_node_t * node,
rcutils_allocator_t * allocator,
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: could that be a const pointer?

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'm not 100% sure. On the one hand the allocator's state is mutable (i.e. when someone calls .allocate it might change the internal state of the allocator), on the other the const in the strict functional sense (see: https://stackoverflow.com/questions/13181546/const-correctness-for-structs-with-pointers) will only restrict changing the function pointers in the allocator.

Here I was using non-const to indicate the allocator is not just "read" from, but instead it is "used" which in my mind is something like "written to".

In short, it could be but the rest of our code which takes an allocator pointer is already non-const to indicate the allocator might be mutated in the function.

If we can find reason is should be const, then I'd update all of them at once rather than just this function.

RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_names_and_types_fini(rmw_names_and_types_t * names_and_types);
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't that take an allocator as well?

// Use the allocator in the names string array
// (prevents this data structure from having to also store it)
names_and_types->names.allocator.deallocate(
names_and_types->types, names_and_types->names.allocator.state);
Copy link
Contributor

Choose a reason for hiding this comment

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

can there be a mismatch between this allocator and the allocator used for the init function?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I don't think so.

names_and_types->types = NULL;
}
// Cleanup names string array
rcutils_ret = rcutils_string_array_fini(&names_and_types->names);
Copy link
Contributor

Choose a reason for hiding this comment

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

@wjwwood wjwwood merged commit 3daf02b into master Jun 17, 2017
@wjwwood wjwwood deleted the refactor_get_topic_names_and_types branch June 17, 2017 01:01
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Jun 17, 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.

2 participants