@@ -34,6 +34,22 @@ rcl_get_zero_initialized_init_options(void)
3434 }; // NOLINT(readability/braces): false positive
3535}
3636
37+ /// Initialize given init_options with the default values and zero-initialize implementation.
38+ RCL_LOCAL
39+ rcl_ret_t
40+ _rcl_init_options_init (rcl_init_options_t * init_options , rcl_allocator_t allocator )
41+ {
42+ init_options -> impl = allocator .allocate (sizeof (rcl_init_options_impl_t ), allocator .state );
43+ RCL_CHECK_FOR_NULL_WITH_MSG (
44+ init_options -> impl ,
45+ "failed to allocate memory for init options impl" ,
46+ return RCL_RET_BAD_ALLOC );
47+ init_options -> impl -> allocator = allocator ;
48+ init_options -> impl -> rmw_init_options = rmw_get_zero_initialized_init_options ();
49+
50+ return RCL_RET_OK ;
51+ }
52+
3753rcl_ret_t
3854rcl_init_options_init (rcl_init_options_t * init_options , rcl_allocator_t allocator )
3955{
@@ -48,13 +64,11 @@ rcl_init_options_init(rcl_init_options_t * init_options, rcl_allocator_t allocat
4864 return RCL_RET_ALREADY_INIT ;
4965 }
5066 RCL_CHECK_ALLOCATOR (& allocator , return RCL_RET_INVALID_ARGUMENT );
51- init_options -> impl = allocator .allocate (sizeof (rcl_init_options_impl_t ), allocator .state );
52- RCL_CHECK_FOR_NULL_WITH_MSG (
53- init_options -> impl ,
54- "failed to allocate memory for init options impl" ,
55- return RCL_RET_BAD_ALLOC );
56- init_options -> impl -> allocator = allocator ;
57- init_options -> impl -> rmw_init_options = rmw_get_zero_initialized_init_options ();
67+
68+ rcl_ret_t ret = _rcl_init_options_init (init_options , allocator );
69+ if (RCL_RET_OK != ret ) {
70+ return ret ;
71+ }
5872 rmw_ret_t rmw_ret = rmw_init_options_init (& (init_options -> impl -> rmw_init_options ), allocator );
5973 if (RMW_RET_OK != rmw_ret ) {
6074 allocator .deallocate (init_options -> impl , allocator .state );
@@ -74,14 +88,15 @@ rcl_init_options_copy(const rcl_init_options_t * src, rcl_init_options_t * dst)
7488
7589 RCL_CHECK_ARGUMENT_FOR_NULL (src , RCL_RET_INVALID_ARGUMENT );
7690 RCL_CHECK_ARGUMENT_FOR_NULL (src -> impl , RCL_RET_INVALID_ARGUMENT );
91+ RCL_CHECK_ALLOCATOR (& src -> impl -> allocator , return RCL_RET_INVALID_ARGUMENT );
7792 RCL_CHECK_ARGUMENT_FOR_NULL (dst , RCL_RET_INVALID_ARGUMENT );
7893 if (NULL != dst -> impl ) {
7994 RCL_SET_ERROR_MSG ("given dst (rcl_init_options_t) is already initialized" );
8095 return RCL_RET_ALREADY_INIT ;
8196 }
8297
8398 // initialize dst (since we know it's in a zero initialized state)
84- rcl_ret_t ret = rcl_init_options_init (dst , src -> impl -> allocator );
99+ rcl_ret_t ret = _rcl_init_options_init (dst , src -> impl -> allocator );
85100 if (RCL_RET_OK != ret ) {
86101 return ret ; // error already set
87102 }
0 commit comments