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

Rename rmw_topic_endpoint_info_array count to size, and initialize it #196

Merged
merged 4 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions rmw/include/rmw/topic_endpoint_info_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C"
typedef struct RMW_PUBLIC_TYPE rmw_topic_endpoint_info_array_t
{
/// Size of the array.
size_t count;
size_t size;
/// Pointer representing an array of rmw_topic_endpoint_info_t
rmw_topic_endpoint_info_t * info_array;
} rmw_topic_endpoint_info_array_t;
Expand Down Expand Up @@ -60,6 +60,7 @@ rmw_topic_endpoint_info_array_check_zero(
* type rmw_topic_endpoint_info_t.
* This function allocates memory to this array to hold n elements,
* where n is the value of the size param to this function.
* The member `size` is updated accordingly.
*
* topic_endpoint_info_array must be zero initialized before being passed into this function.
*
Expand All @@ -85,7 +86,7 @@ rmw_topic_endpoint_info_array_init_with_size(
* The info_array member variable inside of rmw_topic_endpoint_info_array represents an array of
* rmw_topic_endpoint_info_t.
* When initializing this array, memory is allocated for it using the allocator.
* This function reclaims any allocated resources within the object and also sets the value of count
* This function reclaims any allocated resources within the object and also sets the value of size
* to 0.
*
* \param[inout] topic_endpoint_info_array object to be finalized
Expand Down
9 changes: 6 additions & 3 deletions rmw/src/topic_endpoint_info_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rmw_topic_endpoint_info_array_check_zero(
RMW_SET_ERROR_MSG("topic_endpoint_info_array is null");
return RMW_RET_INVALID_ARGUMENT;
}
if (topic_endpoint_info_array->count != 0 || topic_endpoint_info_array->info_array != NULL) {
if (topic_endpoint_info_array->size != 0 || topic_endpoint_info_array->info_array != NULL) {
RMW_SET_ERROR_MSG("topic_endpoint_info_array is not zeroed");
return RMW_RET_ERROR;
}
Expand All @@ -65,6 +65,9 @@ rmw_topic_endpoint_info_array_init_with_size(
RMW_SET_ERROR_MSG("failed to allocate memory for info_array");
return RMW_RET_BAD_ALLOC;
}
for (size_t i = 0; i < size; i++) {
topic_endpoint_info_array->info_array[i] = rmw_get_zero_initialized_topic_endpoint_info();
}
return RMW_RET_OK;
}

Expand All @@ -85,7 +88,7 @@ rmw_topic_endpoint_info_array_fini(

rmw_ret_t ret;
// free all const char * inside the topic_endpoint_info_t
for (size_t i = 0u; i < topic_endpoint_info_array->count; i++) {
for (size_t i = 0u; i < topic_endpoint_info_array->size; i++) {
ret = rmw_topic_endpoint_info_fini(&topic_endpoint_info_array->info_array[i], allocator);
if (ret != RMW_RET_OK) {
return ret;
Expand All @@ -94,6 +97,6 @@ rmw_topic_endpoint_info_array_fini(

allocator->deallocate(topic_endpoint_info_array->info_array, allocator->state);
topic_endpoint_info_array->info_array = NULL;
topic_endpoint_info_array->count = 0;
topic_endpoint_info_array->size = 0;
return RMW_RET_OK;
}
6 changes: 3 additions & 3 deletions rmw/test/test_topic_endpoint_info_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

TEST(test_topic_endpoint_info_array, zero_initialize) {
rmw_topic_endpoint_info_array_t arr = rmw_get_zero_initialized_topic_endpoint_info_array();
EXPECT_EQ(arr.count, 0u);
EXPECT_EQ(arr.size, 0u);
EXPECT_FALSE(arr.info_array);
}

TEST(test_topic_endpoint_info_array, check_zero) {
rmw_topic_endpoint_info_array_t arr = rmw_get_zero_initialized_topic_endpoint_info_array();
EXPECT_EQ(rmw_topic_endpoint_info_array_check_zero(&arr), RMW_RET_OK);
rmw_topic_endpoint_info_array_t arr_count_not_zero = {1, nullptr};
EXPECT_EQ(rmw_topic_endpoint_info_array_check_zero(&arr_count_not_zero), RMW_RET_ERROR);
rmw_topic_endpoint_info_array_t arr_size_not_zero = {1, nullptr};
EXPECT_EQ(rmw_topic_endpoint_info_array_check_zero(&arr_size_not_zero), RMW_RET_ERROR);
rmw_topic_endpoint_info_t topic_endpoint_info;
rmw_topic_endpoint_info_array_t arr_info_array_not_null = {0, &topic_endpoint_info};
EXPECT_EQ(rmw_topic_endpoint_info_array_check_zero(&arr_info_array_not_null), RMW_RET_ERROR);
Expand Down