Skip to content

Commit d6cb68d

Browse files
committed
Deprecate ET_LOG{,_MSG}_AND_RETURN_IF_FALSE
ET_LOG_MSG_AND_RETURN_IF_FALSE is renamed to ET_CHECK_OR_RETURN_FALSE and moved. ET_LOG_AND_RETURN_FALSE is deprecated in favor of ET_CHECK_OR_RETURN_FALSE with a descriptive message. ghstack-source-id: 63ae2fe ghstack-comment-id: 2655450441 Pull Request resolved: #8451
1 parent 1d712ec commit d6cb68d

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

runtime/core/error.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ using ::executorch::runtime::error_code_t;
126126
} \
127127
}
128128

129+
/**
130+
* A convenience macro to be used in utility functions that check whether input
131+
* tensor(s) are valid, which are expected to return a boolean. Checks whether
132+
* `cond` is true; if not, log the failed check with `message` and return false.
133+
*
134+
* @param[in] cond the condition to check
135+
* @param[in] message an additional message to log with `cond`
136+
*/
137+
#define ET_CHECK_OR_RETURN_FALSE(cond__, message__, ...) \
138+
{ \
139+
if (!(cond__)) { \
140+
ET_LOG(Error, "Check failed (%s): " message__, #cond__, ##__VA_ARGS__); \
141+
return false; \
142+
} \
143+
}
144+
129145
/**
130146
* If error__ is not Error::Ok, optionally log a message and return the error
131147
* from the current function, which must be of return type

runtime/core/exec_aten/util/tensor_util.h

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -332,35 +332,22 @@
332332
})
333333

334334
/**
335+
* DEPRECATED: Please use ET_CHECK_OR_RETURN_FALSE instead and provide
336+
* an informative message. (For example, the values of any variables used in
337+
* `cond` would not be reported automatically by this macro.)
338+
*
335339
* A convenience macro to be used in utility functions that check whether input
336340
* tensor(s) are valid, which are expected to return a boolean. Checks whether
337341
* `cond` is true; if not, log the failed check and return false.
338342
*
339343
* @param[in] cond the condition to check
340344
*/
341-
#define ET_LOG_AND_RETURN_IF_FALSE(cond) \
342-
do { \
343-
if (!(cond)) { \
344-
ET_LOG(Error, "Check failed (%s): ", #cond); \
345-
return false; \
346-
} \
347-
} while (false)
345+
#define ET_LOG_AND_RETURN_IF_FALSE(cond) ET_CHECK_OR_RETURN_FALSE(cond, "")
348346

349347
/**
350-
* A convenience macro to be used in utility functions that check whether input
351-
* tensor(s) are valid, which are expected to return a boolean. Checks whether
352-
* `cond` is true; if not, log the failed check with `message` and return false.
353-
*
354-
* @param[in] cond the condition to check
355-
* @param[in] message an additional message to log with `cond`
348+
* DEPRECATED: Please use ET_CHECK_OR_RETURN_FALSE instead.
356349
*/
357-
#define ET_LOG_MSG_AND_RETURN_IF_FALSE(cond, message, ...) \
358-
do { \
359-
if (!(cond)) { \
360-
ET_LOG(Error, "Check failed (%s): " message, #cond, ##__VA_ARGS__); \
361-
return false; \
362-
} \
363-
} while (false)
350+
#define ET_LOG_MSG_AND_RETURN_IF_FALSE ET_CHECK_OR_RETURN_FALSE
364351

365352
/**
366353
* If `cond` is false, log `cond` and return from the kernel with a failure

0 commit comments

Comments
 (0)