Skip to content

Commit

Permalink
Zero init topic names and types (ros2#85)
Browse files Browse the repository at this point in the history
* initialize topic_names_and_type struct in rcl

* sanity check in get_topic_names_and_types

* uncrustify

* initialize all fields...

* address documentation request

* typo
  • Loading branch information
mikaelarguedas authored Oct 28, 2016
1 parent 7661ab2 commit 32bcd0d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
10 changes: 8 additions & 2 deletions rcl/include/rcl/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ extern "C"

typedef rmw_topic_names_and_types_t rcl_topic_names_and_types_t;


/// Return a rcl_topic_names_and_types_t struct with members initialized to NULL.
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_topic_names_and_types_t
rcl_get_zero_initialized_topic_names_and_types(void);

/// Return a list of topic names and their types.
/* This function returns a list of topic names in the ROS graph and their types.
*
* The node parameter must not be NULL, and must point to a valid node.
*
* The topic_names_and_types parameter must not be NULL, and must point to an
* already allocated rcl_topic_names_and_types_t struct.
* The topic_names_and_types parameter must be allocated and zero initialized.
* The topic_names_and_types is the output for this function, and contains
* allocated memory.
* Therefore, it should be passed to rcl_destroy_topic_names_and_types() when
Expand Down
2 changes: 1 addition & 1 deletion rcl/include/rcl/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ rcl_get_zero_initialized_node(void);
* This function will create those external parameter interfaces even if
* parameters are not used later.
*
* The rcl_node_t given must be allocated and zero initalized.
* The rcl_node_t given must be allocated and zero initialized.
* Passing an rcl_node_t which has already had this function called on it, more
* recently than rcl_node_fini, will fail.
* An allocated rcl_node_t with uninitialized memory is undefined behavior.
Expand Down
19 changes: 19 additions & 0 deletions rcl/src/rcl/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ extern "C"

#include "./common.h"

rcl_topic_names_and_types_t
rcl_get_zero_initialized_topic_names_and_types(void)
{
const rcl_topic_names_and_types_t null_topic_names_and_types = {0, NULL, NULL};
return null_topic_names_and_types;
}

rcl_ret_t
rcl_get_topic_names_and_types(
const rcl_node_t * node,
Expand All @@ -31,6 +38,18 @@ rcl_get_topic_names_and_types(
return RCL_RET_NODE_INVALID;
}
RCL_CHECK_ARGUMENT_FOR_NULL(topic_names_and_types, RCL_RET_INVALID_ARGUMENT);
if (topic_names_and_types->topic_count != 0) {
RCL_SET_ERROR_MSG("topic count is not zero");
return RCL_RET_INVALID_ARGUMENT;
}
if (topic_names_and_types->topic_names) {
RCL_SET_ERROR_MSG("topic names is not null");
return RCL_RET_INVALID_ARGUMENT;
}
if (topic_names_and_types->type_names) {
RCL_SET_ERROR_MSG("type names is not null");
return RCL_RET_INVALID_ARGUMENT;
}
return rmw_get_topic_names_and_types(
rcl_node_get_rmw_handle(node),
topic_names_and_types
Expand Down

0 comments on commit 32bcd0d

Please sign in to comment.