Skip to content

Commit

Permalink
Copy allocator passed in to clock init (#274)
Browse files Browse the repository at this point in the history
* Store allocator passed in to clock init

* Linter fix
  • Loading branch information
dhood authored Aug 1, 2018
1 parent b324f9d commit 3356bd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rcl/include/rcl/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef struct rcl_clock_t
rcl_ret_t (* get_now)(void * data, rcl_time_point_value_t * now);
// void (*set_now) (rcl_time_point_value_t);
void * data;
rcl_allocator_t * allocator;
rcl_allocator_t allocator;
} rcl_clock_t;

/// A single point in time, measured in nanoseconds, the reference point is based on the source.
Expand Down
16 changes: 11 additions & 5 deletions rcl/src/rcl/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ rcl_clock_init(
enum rcl_clock_type_t clock_type, rcl_clock_t * clock,
rcl_allocator_t * allocator)
{
RCL_CHECK_ARGUMENT_FOR_NULL(allocator, RCL_RET_INVALID_ARGUMENT, rcl_get_default_allocator());
RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
switch (clock_type) {
case RCL_CLOCK_UNINITIALIZED:
RCL_CHECK_ARGUMENT_FOR_NULL(
Expand All @@ -111,6 +111,8 @@ rcl_clock_fini(
rcl_clock_t * clock)
{
RCL_CHECK_ARGUMENT_FOR_NULL(clock, RCL_RET_INVALID_ARGUMENT, rcl_get_default_allocator());
RCL_CHECK_ALLOCATOR_WITH_MSG(&clock->allocator, "clock has invalid allocator",
return RCL_RET_ERROR);
switch (clock->type) {
case RCL_ROS_TIME:
return rcl_ros_clock_fini(clock);
Expand Down Expand Up @@ -138,7 +140,7 @@ rcl_ros_clock_init(
storage->active = false;
clock->get_now = rcl_get_ros_time;
clock->type = RCL_ROS_TIME;
clock->allocator = allocator;
clock->allocator = *allocator;
return RCL_RET_OK;
}

Expand All @@ -151,7 +153,11 @@ rcl_ros_clock_fini(
RCL_SET_ERROR_MSG("clock not of type RCL_ROS_TIME", rcl_get_default_allocator());
return RCL_RET_ERROR;
}
clock->allocator->deallocate((rcl_ros_clock_storage_t *)clock->data, clock->allocator->state);
if (!clock->data) {
RCL_SET_ERROR_MSG("clock data invalid", rcl_get_default_allocator());
return RCL_RET_ERROR;
}
clock->allocator.deallocate((rcl_ros_clock_storage_t *)clock->data, clock->allocator.state);
return RCL_RET_OK;
}

Expand All @@ -165,7 +171,7 @@ rcl_steady_clock_init(
rcl_init_generic_clock(clock);
clock->get_now = rcl_get_steady_time;
clock->type = RCL_STEADY_TIME;
clock->allocator = allocator;
clock->allocator = *allocator;
return RCL_RET_OK;
}

Expand All @@ -191,7 +197,7 @@ rcl_system_clock_init(
rcl_init_generic_clock(clock);
clock->get_now = rcl_get_system_time;
clock->type = RCL_SYSTEM_TIME;
clock->allocator = allocator;
clock->allocator = *allocator;
return RCL_RET_OK;
}

Expand Down

0 comments on commit 3356bd4

Please sign in to comment.