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

Save allocator for RCL_CLOCK_UNINITIALIZED clock. #623

Merged
merged 5 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 6 additions & 8 deletions rcl/src/rcl/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ rcl_get_system_time(void * data, rcl_time_point_value_t * current_time)

// Internal method for zeroing values on init, assumes clock is valid
static void
rcl_init_generic_clock(rcl_clock_t * clock)
rcl_init_generic_clock(rcl_clock_t * clock, rcl_allocator_t * allocator)
{
clock->type = RCL_CLOCK_UNINITIALIZED;
clock->jump_callbacks = NULL;
clock->num_jump_callbacks = 0u;
clock->get_now = NULL;
clock->data = NULL;
clock->allocator = *allocator;
}

// The function used to get the current ros time.
Expand Down Expand Up @@ -91,7 +92,7 @@ rcl_clock_init(
switch (clock_type) {
case RCL_CLOCK_UNINITIALIZED:
RCL_CHECK_ARGUMENT_FOR_NULL(clock, RCL_RET_INVALID_ARGUMENT);
rcl_init_generic_clock(clock);
rcl_init_generic_clock(clock, allocator);
return RCL_RET_OK;
case RCL_ROS_TIME:
return rcl_ros_clock_init(clock, allocator);
Expand Down Expand Up @@ -144,7 +145,7 @@ rcl_ros_clock_init(
{
RCL_CHECK_ARGUMENT_FOR_NULL(clock, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(allocator, RCL_RET_INVALID_ARGUMENT);
rcl_init_generic_clock(clock);
rcl_init_generic_clock(clock, allocator);
Blast545 marked this conversation as resolved.
Show resolved Hide resolved
clock->data = allocator->allocate(sizeof(rcl_ros_clock_storage_t), allocator->state);
if (NULL == clock->data) {
RCL_SET_ERROR_MSG("allocating memory failed");
Expand All @@ -157,7 +158,6 @@ rcl_ros_clock_init(
storage->active = false;
clock->get_now = rcl_get_ros_time;
clock->type = RCL_ROS_TIME;
clock->allocator = *allocator;
return RCL_RET_OK;
}

Expand Down Expand Up @@ -186,10 +186,9 @@ rcl_steady_clock_init(
{
RCL_CHECK_ARGUMENT_FOR_NULL(clock, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(allocator, RCL_RET_INVALID_ARGUMENT);
rcl_init_generic_clock(clock);
rcl_init_generic_clock(clock, allocator);
clock->get_now = rcl_get_steady_time;
clock->type = RCL_STEADY_TIME;
clock->allocator = *allocator;
return RCL_RET_OK;
}

Expand All @@ -213,10 +212,9 @@ rcl_system_clock_init(
{
RCL_CHECK_ARGUMENT_FOR_NULL(clock, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(allocator, RCL_RET_INVALID_ARGUMENT);
rcl_init_generic_clock(clock);
rcl_init_generic_clock(clock, allocator);
clock->get_now = rcl_get_system_time;
clock->type = RCL_SYSTEM_TIME;
clock->allocator = *allocator;
return RCL_RET_OK;
}

Expand Down
6 changes: 4 additions & 2 deletions rcl/test/rcl/test_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ TEST(CLASSNAME(rcl_time, RMW_IMPLEMENTATION), specific_clock_instantiation) {
rcl_allocator_t allocator = rcl_get_default_allocator();
{
rcl_clock_t uninitialized_clock;
rcl_ret_t ret = rcl_clock_init(
RCL_CLOCK_UNINITIALIZED, &uninitialized_clock, &allocator);
rcl_ret_t ret = rcl_clock_init(RCL_CLOCK_UNINITIALIZED, &uninitialized_clock, &allocator);
Blast545 marked this conversation as resolved.
Show resolved Hide resolved
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
EXPECT_EQ(uninitialized_clock.type, RCL_CLOCK_UNINITIALIZED) <<
"Expected time source of type RCL_CLOCK_UNINITIALIZED";
ret = rcl_clock_fini(&uninitialized_clock);
EXPECT_EQ(ret, RCL_RET_INVALID_ARGUMENT) << rcl_get_error_string().str;
rcl_reset_error();
Copy link
Member

Choose a reason for hiding this comment

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

This is ok, but it still seems unrelated to the PR.
You can add a RCUTILS_CHECK_ALLOCATOR_IS_VALID check after initializing the clock, to test this modification.

Copy link
Contributor Author

@Blast545 Blast545 Apr 21, 2020

Choose a reason for hiding this comment

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

Changed in ce8d867

}
{
rcl_clock_t ros_clock;
Expand Down