Skip to content

Commit

Permalink
code style only: wrap after open parenthesis if not in one line (#203)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
  • Loading branch information
dirk-thomas authored Feb 3, 2020
1 parent 8f2d2b9 commit d7bd057
Show file tree
Hide file tree
Showing 14 changed files with 502 additions and 294 deletions.
3 changes: 2 additions & 1 deletion include/rcutils/error_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin
* \param[in] error_return_type The type to return if the argument is `NULL`.
*/
#define RCUTILS_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type) \
RCUTILS_CHECK_FOR_NULL_WITH_MSG(argument, #argument " argument is null", \
RCUTILS_CHECK_FOR_NULL_WITH_MSG( \
argument, #argument " argument is null", \
return error_return_type)

/// Check a value for null, with an error message and error statement.
Expand Down
9 changes: 6 additions & 3 deletions src/char_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ rcutils_char_array_init(
const rcutils_allocator_t * allocator)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(char_array, RCUTILS_RET_ERROR);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(allocator, "char array has no valid allocator",
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
allocator, "char array has no valid allocator",
return RCUTILS_RET_ERROR);

char_array->owns_buffer = true;
Expand Down Expand Up @@ -67,7 +68,8 @@ rcutils_char_array_fini(rcutils_char_array_t * char_array)

if (char_array->owns_buffer) {
rcutils_allocator_t * allocator = &char_array->allocator;
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(allocator, "char array has no valid allocator",
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
allocator, "char array has no valid allocator",
return RCUTILS_RET_ERROR);

allocator->deallocate(char_array->buffer, allocator->state);
Expand All @@ -91,7 +93,8 @@ rcutils_char_array_resize(rcutils_char_array_t * char_array, size_t new_size)
}

rcutils_allocator_t * allocator = &char_array->allocator;
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(allocator, "char array has no valid allocator",
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
allocator, "char array has no valid allocator",
return RCUTILS_RET_ERROR);

if (new_size == char_array->buffer_capacity) {
Expand Down
37 changes: 20 additions & 17 deletions src/error_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ __format_overwriting_error_state_message(
size_t written = 0;

// write the first static part of the error message
written = __rcutils_copy_string(offset, bytes_left,
"\n"
">>> [rcutils|error_handling.c:" RCUTILS_STRINGIFY(__LINE__) "] rcutils_set_error_state()\n"
"This error state is being overwritten:\n"
"\n"
" '");
written = __rcutils_copy_string(
offset, bytes_left,
"\n"
">>> [rcutils|error_handling.c:" RCUTILS_STRINGIFY(__LINE__) "] rcutils_set_error_state()\n"
"This error state is being overwritten:\n"
"\n"
" '");
offset += written;
bytes_left -= written;
if (0 >= bytes_left) {break;}
Expand All @@ -120,12 +121,13 @@ __format_overwriting_error_state_message(
if (0 >= bytes_left) {break;}

// write the middle part of the state error message
written = __rcutils_copy_string(offset, bytes_left,
"'\n"
"\n"
"with this new error message:\n"
"\n"
" '");
written = __rcutils_copy_string(
offset, bytes_left,
"'\n"
"\n"
"with this new error message:\n"
"\n"
" '");
offset += written;
bytes_left -= written;
if (0 >= bytes_left) {break;}
Expand All @@ -141,11 +143,12 @@ __format_overwriting_error_state_message(
if (0 >= bytes_left) {break;}

// write the last part of the state error message
written = __rcutils_copy_string(offset, bytes_left,
"'\n"
"\n"
"rcutils_reset_error() should be called after error handling to avoid this.\n"
"<<<\n");
written = __rcutils_copy_string(
offset, bytes_left,
"'\n"
"\n"
"rcutils_reset_error() should be called after error handling to avoid this.\n"
"<<<\n");
bytes_left -= written;
} while (0);

Expand Down
12 changes: 6 additions & 6 deletions src/hash_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ static rcutils_ret_t hash_map_insert_entry(

// If we have initialized this bucket yet then do so
if (NULL == bucket->impl) {
ret = rcutils_array_list_init(bucket, BUCKET_INITIAL_CAP, sizeof(rcutils_hash_map_entry_t *),
allocator);
ret = rcutils_array_list_init(
bucket, BUCKET_INITIAL_CAP, sizeof(rcutils_hash_map_entry_t *), allocator);
}

if (RCUTILS_RET_OK == ret) {
Expand Down Expand Up @@ -220,8 +220,8 @@ static rcutils_ret_t hash_map_check_and_grow_map(rcutils_hash_map_t * hash_map)
}

// Cleanup the old map and swap in the new one
ret = hash_map_deallocate_map(hash_map->impl->map, hash_map->impl->capacity,
&hash_map->impl->allocator, false);
ret = hash_map_deallocate_map(
hash_map->impl->map, hash_map->impl->capacity, &hash_map->impl->allocator, false);
// everything worked up to this point, so if we fail to dealloc the old map still set the new
hash_map->impl->map = new_map;
hash_map->impl->capacity = new_capacity;
Expand Down Expand Up @@ -286,8 +286,8 @@ rcutils_ret_t
rcutils_hash_map_fini(rcutils_hash_map_t * hash_map)
{
HASH_MAP_VALIDATE_HASH_MAP(hash_map);
rcutils_ret_t ret = hash_map_deallocate_map(hash_map->impl->map, hash_map->impl->capacity,
&hash_map->impl->allocator, true);
rcutils_ret_t ret = hash_map_deallocate_map(
hash_map->impl->map, hash_map->impl->capacity, &hash_map->impl->allocator, true);

if (RCUTILS_RET_OK == ret) {
hash_map->impl->allocator.deallocate(hash_map->impl, hash_map->impl->allocator.state);
Expand Down
25 changes: 16 additions & 9 deletions src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ rcutils_ret_t rcutils_logging_initialize_with_allocator(rcutils_allocator_t allo
if (strcmp(line_buffered, "1") == 0) {
g_force_stdout_line_buffered = true;
} else if (strcmp(line_buffered, "0") != 0 && strcmp(line_buffered, "") != 0) {
fprintf(stderr,
fprintf(
stderr,
"Warning: unexpected value [%s] specified for RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED. "
"Default value 0 will be used. Valid values are 1 or 0.\n",
line_buffered);
}
} else {
fprintf(stderr, "Error getting env. variable "
fprintf(
stderr, "Error getting env. variable "
"RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED: %s\n", ret_str);
ret = RCUTILS_RET_INVALID_ARGUMENT;
}
Expand Down Expand Up @@ -159,7 +161,8 @@ rcutils_ret_t rcutils_logging_initialize_with_allocator(rcutils_allocator_t allo
ret_str);
ret = RCUTILS_RET_INVALID_ARGUMENT;
}
memcpy(g_rcutils_logging_output_format_string, g_rcutils_logging_default_output_format,
memcpy(
g_rcutils_logging_output_format_string, g_rcutils_logging_default_output_format,
strlen(g_rcutils_logging_default_output_format) + 1);
}

Expand Down Expand Up @@ -513,8 +516,8 @@ const char * expand_line_number(
}

// Even in the case of truncation the result will still be null-terminated.
int written = rcutils_snprintf(line_number_expansion, sizeof(line_number_expansion), "%zu",
location->line_number);
int written = rcutils_snprintf(
line_number_expansion, sizeof(line_number_expansion), "%zu", location->line_number);
if (written < 0) {
fprintf(stderr, "failed to format line number: '%zu'\n", location->line_number);
return NULL;
Expand Down Expand Up @@ -764,7 +767,8 @@ rcutils_ret_t rcutils_logging_format_message(
if (RCUTILS_RET_OK == status) { \
status = rcutils_char_array_strncat(&output_array, color, strlen(color)); \
if (RCUTILS_RET_OK != status) { \
fprintf(stderr, "Error: rcutils_char_array_strncat failed with: %d\n", \
fprintf( \
stderr, "Error: rcutils_char_array_strncat failed with: %d\n", \
status); \
} \
} \
Expand Down Expand Up @@ -844,7 +848,8 @@ void rcutils_logging_console_output_handler(
va_copy(args_clone, *args);
status = rcutils_char_array_vsprintf(&msg_array, format, args_clone);
if (RCUTILS_RET_OK != status) {
fprintf(stderr, "Error: rcutils_char_array_vsprintf failed with: %d\n",
fprintf(
stderr, "Error: rcutils_char_array_vsprintf failed with: %d\n",
status);
}
va_end(args_clone);
Expand All @@ -854,7 +859,8 @@ void rcutils_logging_console_output_handler(
status = rcutils_logging_format_message(
location, severity, name, timestamp, msg_array.buffer, &output_array);
if (RCUTILS_RET_OK != status) {
fprintf(stderr, "Error: rcutils_logging_format_message failed with: %d\n",
fprintf(
stderr, "Error: rcutils_logging_format_message failed with: %d\n",
status);
}
}
Expand All @@ -869,7 +875,8 @@ void rcutils_logging_console_output_handler(
int flush_result = fflush(stream);
if (flush_result != 0 && !g_stdout_flush_failure_reported) {
g_stdout_flush_failure_reported = true;
fprintf(stderr, "Error: failed to perform fflush on stdout, fflush return code is: %d\n",
fprintf(
stderr, "Error: failed to perform fflush on stdout, fflush return code is: %d\n",
flush_result);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ rcutils_split_last(
result_error = RCUTILS_RET_BAD_ALLOC;
goto fail;
}
snprintf(string_array->data[0], found_last + 1 - lhs_offset - inner_rhs_offset,
snprintf(
string_array->data[0], found_last + 1 - lhs_offset - inner_rhs_offset,
"%s", str + lhs_offset);

string_array->data[1] = allocator.allocate(
Expand All @@ -199,7 +200,8 @@ rcutils_split_last(
result_error = RCUTILS_RET_BAD_ALLOC;
goto fail;
}
snprintf(string_array->data[1], string_size - found_last - rhs_offset, "%s",
snprintf(
string_array->data[1], string_size - found_last - rhs_offset, "%s",
str + found_last + 1);
}

Expand Down
15 changes: 10 additions & 5 deletions test/test_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ TEST_F(CLASSNAME(TestAllocatorFixture, RMW_IMPLEMENTATION), test_default_allocat
on_unexpected_free([&frees]() {frees++;});

rcutils_allocator_t allocator;
EXPECT_NO_MEMORY_OPERATIONS({
EXPECT_NO_MEMORY_OPERATIONS(
{
allocator = rcutils_get_default_allocator();
});
EXPECT_EQ(0u, mallocs);
Expand All @@ -72,23 +73,27 @@ TEST_F(CLASSNAME(TestAllocatorFixture, RMW_IMPLEMENTATION), test_default_allocat
EXPECT_EQ(0u, frees);

void * allocated_memory = nullptr;
EXPECT_NO_MEMORY_OPERATIONS({
EXPECT_NO_MEMORY_OPERATIONS(
{
allocated_memory = allocator.allocate(1024, allocator.state);
});
EXPECT_EQ(1u, mallocs);
EXPECT_NE(nullptr, allocated_memory);
EXPECT_NO_MEMORY_OPERATIONS({
EXPECT_NO_MEMORY_OPERATIONS(
{
allocated_memory = allocator.reallocate(allocated_memory, 2048, allocator.state);
});
EXPECT_EQ(1u, reallocs);
EXPECT_NE(nullptr, allocated_memory);
EXPECT_NO_MEMORY_OPERATIONS({
EXPECT_NO_MEMORY_OPERATIONS(
{
allocator.deallocate(allocated_memory, allocator.state);
allocated_memory = allocator.zero_allocate(1024, sizeof(void *), allocator.state);
});
EXPECT_EQ(1u, callocs);
EXPECT_NE(nullptr, allocated_memory);
EXPECT_NO_MEMORY_OPERATIONS({
EXPECT_NO_MEMORY_OPERATIONS(
{
allocator.deallocate(allocated_memory, allocator.state);
});
EXPECT_EQ(1u, mallocs);
Expand Down
Loading

0 comments on commit d7bd057

Please sign in to comment.