Waitset member allocation use rmw types (#190)

* allocate memory for rmw types and not rcl types in waitset RMW storage

* zero initialize memory on resize and clear

* add missing void * cast to make windows happy

* set mem after checking successful alloc and use right type for rmw storage

* another instance of cast to (rmw_ ## Type ## _t *) instead of (void *)
This commit is contained in:
Mikael Arguedas 2017-11-28 15:01:22 -08:00 committed by GitHub
parent 293aee7843
commit 80e500b771
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -283,7 +283,7 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al
memset( \ memset( \
wait_set->impl->RMWStorage, \ wait_set->impl->RMWStorage, \
0, \ 0, \
sizeof(rmw_ ## Type ## _t *) * wait_set->impl->RMWCount); \ sizeof(void *) * wait_set->impl->RMWCount); \
wait_set->impl->RMWCount = 0; wait_set->impl->RMWCount = 0;
#define SET_RESIZE(Type, ExtraDealloc, ExtraRealloc) \ #define SET_RESIZE(Type, ExtraDealloc, ExtraRealloc) \
@ -308,6 +308,7 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al
RCL_CHECK_FOR_NULL_WITH_MSG( \ RCL_CHECK_FOR_NULL_WITH_MSG( \
wait_set->Type ## s, "allocating memory failed", \ wait_set->Type ## s, "allocating memory failed", \
return RCL_RET_BAD_ALLOC, wait_set->impl->allocator); \ return RCL_RET_BAD_ALLOC, wait_set->impl->allocator); \
memset((void *)wait_set->Type ## s, 0, sizeof(rcl_ ## Type ## _t *) * size); \
wait_set->size_of_ ## Type ## s = size; \ wait_set->size_of_ ## Type ## s = size; \
ExtraRealloc \ ExtraRealloc \
} \ } \
@ -324,13 +325,14 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al
/* Also resize the rmw storage. */ \ /* Also resize the rmw storage. */ \
wait_set->impl->RMWCount = 0; \ wait_set->impl->RMWCount = 0; \
wait_set->impl->RMWStorage = (void **)allocator.reallocate( \ wait_set->impl->RMWStorage = (void **)allocator.reallocate( \
wait_set->impl->RMWStorage, sizeof(rcl_ ## Type ## _t *) * size, allocator.state); \ wait_set->impl->RMWStorage, sizeof(void *) * size, allocator.state); \
if (!wait_set->impl->RMWStorage) { \ if (!wait_set->impl->RMWStorage) { \
allocator.deallocate((void *)wait_set->Type ## s, allocator.state); \ allocator.deallocate((void *)wait_set->Type ## s, allocator.state); \
wait_set->size_of_ ## Type ## s = 0; \ wait_set->size_of_ ## Type ## s = 0; \
RCL_SET_ERROR_MSG("allocating memory failed", wait_set->impl->allocator); \ RCL_SET_ERROR_MSG("allocating memory failed", wait_set->impl->allocator); \
return RCL_RET_BAD_ALLOC; \ return RCL_RET_BAD_ALLOC; \
} } \
memset(wait_set->impl->RMWStorage, 0, sizeof(void *) * size);
/* Implementation-specific notes: /* Implementation-specific notes:
* *