@@ -205,42 +205,37 @@ using ::executorch::runtime::error_code_t;
205
205
* @param[in] ... Optional format string for the log error message and its
206
206
* arguments.
207
207
*/
208
- #define ET_CHECK_OK_OR_RETURN_ERROR (error__, ...) \
209
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR (error__, ##__VA_ARGS__)
210
-
211
- // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
212
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR (...) \
213
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT ( \
214
- __VA_ARGS__, 10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 ) \
215
- (__VA_ARGS__)
208
+ #define ET_CHECK_OK_OR_RETURN_ERROR (...) \
209
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR (__VA_ARGS__)
216
210
217
211
/* *
218
212
* Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
219
213
* This macro selects the correct version of
220
214
* ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR based on the number of arguments passed.
221
- * It uses a trick with the preprocessor to count the number of arguments and
222
- * then selects the appropriate macro.
223
- *
224
- * The macro expansion uses __VA_ARGS__ to accept any number of arguments and
225
- * then appends them to ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_, followed by the
226
- * count of arguments. The count is determined by the macro
227
- * ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT which takes the arguments and
228
- * passes them along with a sequence of numbers (2, 1). The preprocessor then
229
- * matches this sequence to the correct number of arguments provided.
230
- *
231
- * If two arguments are passed, ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 is
232
- * selected, suitable for cases where an error code and a custom message are
233
- * provided. If only one argument is passed,
234
- * ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1 is selected, which is used for cases
235
- * with just an error code.
236
- *
237
- * Usage:
238
- * ET_CHECK_OK_OR_RETURN_ERROR(error_code); // Calls v1
239
- * ET_CHECK_OK_OR_RETURN_ERROR(error_code, "Error message", ...); // Calls v2
215
+ * It uses a helper that reliably picks the 1-arg or 2+-arg form on
216
+ * MSVC/Clang/GCC.
240
217
*/
241
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT ( \
242
- _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) \
243
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_##N
218
+ #define ET_INTERNAL_EXPAND (x ) x
219
+ #define ET_INTERNAL_GET_MACRO ( \
220
+ _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) \
221
+ NAME
222
+
223
+ // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
224
+ // Picks _2 for 2..10 args, _1 for exactly 1 arg.
225
+ #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR (...) \
226
+ ET_INTERNAL_EXPAND (ET_INTERNAL_GET_MACRO( \
227
+ __VA_ARGS__, \
228
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 10 */ \
229
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 9 */ \
230
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 8 */ \
231
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 7 */ \
232
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 6 */ \
233
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 5 */ \
234
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 4 */ \
235
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 3 */ \
236
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 2 */ \
237
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1 /* 1 */ \
238
+ )(__VA_ARGS__))
244
239
245
240
// Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
246
241
#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1 (error__ ) \
@@ -260,21 +255,3 @@ using ::executorch::runtime::error_code_t;
260
255
return et_error__; \
261
256
} \
262
257
} while (0 )
263
-
264
- // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
265
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_3 \
266
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
267
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_4 \
268
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
269
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_5 \
270
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
271
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_6 \
272
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
273
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_7 \
274
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
275
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_8 \
276
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
277
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_9 \
278
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
279
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_10 \
280
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
0 commit comments