eal: introduce portable format attribute
When using __attribute__((format(...)) on functions, GCC on Windows assumes MS-specific format string by default, even if the underlying stdio implementation is ANSI-compliant (either MS Unicersal CRT or MinGW implementation). Wrap attribute into a macro that forces GNU-specific format string when using GCC. Use this new attribute for logging and panic messages in EAL and for output strings in cmdline library. Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> Tested-by: William Tu <u9012063@gmail.com> Tested-by: Pallavi Kadam <pallavi.kadam@intel.com>
This commit is contained in:
parent
0c9a5735a9
commit
abc61614f8
|
@ -7,6 +7,8 @@
|
|||
#ifndef _CMDLINE_H_
|
||||
#define _CMDLINE_H_
|
||||
|
||||
#include <rte_common.h>
|
||||
|
||||
#include <termios.h>
|
||||
#include <cmdline_rdline.h>
|
||||
#include <cmdline_parse.h>
|
||||
|
@ -34,7 +36,7 @@ struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_
|
|||
void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
|
||||
void cmdline_free(struct cmdline *cl);
|
||||
void cmdline_printf(const struct cmdline *cl, const char *fmt, ...)
|
||||
__attribute__((format(printf,2,3)));
|
||||
__rte_format_printf(2, 3);
|
||||
int cmdline_in(struct cmdline *cl, const char *buf, int size);
|
||||
int cmdline_write_char(struct rdline *rdl, char c);
|
||||
|
||||
|
|
|
@ -104,6 +104,21 @@ typedef uint16_t unaligned_uint16_t;
|
|||
*/
|
||||
#define RTE_SET_USED(x) (void)(x)
|
||||
|
||||
/**
|
||||
* Check format string and its arguments at compile-time.
|
||||
*
|
||||
* GCC on Windows assumes MS-specific format string by default,
|
||||
* even if the underlying stdio implementation is ANSI-compliant,
|
||||
* so this must be overridden.
|
||||
*/
|
||||
#if RTE_CC_IS_GNU
|
||||
#define __rte_format_printf(format_index, first_arg) \
|
||||
__attribute__((format(gnu_printf, format_index, first_arg)))
|
||||
#else
|
||||
#define __rte_format_printf(format_index, first_arg) \
|
||||
__attribute__((format(printf, format_index, first_arg)))
|
||||
#endif
|
||||
|
||||
#define RTE_PRIORITY_LOG 101
|
||||
#define RTE_PRIORITY_BUS 110
|
||||
#define RTE_PRIORITY_CLASS 120
|
||||
|
@ -799,7 +814,7 @@ rte_str_to_size(const char *str)
|
|||
void
|
||||
rte_exit(int exit_code, const char *format, ...)
|
||||
__attribute__((noreturn))
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
__rte_format_printf(2, 3);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ void __rte_panic(const char *funcname , const char *format, ...)
|
|||
#endif
|
||||
#endif
|
||||
__attribute__((noreturn))
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
__rte_format_printf(2, 3);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev);
|
|||
int
|
||||
rte_devargs_parsef(struct rte_devargs *da,
|
||||
const char *format, ...)
|
||||
__attribute__((format(printf, 2, 0)));
|
||||
__rte_format_printf(2, 0);
|
||||
|
||||
/**
|
||||
* Insert an rte_devargs in the global list.
|
||||
|
|
|
@ -282,7 +282,7 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
|
|||
__attribute__((cold))
|
||||
#endif
|
||||
#endif
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
__rte_format_printf(3, 4);
|
||||
|
||||
/**
|
||||
* Generates a log message.
|
||||
|
@ -311,7 +311,7 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
|
|||
* - Negative on error.
|
||||
*/
|
||||
int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
|
||||
__attribute__((format(printf,3,0)));
|
||||
__rte_format_printf(3, 0);
|
||||
|
||||
/**
|
||||
* Generates a log message.
|
||||
|
|
Loading…
Reference in a new issue