Prefix status macro implementation with MP_.

This makes it less likely for the implementation to conflict with other
ASSIGN_OR_RETURN() and RETURN_IF_ERROR() implementations.

PiperOrigin-RevId: 570726994
This commit is contained in:
Daniel Cheng 2023-10-04 10:02:21 -07:00 committed by Copybara-Service
parent 9bb042cc86
commit 7f1c17065a

View File

@ -82,7 +82,7 @@
// return absl::OkStatus(); // return absl::OkStatus();
// } // }
#define MP_RETURN_IF_ERROR(expr) \ #define MP_RETURN_IF_ERROR(expr) \
STATUS_MACROS_IMPL_ELSE_BLOCKER_ \ MP_STATUS_MACROS_IMPL_ELSE_BLOCKER_ \
if (mediapipe::status_macro_internal::StatusAdaptorForMacros \ if (mediapipe::status_macro_internal::StatusAdaptorForMacros \
status_macro_internal_adaptor = {(expr), MEDIAPIPE_LOC}) { \ status_macro_internal_adaptor = {(expr), MEDIAPIPE_LOC}) { \
} else /* NOLINT */ \ } else /* NOLINT */ \
@ -134,10 +134,10 @@
// Example: Logging the error on failure. // Example: Logging the error on failure.
// ASSIGN_OR_RETURN(ValueType value, MaybeGetValue(query), _.LogError()); // ASSIGN_OR_RETURN(ValueType value, MaybeGetValue(query), _.LogError());
// //
#define ASSIGN_OR_RETURN(...) \ #define ASSIGN_OR_RETURN(...) \
STATUS_MACROS_IMPL_GET_VARIADIC_((__VA_ARGS__, \ MP_STATUS_MACROS_IMPL_GET_VARIADIC_( \
STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_3_, \ (__VA_ARGS__, MP_STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_3_, \
STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_2_)) \ MP_STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_2_)) \
(__VA_ARGS__) (__VA_ARGS__)
// ================================================================= // =================================================================
@ -146,37 +146,39 @@
// MSVC incorrectly expands variadic macros, splice together a macro call to // MSVC incorrectly expands variadic macros, splice together a macro call to
// work around the bug. // work around the bug.
#define STATUS_MACROS_IMPL_GET_VARIADIC_HELPER_(_1, _2, _3, NAME, ...) NAME #define MP_STATUS_MACROS_IMPL_GET_VARIADIC_HELPER_(_1, _2, _3, NAME, ...) NAME
#define STATUS_MACROS_IMPL_GET_VARIADIC_(args) \ #define MP_STATUS_MACROS_IMPL_GET_VARIADIC_(args) \
STATUS_MACROS_IMPL_GET_VARIADIC_HELPER_ args MP_STATUS_MACROS_IMPL_GET_VARIADIC_HELPER_ args
#define STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_2_(lhs, rexpr) \ #define MP_STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_2_(lhs, rexpr) \
STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_( \ MP_STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_( \
STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__), lhs, rexpr, \ MP_STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__), lhs, rexpr, \
return mediapipe::StatusBuilder( \ return mediapipe::StatusBuilder( \
std::move(STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__)) \ std::move(MP_STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__)) \
.status(), \ .status(), \
MEDIAPIPE_LOC)) MEDIAPIPE_LOC))
#define STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_3_(lhs, rexpr, error_expression) \ #define MP_STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_3_(lhs, rexpr, \
STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_( \ error_expression) \
STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__), lhs, rexpr, \ MP_STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_( \
mediapipe::StatusBuilder _( \ MP_STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__), lhs, rexpr, \
std::move(STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__)) \ mediapipe::StatusBuilder _( \
.status(), \ std::move(MP_STATUS_MACROS_IMPL_CONCAT_(_status_or_value, __LINE__)) \
MEDIAPIPE_LOC); \ .status(), \
(void)_; /* error_expression is allowed to not use this variable */ \ MEDIAPIPE_LOC); \
(void)_; /* error_expression is allowed to not use this variable */ \
return (error_expression)) return (error_expression))
#define STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_(statusor, lhs, rexpr, \ #define MP_STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_(statusor, lhs, rexpr, \
error_expression) \ error_expression) \
auto statusor = (rexpr); \ auto statusor = (rexpr); \
if (ABSL_PREDICT_FALSE(!statusor.ok())) { \ if (ABSL_PREDICT_FALSE(!statusor.ok())) { \
error_expression; \ error_expression; \
} \ } \
lhs = std::move(statusor).value() lhs = std::move(statusor).value()
// Internal helper for concatenating macro values. // Internal helper for concatenating macro values.
#define STATUS_MACROS_IMPL_CONCAT_INNER_(x, y) x##y #define MP_STATUS_MACROS_IMPL_CONCAT_INNER_(x, y) x##y
#define STATUS_MACROS_IMPL_CONCAT_(x, y) STATUS_MACROS_IMPL_CONCAT_INNER_(x, y) #define MP_STATUS_MACROS_IMPL_CONCAT_(x, y) \
MP_STATUS_MACROS_IMPL_CONCAT_INNER_(x, y)
// The GNU compiler emits a warning for code like: // The GNU compiler emits a warning for code like:
// //
@ -189,9 +191,9 @@
// if (do_expr) MP_RETURN_IF_ERROR(expr) << "Some message"; // if (do_expr) MP_RETURN_IF_ERROR(expr) << "Some message";
// //
// The "switch (0) case 0:" idiom is used to suppress this. // The "switch (0) case 0:" idiom is used to suppress this.
#define STATUS_MACROS_IMPL_ELSE_BLOCKER_ \ #define MP_STATUS_MACROS_IMPL_ELSE_BLOCKER_ \
switch (0) \ switch (0) \
case 0: \ case 0: \
default: // NOLINT default: // NOLINT
namespace mediapipe { namespace mediapipe {