summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
bdf4623)
C99 format specifiers like "%hhd" are used with log_message() but MinGW
(and Windows) does not really supports them, so the compiler suggests to
use the "gnu_printf" attribute for the function.
However "gnu_printf"is not available on clang so it's not an option,
a better alternative is the solution suggested by MinGW at
https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/
The change fixes the following warnings when compiling with MinGW:
.../libam7xxx/src/am7xxx.c: In function ‘log_message’:
.../libam7xxx/src/am7xxx.c:647:3: warning: function ‘log_message’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
vfprintf(stderr, fmt, ap);
^~~~~~~~
.../libam7xxx/src/am7xxx.c: In function ‘open_device’:
.../libam7xxx/src/am7xxx.c:772:15: warning: unknown conversion type character ‘h’ in format [-Wformat=]
debug(ctx, "Cannot set configuration %hhu\n",
^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
#define debug(ctx, ...) log_message(ctx, AM7XXX_LOG_DEBUG, __func__, 0, __VA_ARGS__)
^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:772:15: warning: too many arguments for format [-Wformat-extra-args]
debug(ctx, "Cannot set configuration %hhu\n",
^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
#define debug(ctx, ...) log_message(ctx, AM7XXX_LOG_DEBUG, __func__, 0, __VA_ARGS__)
^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:785:14: warning: unknown conversion type character ‘h’ in format [-Wformat=]
debug(ctx, "Cannot claim interface %hhu\n",
^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
#define debug(ctx, ...) log_message(ctx, AM7XXX_LOG_DEBUG, __func__, 0, __VA_ARGS__)
^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:785:14: warning: too many arguments for format [-Wformat-extra-args]
debug(ctx, "Cannot claim interface %hhu\n",
^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
#define debug(ctx, ...) log_message(ctx, AM7XXX_LOG_DEBUG, __func__, 0, __VA_ARGS__)
^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:803:14: warning: unknown conversion type character ‘h’ in format [-Wformat=]
debug(ctx, "libusb configuration changed (expected: %hhu, current: %d)\n",
^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
#define debug(ctx, ...) log_message(ctx, AM7XXX_LOG_DEBUG, __func__, 0, __VA_ARGS__)
^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:803:14: warning: too many arguments for format [-Wformat-extra-args]
debug(ctx, "libusb configuration changed (expected: %hhu, current: %d)\n",
^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
#define debug(ctx, ...) log_message(ctx, AM7XXX_LOG_DEBUG, __func__, 0, __VA_ARGS__)
^~~~~~~~~~~
add_definitions("-D_DEFAULT_SOURCE") # for htole32()
add_definitions("-D_POSIX_C_SOURCE=200112L") # for nanosleep() and lroundf()
add_definitions("-D_DEFAULT_SOURCE") # for htole32()
add_definitions("-D_POSIX_C_SOURCE=200112L") # for nanosleep() and lroundf()
+# Express a preference for C99 format strings when using MinGW, see:
+# https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/
+add_definitions("-D__USE_MINGW_ANSI_STDIO=1")
+
# Find packages needed to build library
find_package(libusb-1.0 REQUIRED)
include_directories(${LIBUSB_1_INCLUDE_DIRS})
# Find packages needed to build library
find_package(libusb-1.0 REQUIRED)
include_directories(${LIBUSB_1_INCLUDE_DIRS})
#define __attribute__(x) /* NOTHING */
#endif
#define __attribute__(x) /* NOTHING */
#endif
+/*
+ * Fix printf format when compiling for Windows with MinGW, see:
+ * https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/
+ */
+#ifdef __MINGW_PRINTF_FORMAT
+ #define AM7XXX_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
+#else
+ #define AM7XXX_PRINTF_FORMAT printf
+#endif
+
/* Control shared library symbols visibility */
#if defined _WIN32 || defined __CYGWIN__
#define AM7XXX_PUBLIC __declspec(dllexport)
/* Control shared library symbols visibility */
#if defined _WIN32 || defined __CYGWIN__
#define AM7XXX_PUBLIC __declspec(dllexport)
const char *function_name,
int line,
const char *fmt,
const char *function_name,
int line,
const char *fmt,
- ...) __attribute__ ((format (printf, 5, 6)));
+ ...) __attribute__ ((format (AM7XXX_PRINTF_FORMAT, 5, 6)));
#define fatal(...) log_message(NULL, AM7XXX_LOG_FATAL, __func__, __LINE__, __VA_ARGS__)
#define error(ctx, ...) log_message(ctx, AM7XXX_LOG_ERROR, __func__, __LINE__, __VA_ARGS__)
#define fatal(...) log_message(NULL, AM7XXX_LOG_FATAL, __func__, __LINE__, __VA_ARGS__)
#define error(ctx, ...) log_message(ctx, AM7XXX_LOG_ERROR, __func__, __LINE__, __VA_ARGS__)