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

Return OK when finalizing zero-initialized contexts #842

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion rcl/include/rcl/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ rcl_get_zero_initialized_context(void);
/**
* The context to be finalized must have been previously initialized with
* `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 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),
* then `RCL_RET_INVALID_ARGUMENT` is returned.
*
Expand Down
6 changes: 4 additions & 2 deletions rcl/src/rcl/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ rcl_ret_t
rcl_context_fini(rcl_context_t * context)
{
RCL_CHECK_ARGUMENT_FOR_NULL(context, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_FOR_NULL_WITH_MSG(
context->impl, "context is zero-initialized", return RCL_RET_INVALID_ARGUMENT);
if (!context->impl) {
// Context is zero-initialized
return RCL_RET_OK;
}
if (rcl_context_is_valid(context)) {
RCL_SET_ERROR_MSG("rcl_shutdown() not called on the given context");
return RCL_RET_INVALID_ARGUMENT;
Expand Down
4 changes: 4 additions & 0 deletions rcl/test/rcl/test_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ TEST_F(CLASSNAME(TestContextFixture, RMW_IMPLEMENTATION), bad_fini) {
});

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);
EXPECT_EQ(RCL_RET_OK, ret);

Expand Down