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

Don't call rcl_logging_configure/rcl_logging_fini in rcl_init/rcl_shutdown #579

Merged
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
27 changes: 26 additions & 1 deletion rcl/include/rcl/init_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,39 @@ rcl_init_options_fini(rcl_init_options_t * init_options);
* Lock-Free | Yes
*
* \param[in] init_options object from which the rmw init options should be retrieved
* \return pointer to the the rmw init options, or
* \return pointer to the the rcl init options, or
* \return `NULL` if there was an error
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rmw_init_options_t *
rcl_init_options_get_rmw_init_options(rcl_init_options_t * init_options);

/// Return the allocator stored in the init_options.
/**
* This function can fail and return `NULL` if:
* - init_options is NULL
* - init_options is invalid, e.g. init_options->impl is NULL
*
* If NULL is returned an error message will have been set.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] init_options object from which the allocator should be retrieved
* \return pointer to the rcl allocator, or
* \return `NULL` if there was an error
*/
RCL_PUBLIC
RCL_WARN_UNUSED
const rcl_allocator_t *
rcl_init_options_get_allocator(const rcl_init_options_t * init_options);
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved

#ifdef __cplusplus
}
#endif
Expand Down
17 changes: 0 additions & 17 deletions rcl/src/rcl/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,6 @@ rcl_init(
goto fail;
}

ret = rcl_logging_configure(&context->global_arguments, &allocator);
if (RCL_RET_OK != ret) {
fail_ret = ret;
RCUTILS_LOG_ERROR_NAMED(
ROS_PACKAGE_NAME,
"Failed to configure logging: %s",
rcutils_get_error_string().str);
goto fail;
}

// Set the instance id.
uint64_t next_instance_id = rcutils_atomic_fetch_add_uint64_t(&__rcl_next_unique_id, 1);
if (0 == next_instance_id) {
Expand Down Expand Up @@ -260,13 +250,6 @@ rcl_shutdown(rcl_context_t * context)
return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
}

rcl_ret_t rcl_ret = rcl_logging_fini();
RCUTILS_LOG_ERROR_EXPRESSION_NAMED(
RCL_RET_OK != rcl_ret, ROS_PACKAGE_NAME,
"Failed to fini logging, rcl_ret_t: %i, rcl_error_str: %s", rcl_ret,
rcl_get_error_string().str);
rcl_reset_error();

return RCL_RET_OK;
}

Expand Down
8 changes: 8 additions & 0 deletions rcl/src/rcl/init_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ rcl_init_options_get_rmw_init_options(rcl_init_options_t * init_options)
return &(init_options->impl->rmw_init_options);
}

const rcl_allocator_t *
rcl_init_options_get_allocator(const rcl_init_options_t * init_options)
{
RCL_CHECK_ARGUMENT_FOR_NULL(init_options, NULL);
RCL_CHECK_ARGUMENT_FOR_NULL(init_options->impl, NULL);
return &(init_options->impl->allocator);
}

#ifdef __cplusplus
}
#endif
7 changes: 7 additions & 0 deletions rcl/test/rcl/test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "rcl/error_handling.h"
#include "rcl/graph.h"
#include "rcl/logging.h"
#include "rcl/rcl.h"

#include "rcutils/logging_macros.h"
Expand Down Expand Up @@ -66,6 +67,7 @@ class CLASSNAME (TestGraphFixture, RMW_IMPLEMENTATION) : public ::testing::Test
void SetUp()
{
rcl_ret_t ret;
rcl_allocator_t allocator = rcl_get_default_allocator();
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
ret = rcl_init_options_init(&init_options, rcl_get_default_allocator());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
Expand All @@ -77,6 +79,10 @@ class CLASSNAME (TestGraphFixture, RMW_IMPLEMENTATION) : public ::testing::Test
*this->old_context_ptr = rcl_get_zero_initialized_context();
ret = rcl_init(0, nullptr, &init_options, this->old_context_ptr);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
EXPECT_EQ(
RCL_RET_OK,
rcl_logging_configure(&this->old_context_ptr->global_arguments, &allocator)
) << rcl_get_error_string().str;
this->old_node_ptr = new rcl_node_t;
*this->old_node_ptr = rcl_get_zero_initialized_node();
const char * old_name = "old_node_name";
Expand Down Expand Up @@ -127,6 +133,7 @@ class CLASSNAME (TestGraphFixture, RMW_IMPLEMENTATION) : public ::testing::Test
ret = rcl_context_fini(this->old_context_ptr);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
delete this->old_context_ptr;
EXPECT_EQ(RCL_RET_OK, rcl_logging_fini()) << rcl_get_error_string().str;
}
};

Expand Down
10 changes: 9 additions & 1 deletion rcl/test/rcl/test_logging_rosout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "osrf_testing_tools_cpp/scope_exit.hpp"
#include "rcl/error_handling.h"
#include "rcl/logging.h"
#include "rcl/rcl.h"
#include "rcl/subscription.h"
#include "rcl_interfaces/msg/log.h"
Expand Down Expand Up @@ -70,8 +71,9 @@ class TEST_FIXTURE_P_RMW (TestLoggingRosoutFixture)
{
auto param = GetParam();
rcl_ret_t ret;
rcl_allocator_t allocator = rcl_get_default_allocator();
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
ret = rcl_init_options_init(&init_options, rcl_get_default_allocator());
ret = rcl_init_options_init(&init_options, allocator);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
Expand All @@ -83,6 +85,11 @@ class TEST_FIXTURE_P_RMW (TestLoggingRosoutFixture)
ret = rcl_init(param.argc, param.argv, &init_options, this->context_ptr);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;

EXPECT_EQ(
RCL_RET_OK,
rcl_logging_configure(&this->context_ptr->global_arguments, &allocator)
) << rcl_get_error_string().str;

// create node
rcl_node_options_t node_options = rcl_node_get_default_options();
if (!param.enable_node_option_rosout) {
Expand Down Expand Up @@ -120,6 +127,7 @@ class TEST_FIXTURE_P_RMW (TestLoggingRosoutFixture)
ret = rcl_context_fini(this->context_ptr);
delete this->context_ptr;
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_OK, rcl_logging_fini()) << rcl_get_error_string().str;
}

protected:
Expand Down