Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

API changes to sync with one Participant per Context change in rmw_fastrtps #392

Merged
merged 7 commits into from
Apr 3, 2020

Conversation

ivanpauno
Copy link
Member

Needed since ros2/rmw#189.

@ivanpauno ivanpauno added the in review Waiting for review (Kanban column) label Feb 28, 2020
@ivanpauno ivanpauno self-assigned this Feb 28, 2020
@ivanpauno ivanpauno changed the title Rename rmw_node_security_options_t to rmw_security_options_t API changes to sync with one Participant per Context change in rmw_fastrtps Mar 4, 2020
@ivanpauno ivanpauno force-pushed the ivanpauno/one-participant-per-context branch from 0835337 to bada946 Compare March 13, 2020 16:42
@@ -51,20 +57,38 @@ rmw_init_options_copy(const rmw_init_options_t * src, rmw_init_options_t * dst)
RMW_SET_ERROR_MSG("expected zero-initialized dst");
return RMW_RET_INVALID_ARGUMENT;
}
const rcutils_allocator_t * allocator = &src->allocator;
Copy link
Contributor

Choose a reason for hiding this comment

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

@ivanpauno hmm const pointer? I would've thought it should've been a mutable reference.

Copy link
Member Author

@ivanpauno ivanpauno Mar 20, 2020

Choose a reason for hiding this comment

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

I can use a reference instead of a pointer.
About constness, we've some functions that take a const pointer, there are others taking it by value, and others taking a mutable pointer.

In the first and last case, you can do:

allocator->allocate(size, allocator->state);

In the second case, you can replace -> with ..

Why does this work? I will have to check, but I think that C structs constness is not propagated to its members. So, it doesn't matter that allocate takes a mutable pointer to state.

edit: I think my comment applies to both C and C++, if you have public member that it's a pointer constness is not propagated.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can use a reference instead of a pointer.

I was mostly interested in the rationale behind explicitly introducing an indirection.

About constness, we've some functions that take a const pointer, there are others taking it by value, and others taking a mutable pointer.

I'm aware of how allocators are passed in all forms and colors here and there. That's something we can discuss in a follow-up issue though.

Why does this work? I will have to check, but I think that C structs constness is not propagated to its members. So, it doesn't matter that allocate takes a mutable pointer to state.

A const qualified struct in C/C++ implies that none of its members can be mutated. In the case you mention, you're actually not mutating state, the pointer. AFAIK cv-qualifiers do not propagate through indirections. That's why a const std::shared_ptr<SomeObject> will happily let you mutate SomeObject, whereas const std::shared_ptr<const SomeObject> will likely get you what you want.

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 was mostly interested in the rationale behind explicitly introducing an indirection.

Ok, I can use a reference if you want.

I'm aware of how allocators are passed in all forms and colors here and there. That's something we can discuss in a follow-up issue though.

👍

A const qualified struct in C/C++ implies that none of its members can be mutated. In the case you mention, you're actually not mutating state, the pointer. AFAIK cv-qualifiers do not propagate through indirections. That's why a const std::shared_ptr will happily let you mutate SomeObject, whereas const std::shared_ptr will likely get you what you want.

Yes, exactly. I misunderstood your first comment and derailed a bit.

rmw_connext_shared_cpp/src/node.cpp Outdated Show resolved Hide resolved

if (security_context_found != map.end()) {
security_context = std::string(
security_context_found->second.begin(), security_context_found->second.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

@ivanpauno this is a peculiar way of copying an std::string and I suspect less efficient than a plain copy-assignment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a peculiar API. I wonder why a sequence of bytes. Is it to support other encodings in the future? cc @dirk-thomas

@ivanpauno ivanpauno force-pushed the ivanpauno/one-participant-per-context branch from 0ca853b to c410e96 Compare March 19, 2020 21:33
@ivanpauno ivanpauno requested a review from hidmic March 25, 2020 17:53
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM though I have a few questions.

rmw_connext_shared_cpp/src/node.cpp Outdated Show resolved Hide resolved
for (auto i = 0; i < named_nodes_num; ++i) {
node_names->data[i] = rcutils_strdup(tmp_names_list.data[i], allocator);
node_namespaces->data[i] = rcutils_strdup(tmp_namespaces_list.data[i], allocator);
if (security_contexts) {
security_contexts->data[i] = rcutils_strdup(tmp_security_contexts_list.data[i], allocator);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@ivanpauno meta: this predates your PR, but why does this code assume that rcutils_strdup will succeed? Also, simply moving strings in tmp arrays would be much more efficient than this (de)allocation dance.

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 completely agree.
I will open an issue for this, because it's out of the scope of this PR IMO.

@ivanpauno ivanpauno requested a review from hidmic March 26, 2020 17:54
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM

bool success = participant_qos.user_data.value.length(static_cast<DDS::Long>(length));
if (!success) {
RMW_SET_ERROR_MSG("failed to resize participant user_data");
return NULL;
}

int written = snprintf(
int written = std::snprintf(
Copy link
Contributor

Choose a reason for hiding this comment

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

@ivanpauno uh, why the added prefix?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I just remembered that rcutils has a portable snprintf flavor.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ivanpauno uh, why the added prefix?

it's not really needed. I can delete it again.

Also, I just remembered that rcutils has a portable snprintf flavor.

This seems to be portable, as it's currently working fine.
Do you know the rationale of having a rcutils flavor?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not surprisingly, there's something peculiar about using snprintf in Windows. But @wjwwood may have deeper insight.

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 mean, this code is passing CI on Windows with master, which does the same thing.
If CI is green, I wouldn't change anything else.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. I won't block on it, though now I'm curious about rcutils_snprintf.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe the std:: avoids it but on Windows it will usually generate a compiler warning if you try to use snprintf directly. Or at least that’s my recollection.

Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM

@ivanpauno ivanpauno merged commit 1b26f31 into master Apr 3, 2020
@delete-merged-branch delete-merged-branch bot deleted the ivanpauno/one-participant-per-context branch April 3, 2020 13:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in review Waiting for review (Kanban column)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants