Skip to content

Commit

Permalink
Merge pull request #66 from ros2/allocator_check
Browse files Browse the repository at this point in the history
Migrate CHECK_ARGUMENT_FOR_NULL and CHECK_FOR_NULL_WITH_MSG from rcl into rcutils
  • Loading branch information
tfoote authored Nov 11, 2017
2 parents b981951 + d4cc8a0 commit 4783bc4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
29 changes: 29 additions & 0 deletions include/rcutils/error_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,35 @@ void
rcutils_set_error_state(
const char * error_msg, const char * file, size_t line_number, rcutils_allocator_t allocator);

/// Check an argument for a null value.
/**
* If the argument's value is `NULL`, set the error message saying so and
* return the `error_return_type`.
*
* \param[in] argument The argument to test.
* \param[in] error_return_type The type to return if the argument is `NULL`.
* \param[in] allocator The allocator to use if an error message needs to be allocated.
*/
#define RCUTILS_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type, allocator) \
RCUTILS_CHECK_FOR_NULL_WITH_MSG(argument, #argument " argument is null", \
return error_return_type, allocator)

/// Check a value for null, with an error message and error statement.
/**
* If `value` is `NULL`, the error statement will be evaluated after
* setting the error message.
*
* \param[in] value The value to test.
* \param[in] msg The error message if `value` is `NULL`.
* \param[in] error_statement The statement to evaluate if `value` is `NULL`.
* \param[in] allocator The allocator to use if an error message needs to be allocated.
*/
#define RCUTILS_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement, allocator) \
if (!(value)) { \
RCUTILS_SET_ERROR_MSG(msg, allocator); \
error_statement; \
}

/// Set the error message, as well as append the current file and line number.
/**
* If an error message was previously set, and rcutils_reset_error() was not called
Expand Down
10 changes: 0 additions & 10 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ extern "C"

#include "rcutils/error_handling.h"

#define RCUTILS_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type, allocator) \
RCUTILS_CHECK_FOR_NULL_WITH_MSG(argument, #argument " argument is null", \
return error_return_type, allocator)

#define RCUTILS_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement, allocator) \
if (!(value)) { \
RCUTILS_SET_ERROR_MSG(msg, allocator); \
error_statement; \
}

#if __cplusplus
}
#endif
Expand Down

0 comments on commit 4783bc4

Please sign in to comment.