Skip to content

Commit 5e210c5

Browse files
committed
Reduce error handling static size (#14) (#15)
This reverts commit befc608. Reduce error handling static size (#14) (#15) Signed-off-by: Pablo Garrido <[email protected]> (cherry picked from commit 1176652) Co-authored-by: Pablo Garrido <[email protected]> Revert "Revert "Install headers to include\${PROJECT_NAME} (ros2#351)"" This reverts commit 4546892.
1 parent fd88d40 commit 5e210c5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

include/rcutils/error_handling.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern "C"
5252
#elif !defined(RCUTILS_NO_FILESYSTEM)
5353
#define RCUTILS_SAFE_FWRITE_TO_STDERR(msg) \
5454
do {fwrite(msg, sizeof(char), strlen(msg), stderr);} while (0)
55-
#else
55+
#else
5656
#define RCUTILS_SAFE_FWRITE_TO_STDERR(msg)
5757
#endif
5858

@@ -65,6 +65,8 @@ extern "C"
6565
* \param[in] format_string The string to be used as the format of the error message.
6666
* \param[in] ... Arguments for the format string.
6767
*/
68+
69+
#if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
6870
#define RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING(format_string, ...) \
6971
do { \
7072
char output_msg[RCUTILS_ERROR_MESSAGE_MAX_LENGTH]; \
@@ -75,7 +77,11 @@ extern "C"
7577
RCUTILS_SAFE_FWRITE_TO_STDERR(output_msg); \
7678
} \
7779
} while (0)
80+
#else
81+
#define RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING(format_string, ...)
82+
#endif
7883

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

@@ -102,6 +108,13 @@ extern "C"
102108
RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH - \
103109
RCUTILS_ERROR_FORMATTING_CHARACTERS - \
104110
1)
111+
#else
112+
#define RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH 1
113+
#define RCUTILS_ERROR_FORMATTING_CHARACTERS 1
114+
#define RCUTILS_ERROR_MESSAGE_MAX_LENGTH 1
115+
#define RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH 1
116+
#define RCUTILS_ERROR_STATE_FILE_MAX_LENGTH 1
117+
#endif // RCUTILS_AVOID_DYNAMIC_ALLOCATION
105118

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

125138
// make sure our math is right...
126-
#if __STDC_VERSION__ >= 201112L
139+
#if __STDC_VERSION__ >= 201112L && !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
127140
static_assert(
128141
sizeof(rcutils_error_string_t) == (
129142
RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH +

src/error_handling_helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static
108108
void
109109
__rcutils_convert_uint64_t_into_c_str(uint64_t number, char * buffer, size_t buffer_size)
110110
{
111+
#if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
111112
assert(buffer != NULL);
112113
assert(buffer_size >= 21);
113114
(void)buffer_size; // prevent warning in release builds where there is no assert(...)
@@ -131,6 +132,7 @@ __rcutils_convert_uint64_t_into_c_str(uint64_t number, char * buffer, size_t buf
131132

132133
// reverse the string in place
133134
__rcutils_reverse_str(buffer, strnlen(buffer, 21));
135+
#endif
134136
}
135137

136138
// do not use externally, internal function which is only to be used by error_handling.c
@@ -140,6 +142,7 @@ __rcutils_format_error_string(
140142
rcutils_error_string_t * error_string,
141143
const rcutils_error_state_t * error_state)
142144
{
145+
#if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION)
143146
assert(error_string != NULL);
144147
assert(error_state != NULL);
145148
static const char format_1[] = ", at ";
@@ -173,6 +176,7 @@ __rcutils_format_error_string(
173176
written = __rcutils_copy_string(offset, bytes_left, line_number_buffer);
174177
offset += written;
175178
offset[0] = '\0';
179+
#endif
176180
}
177181

178182
#ifdef __cplusplus

0 commit comments

Comments
 (0)