Skip to content

Commit

Permalink
for tracepoint fallbacks, use c++-style mark-unused
Browse files Browse the repository at this point in the history
Summary: Trying to mark macro params as unused using only the C preprocessor is painful. But we have an easier way in C++.

Reviewed By: nslingerland

Differential Revision: D60238723

fbshipit-source-id: c527bea47586e18dd40ecfa53cc60601771c8235
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Jul 27, 2024
1 parent cab625c commit 7c4f66a
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions folly/tracing/StaticTracepoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,13 @@

#define FOLLY_HAVE_SDT 0

// Mark variadic macro args as unused from https://stackoverflow.com/a/31470425
#define FOLLY_UNUSED0()
#define FOLLY_UNUSED1(a) (void)(a)
#define FOLLY_UNUSED2(a, b) (void)(a), FOLLY_UNUSED1(b)
#define FOLLY_UNUSED3(a, b, c) (void)(a), FOLLY_UNUSED2(b, c)
#define FOLLY_UNUSED4(a, b, c, d) (void)(a), FOLLY_UNUSED3(b, c, d)
#define FOLLY_UNUSED5(a, b, c, d, e) (void)(a), FOLLY_UNUSED4(b, c, d, e)
#define FOLLY_UNUSED6(a, b, c, d, e, f) (void)(a), FOLLY_UNUSED5(b, c, d, e, f)
#define FOLLY_UNUSED7(a, b, c, d, e, f, g) \
(void)(a), FOLLY_UNUSED6(b, c, d, e, f, g)
#define FOLLY_UNUSED8(a, b, c, d, e, f, g, h) \
(void)(a), FOLLY_UNUSED7(b, c, d, e, f, g, h)

#define FOLLY_VA_NUM_ARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, N, ...) N
#define FOLLY_VA_NUM_ARGS(...) \
FOLLY_VA_NUM_ARGS_IMPL(100, ##__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)

#define FOLLY_ALL_UNUSED_IMPL_(nargs) FOLLY_UNUSED##nargs
#define FOLLY_ALL_UNUSED_IMPL(nargs) FOLLY_ALL_UNUSED_IMPL_(nargs)

#if defined(_MSC_VER)
#define FOLLY_ALL_UNUSED(...)
#else
#define FOLLY_ALL_UNUSED(...) \
FOLLY_ALL_UNUSED_IMPL(FOLLY_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
#endif

#define FOLLY_SDT(provider, name, ...) \
do { \
FOLLY_ALL_UNUSED(__VA_ARGS__); \
#define FOLLY_SDT(provider, name, ...) \
do { \
[](auto const&...) {}(__VA_ARGS__); \
} while (0)
#define FOLLY_SDT_WITH_SEMAPHORE(provider, name, ...) \
do { \
FOLLY_ALL_UNUSED(__VA_ARGS__); \
[](auto const&...) {}(__VA_ARGS__); \
} while (0)
#define FOLLY_SDT_IS_ENABLED(provider, name) (false)
#define FOLLY_SDT_SEMAPHORE(provider, name) \
Expand Down

0 comments on commit 7c4f66a

Please sign in to comment.