lib: remove named variadic macros in exported headers

Exported header files used by applications should allow the strictest
compiler flags. Language extensions used in many places must be explicitly
marked or removed to avoid warnings and compilation failures.

Since there is no way to force named variadic macros as extensions, use a
a standard __VA_ARGS__ with an extra dummy argument to format strings.

This commit prevents the following errors:

 error: ISO C does not permit named variadic macros

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
This commit is contained in:
Adrien Mazarguil 2016-09-08 14:25:09 +02:00 committed by Thomas Monjalon
parent 8480682efb
commit cd370e48ba
3 changed files with 28 additions and 15 deletions

View File

@ -77,26 +77,30 @@ extern const char **rte_cyptodev_names;
/* Logging Macros */
#define CDEV_LOG_ERR(fmt, args...) \
RTE_LOG(ERR, CRYPTODEV, "%s() line %u: " fmt "\n", \
__func__, __LINE__, ## args)
#define CDEV_LOG_ERR(...) \
RTE_LOG(ERR, CRYPTODEV, \
RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
__func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
#define CDEV_PMD_LOG_ERR(dev, fmt, args...) \
RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
dev, __func__, __LINE__, ## args)
#define CDEV_PMD_LOG_ERR(dev, ...) \
RTE_LOG(ERR, CRYPTODEV, \
RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
dev, __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
#ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
#define CDEV_LOG_DEBUG(fmt, args...) \
RTE_LOG(DEBUG, CRYPTODEV, "%s() line %u: " fmt "\n", \
__func__, __LINE__, ## args) \
#define CDEV_LOG_DEBUG(...) \
RTE_LOG(DEBUG, CRYPTODEV, \
RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
__func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
#define CDEV_PMD_TRACE(fmt, args...) \
RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s: " fmt "\n", \
dev, __func__, ## args)
#define CDEV_PMD_TRACE(...) \
RTE_LOG(DEBUG, CRYPTODEV, \
RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
#else
#define CDEV_LOG_DEBUG(fmt, args...)
#define CDEV_PMD_TRACE(fmt, args...)
#define CDEV_LOG_DEBUG(...) (void)0
#define CDEV_PMD_TRACE(...) (void)0
#endif
/**

View File

@ -62,7 +62,7 @@ extern "C" {
#define RTE_PMD_DEBUG_TRACE(...) \
rte_pmd_debug_trace(__func__, __VA_ARGS__)
#else
#define RTE_PMD_DEBUG_TRACE(fmt, args...)
#define RTE_PMD_DEBUG_TRACE(...)
#endif
struct rte_cryptodev_session {

View File

@ -335,6 +335,15 @@ rte_bsf32(uint32_t v)
/** Take a macro value and get a string version of it */
#define RTE_STR(x) _RTE_STR(x)
/**
* ISO C helpers to modify format strings using variadic macros.
* This is a replacement for the ", ## __VA_ARGS__" GNU extension.
* An empty %s argument is appended to avoid a dangling comma.
*/
#define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
#define RTE_FMT_HEAD(fmt, ...) fmt
#define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
/** Mask value of type "tp" for the first "ln" bit set. */
#define RTE_LEN2MASK(ln, tp) \
((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))