Return OK when finalizing zero-initialized contexts (#842)

Resolves #814

This is consistent behavior with finalizing other types of zero-initialized objects.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
This commit is contained in:
Jacob Perron 2020-10-27 18:50:26 -07:00 committed by Alejandro Hernández Cordero
parent 885fa21a89
commit 675dbac13f
3 changed files with 10 additions and 3 deletions

View file

@ -154,8 +154,9 @@ rcl_get_zero_initialized_context(void);
/** /**
* The context to be finalized must have been previously initialized with * The context to be finalized must have been previously initialized with
* `rcl_init()`, and then later invalidated with `rcl_shutdown()`. * `rcl_init()`, and then later invalidated with `rcl_shutdown()`.
* A zero-initialized context that has not been initialized can be finalized.
* If context is `NULL`, then `RCL_RET_INVALID_ARGUMENT` is returned. * If context is `NULL`, then `RCL_RET_INVALID_ARGUMENT` is returned.
* If context is zero-initialized, then `RCL_RET_INVALID_ARGUMENT` is returned. * If context is zero-initialized, then `RCL_RET_OK` is returned.
* If context is initialized and valid (`rcl_shutdown()` was not called on it), * If context is initialized and valid (`rcl_shutdown()` was not called on it),
* then `RCL_RET_INVALID_ARGUMENT` is returned. * then `RCL_RET_INVALID_ARGUMENT` is returned.
* *

View file

@ -49,8 +49,10 @@ rcl_ret_t
rcl_context_fini(rcl_context_t * context) rcl_context_fini(rcl_context_t * context)
{ {
RCL_CHECK_ARGUMENT_FOR_NULL(context, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(context, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_FOR_NULL_WITH_MSG( if (!context->impl) {
context->impl, "context is zero-initialized", return RCL_RET_INVALID_ARGUMENT); // Context is zero-initialized
return RCL_RET_OK;
}
if (rcl_context_is_valid(context)) { if (rcl_context_is_valid(context)) {
RCL_SET_ERROR_MSG("rcl_shutdown() not called on the given context"); RCL_SET_ERROR_MSG("rcl_shutdown() not called on the given context");
return RCL_RET_INVALID_ARGUMENT; return RCL_RET_INVALID_ARGUMENT;

View file

@ -142,6 +142,10 @@ TEST_F(CLASSNAME(TestContextFixture, RMW_IMPLEMENTATION), bad_fini) {
}); });
rcl_context_t context = rcl_get_zero_initialized_context(); rcl_context_t context = rcl_get_zero_initialized_context();
ret = rcl_context_fini(&context);
EXPECT_EQ(RCL_RET_OK, ret);
ret = rcl_init(0, nullptr, &init_options, &context); ret = rcl_init(0, nullptr, &init_options, &context);
EXPECT_EQ(RCL_RET_OK, ret); EXPECT_EQ(RCL_RET_OK, ret);