-
Notifications
You must be signed in to change notification settings - Fork 33
API changes to sync with one Participant per Context change in rmw_fastrtps #392
Conversation
0835337
to
bada946
Compare
@@ -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; |
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.
@ivanpauno hmm const pointer
? I would've thought it should've been a mutable reference
.
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 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.
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 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.
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 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.
|
||
if (security_context_found != map.end()) { | ||
security_context = std::string( | ||
security_context_found->second.begin(), security_context_found->second.end()); |
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.
@ivanpauno this is a peculiar way of copying an std::string
and I suspect less efficient than a plain copy-assignment.
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.
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 peculiar API. I wonder why a sequence of bytes. Is it to support other encodings in the future? cc @dirk-thomas
0ca853b
to
c410e96
Compare
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 though I have a few questions.
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); | ||
} |
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.
@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.
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 completely agree.
I will open an issue for this, because it's out of the scope of this PR IMO.
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
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( |
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.
@ivanpauno uh, why the added prefix?
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.
Also, I just remembered that rcutils
has a portable snprintf
flavor.
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.
@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?
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.
Not surprisingly, there's something peculiar about using snprintf
in Windows. But @wjwwood may have deeper insight.
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 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.
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.
Fair enough. I won't block on it, though now I'm curious about rcutils_snprintf
.
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.
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.
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
3d53faf
to
5726630
Compare
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
Needed since ros2/rmw#189.