Skip to content

Commit

Permalink
Reduce error handling static size (#14) (#15)
Browse files Browse the repository at this point in the history
This reverts commit befc608.

Reduce error handling static size (#14) (#15)

Signed-off-by: Pablo Garrido <pablogs9@gmail.com>
(cherry picked from commit 1176652)

Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
Revert "Revert "Install headers to include\${PROJECT_NAME} (ros2#351)""

This reverts commit 4546892.
  • Loading branch information
pablogs9 committed May 18, 2022
1 parent fe3555f commit bce38e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions include/rcutils/error_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern "C"
#elif !defined(RCUTILS_NO_FILESYSTEM)
#define RCUTILS_SAFE_FWRITE_TO_STDERR(msg) \
do {fwrite(msg, sizeof(char), strlen(msg), stderr);} while (0)
#else
#else
#define RCUTILS_SAFE_FWRITE_TO_STDERR(msg)
#endif

Expand All @@ -65,6 +65,8 @@ extern "C"
* \param[in] format_string The string to be used as the format of the error message.
* \param[in] ... Arguments for the format string.
*/

#if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
#define RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING(format_string, ...) \
do { \
char output_msg[RCUTILS_ERROR_MESSAGE_MAX_LENGTH]; \
Expand All @@ -75,7 +77,11 @@ extern "C"
RCUTILS_SAFE_FWRITE_TO_STDERR(output_msg); \
} \
} while (0)
#else
#define RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING(format_string, ...)
#endif

#if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
/// The maximum length a formatted number is allowed to have.
#define RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH 20 // "18446744073709551615"

Expand All @@ -102,6 +108,13 @@ extern "C"
RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH - \
RCUTILS_ERROR_FORMATTING_CHARACTERS - \
1)
#else
#define RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH 1
#define RCUTILS_ERROR_FORMATTING_CHARACTERS 1
#define RCUTILS_ERROR_MESSAGE_MAX_LENGTH 1
#define RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH 1
#define RCUTILS_ERROR_STATE_FILE_MAX_LENGTH 1
#endif // RCUTILS_AVOID_DYNAMIC_ALLOCATION

/// Struct wrapping a fixed-size c string used for returning the formatted error string.
typedef struct rcutils_error_string_s
Expand All @@ -123,7 +136,7 @@ typedef struct rcutils_error_state_s
} rcutils_error_state_t;

// make sure our math is right...
#if __STDC_VERSION__ >= 201112L
#if __STDC_VERSION__ >= 201112L && !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
static_assert(
sizeof(rcutils_error_string_t) == (
RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH +
Expand Down
4 changes: 4 additions & 0 deletions src/error_handling_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ static
void
__rcutils_convert_uint64_t_into_c_str(uint64_t number, char * buffer, size_t buffer_size)
{
#if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
assert(buffer != NULL);
assert(buffer_size >= 21);
(void)buffer_size; // prevent warning in release builds where there is no assert(...)
Expand All @@ -131,6 +132,7 @@ __rcutils_convert_uint64_t_into_c_str(uint64_t number, char * buffer, size_t buf

// reverse the string in place
__rcutils_reverse_str(buffer, strnlen(buffer, 21));
#endif
}

// do not use externally, internal function which is only to be used by error_handling.c
Expand All @@ -140,6 +142,7 @@ __rcutils_format_error_string(
rcutils_error_string_t * error_string,
const rcutils_error_state_t * error_state)
{
#if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
assert(error_string != NULL);
assert(error_state != NULL);
static const char format_1[] = ", at ";
Expand Down Expand Up @@ -173,6 +176,7 @@ __rcutils_format_error_string(
written = __rcutils_copy_string(offset, bytes_left, line_number_buffer);
offset += written;
offset[0] = '\0';
#endif
}

#ifdef __cplusplus
Expand Down

0 comments on commit bce38e1

Please sign in to comment.