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

get_zero_initialized_xxx functions return zero initialized structure. #380

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion rmw/include/rmw/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ extern "C"
/// Define publisher/subscription events
typedef enum rmw_event_type_e
{
// initial value
RMW_EVENT_INVALID,

// subscription events
RMW_EVENT_LIVELINESS_CHANGED,
RMW_EVENT_REQUESTED_DEADLINE_MISSED,
Expand All @@ -48,7 +51,7 @@ typedef enum rmw_event_type_e
RMW_EVENT_PUBLICATION_MATCHED,

// sentinel value
RMW_EVENT_INVALID
RMW_EVENT_TYPE_MAX
} rmw_event_type_t;

/// Encapsulate the RMW event implementation, data, and type.
Expand Down
9 changes: 2 additions & 7 deletions rmw/src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ extern "C" {
rmw_event_t
rmw_get_zero_initialized_event(void)
{
// TODO(@fujitatomoya): This is not exatly zero initialized structure.
/// We should introduce xxx_get_default_event to return the default values.
static const rmw_event_t event = {
.implementation_identifier = NULL,
.data = NULL,
.event_type = RMW_EVENT_INVALID
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
};
// All members are initialized to 0 or NULL by C99 6.7.8/10.
static const rmw_event_t event;
return event;
}

Expand Down
10 changes: 3 additions & 7 deletions rmw/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ extern "C"
rmw_context_t
rmw_get_zero_initialized_context(void)
{
return (const rmw_context_t) {
.instance_id = 0,
.implementation_identifier = NULL,
.options = rmw_get_zero_initialized_init_options(),
.actual_domain_id = 0u,
.impl = NULL
}; // NOLINT(readability/braces): false positive
// All members are initialized to 0 or NULL by C99 6.7.8/10.
static const rmw_context_t context;
return context;
}

#ifdef __cplusplus
Expand Down
13 changes: 2 additions & 11 deletions rmw/src/init_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@ extern "C"
rmw_init_options_t
rmw_get_zero_initialized_init_options(void)
{
// TODO(@fujitatomoya): This is not exatly zero initialized structure.
/// We should introduce xxx_get_default_init_optionst to return the default values.
static const rmw_init_options_t init_option = {
.domain_id = RMW_DEFAULT_DOMAIN_ID,
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
.discovery_options = {RMW_AUTOMATIC_DISCOVERY_RANGE_NOT_SET, 0},
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
.implementation_identifier = NULL,
.impl = NULL,
.instance_id = 0,
.enclave = NULL,
.security_options = {RMW_SECURITY_ENFORCEMENT_PERMISSIVE, NULL},
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
};
// All members are initialized to 0 or NULL by C99 6.7.8/10.
static const rmw_init_options_t init_option;
return init_option;
}

Expand Down
2 changes: 2 additions & 0 deletions rmw/test/test_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ TEST(rmw_init_options, get_zero_initialized_init_options)
{
const rmw_context_t context = rmw_get_zero_initialized_context();
EXPECT_EQ(context.instance_id, 0u);
EXPECT_EQ(context.implementation_identifier, nullptr);
EXPECT_EQ(context.actual_domain_id, 0u);
EXPECT_EQ(context.impl, nullptr);
}
2 changes: 2 additions & 0 deletions rmw/test/test_init_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
TEST(rmw_init_options, get_zero_initialized_init_options)
{
const rmw_init_options_t options = rmw_get_zero_initialized_init_options();
EXPECT_EQ(options.domain_id, 0u);
EXPECT_EQ(options.instance_id, 0u);
EXPECT_EQ(options.implementation_identifier, nullptr);
EXPECT_EQ(options.impl, nullptr);
EXPECT_EQ(options.enclave, nullptr);
}