Add JEMALLOC_FORMAT_PRINTF().

Replace JEMALLOC_ATTR(format(printf, ...). with
JEMALLOC_FORMAT_PRINTF(), so that configuration feature tests can
omit the attribute if it would cause extraneous compilation warnings.
This commit is contained in:
Jason Evans 2015-07-22 15:44:47 -07:00
parent 1b0e4abbfd
commit e42c309eba
8 changed files with 54 additions and 20 deletions

View File

@ -438,6 +438,26 @@ CFLAGS="${SAVED_CFLAGS}"
if test "x${je_cv_alloc_size}" = "xyes" ; then if test "x${je_cv_alloc_size}" = "xyes" ; then
AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ]) AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
fi fi
dnl Check for format(gnu_printf, ...) attribute support.
SAVED_CFLAGS="${CFLAGS}"
JE_CFLAGS_APPEND([-Werror])
JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
[void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
[je_cv_format_gnu_printf])
CFLAGS="${SAVED_CFLAGS}"
if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
fi
dnl Check for format(printf, ...) attribute support.
SAVED_CFLAGS="${CFLAGS}"
JE_CFLAGS_APPEND([-Werror])
JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
[void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
[je_cv_format_printf])
CFLAGS="${SAVED_CFLAGS}"
if test "x${je_cv_format_printf}" = "xyes" ; then
AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
fi
dnl Support optional additions to rpath. dnl Support optional additions to rpath.
AC_ARG_WITH([rpath], AC_ARG_WITH([rpath],

View File

@ -104,13 +104,12 @@ void malloc_write(const char *s);
int malloc_vsnprintf(char *str, size_t size, const char *format, int malloc_vsnprintf(char *str, size_t size, const char *format,
va_list ap); va_list ap);
int malloc_snprintf(char *str, size_t size, const char *format, ...) int malloc_snprintf(char *str, size_t size, const char *format, ...)
JEMALLOC_ATTR(format(printf, 3, 4)); JEMALLOC_FORMAT_PRINTF(3, 4);
void malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque, void malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
const char *format, va_list ap); const char *format, va_list ap);
void malloc_cprintf(void (*write)(void *, const char *), void *cbopaque, void malloc_cprintf(void (*write)(void *, const char *), void *cbopaque,
const char *format, ...) JEMALLOC_ATTR(format(printf, 3, 4)); const char *format, ...) JEMALLOC_FORMAT_PRINTF(3, 4);
void malloc_printf(const char *format, ...) void malloc_printf(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);
JEMALLOC_ATTR(format(printf, 1, 2));
#endif /* JEMALLOC_H_EXTERNS */ #endif /* JEMALLOC_H_EXTERNS */
/******************************************************************************/ /******************************************************************************/

View File

@ -4,6 +4,12 @@
/* Defined if alloc_size attribute is supported. */ /* Defined if alloc_size attribute is supported. */
#undef JEMALLOC_HAVE_ATTR_ALLOC_SIZE #undef JEMALLOC_HAVE_ATTR_ALLOC_SIZE
/* Defined if format(gnu_printf, ...) attribute is supported. */
#undef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF
/* Defined if format(printf, ...) attribute is supported. */
#undef JEMALLOC_HAVE_ATTR_FORMAT_PRINTF
/* /*
* Define overrides for non-standard allocator-related functions if they are * Define overrides for non-standard allocator-related functions if they are
* present on the system. * present on the system.

View File

@ -38,9 +38,6 @@
#ifdef JEMALLOC_HAVE_ATTR #ifdef JEMALLOC_HAVE_ATTR
# define JEMALLOC_ATTR(s) __attribute__((s)) # define JEMALLOC_ATTR(s) __attribute__((s))
# ifndef JEMALLOC_EXPORT
# define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default"))
# endif
# define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s)) # define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s))
# ifdef JEMALLOC_HAVE_ATTR_ALLOC_SIZE # ifdef JEMALLOC_HAVE_ATTR_ALLOC_SIZE
# define JEMALLOC_ALLOC_SIZE(s) JEMALLOC_ATTR(alloc_size(s)) # define JEMALLOC_ALLOC_SIZE(s) JEMALLOC_ATTR(alloc_size(s))
@ -49,11 +46,24 @@
# define JEMALLOC_ALLOC_SIZE(s) # define JEMALLOC_ALLOC_SIZE(s)
# define JEMALLOC_ALLOC_SIZE2(s1, s2) # define JEMALLOC_ALLOC_SIZE2(s1, s2)
# endif # endif
# ifndef JEMALLOC_EXPORT
# define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default"))
# endif
# ifdef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF
# define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(gnu_printf, s, i))
# elif defined(JEMALLOC_HAVE_ATTR_FORMAT_PRINTF)
# define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(printf, s, i))
# else
# define JEMALLOC_FORMAT_PRINTF(s, i)
# endif
# define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline) # define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline)
# define JEMALLOC_NOTHROW JEMALLOC_ATTR(nothrow) # define JEMALLOC_NOTHROW JEMALLOC_ATTR(nothrow)
# define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s)) # define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s))
#elif _MSC_VER #elif _MSC_VER
# define JEMALLOC_ATTR(s) # define JEMALLOC_ATTR(s)
# define JEMALLOC_ALIGNED(s) __declspec(align(s))
# define JEMALLOC_ALLOC_SIZE(s)
# define JEMALLOC_ALLOC_SIZE2(s1, s2)
# ifndef JEMALLOC_EXPORT # ifndef JEMALLOC_EXPORT
# ifdef DLLEXPORT # ifdef DLLEXPORT
# define JEMALLOC_EXPORT __declspec(dllexport) # define JEMALLOC_EXPORT __declspec(dllexport)
@ -61,9 +71,7 @@
# define JEMALLOC_EXPORT __declspec(dllimport) # define JEMALLOC_EXPORT __declspec(dllimport)
# endif # endif
# endif # endif
# define JEMALLOC_ALIGNED(s) __declspec(align(s)) # define JEMALLOC_FORMAT_PRINTF(s, i)
# define JEMALLOC_ALLOC_SIZE(s)
# define JEMALLOC_ALLOC_SIZE2(s1, s2)
# define JEMALLOC_NOINLINE __declspec(noinline) # define JEMALLOC_NOINLINE __declspec(noinline)
# ifdef __cplusplus # ifdef __cplusplus
# define JEMALLOC_NOTHROW __declspec(nothrow) # define JEMALLOC_NOTHROW __declspec(nothrow)
@ -73,10 +81,11 @@
# define JEMALLOC_SECTION(s) __declspec(allocate(s)) # define JEMALLOC_SECTION(s) __declspec(allocate(s))
#else #else
# define JEMALLOC_ATTR(s) # define JEMALLOC_ATTR(s)
# define JEMALLOC_EXPORT
# define JEMALLOC_ALIGNED(s) # define JEMALLOC_ALIGNED(s)
# define JEMALLOC_ALLOC_SIZE(s) # define JEMALLOC_ALLOC_SIZE(s)
# define JEMALLOC_ALLOC_SIZE2(s1, s2) # define JEMALLOC_ALLOC_SIZE2(s1, s2)
# define JEMALLOC_EXPORT
# define JEMALLOC_FORMAT_PRINTF(s, i)
# define JEMALLOC_NOINLINE # define JEMALLOC_NOINLINE
# define JEMALLOC_NOTHROW # define JEMALLOC_NOTHROW
# define JEMALLOC_SECTION(s) # define JEMALLOC_SECTION(s)

View File

@ -1007,7 +1007,7 @@ prof_dump_write(bool propagate_err, const char *s)
return (false); return (false);
} }
JEMALLOC_ATTR(format(printf, 2, 3)) JEMALLOC_FORMAT_PRINTF(2, 3)
static bool static bool
prof_dump_printf(bool propagate_err, const char *format, ...) prof_dump_printf(bool propagate_err, const char *format, ...)
{ {
@ -1338,7 +1338,7 @@ label_return:
return (ret); return (ret);
} }
JEMALLOC_ATTR(format(printf, 1, 2)) JEMALLOC_FORMAT_PRINTF(1, 2)
static int static int
prof_open_maps(const char *format, ...) prof_open_maps(const char *format, ...)
{ {

View File

@ -586,7 +586,7 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
return (ret); return (ret);
} }
JEMALLOC_ATTR(format(printf, 3, 4)) JEMALLOC_FORMAT_PRINTF(3, 4)
int int
malloc_snprintf(char *str, size_t size, const char *format, ...) malloc_snprintf(char *str, size_t size, const char *format, ...)
{ {
@ -625,7 +625,7 @@ malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
* Print to a callback function in such a way as to (hopefully) avoid memory * Print to a callback function in such a way as to (hopefully) avoid memory
* allocation. * allocation.
*/ */
JEMALLOC_ATTR(format(printf, 3, 4)) JEMALLOC_FORMAT_PRINTF(3, 4)
void void
malloc_cprintf(void (*write_cb)(void *, const char *), void *cbopaque, malloc_cprintf(void (*write_cb)(void *, const char *), void *cbopaque,
const char *format, ...) const char *format, ...)
@ -638,7 +638,7 @@ malloc_cprintf(void (*write_cb)(void *, const char *), void *cbopaque,
} }
/* Print to stderr in such a way as to avoid memory allocation. */ /* Print to stderr in such a way as to avoid memory allocation. */
JEMALLOC_ATTR(format(printf, 1, 2)) JEMALLOC_FORMAT_PRINTF(1, 2)
void void
malloc_printf(const char *format, ...) malloc_printf(const char *format, ...)
{ {

View File

@ -319,8 +319,8 @@ label_test_end: \
} \ } \
} while (0) } while (0)
void test_skip(const char *format, ...) JEMALLOC_ATTR(format(printf, 1, 2)); void test_skip(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);
void test_fail(const char *format, ...) JEMALLOC_ATTR(format(printf, 1, 2)); void test_fail(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);
/* For private use by macros. */ /* For private use by macros. */
test_status_t p_test(test_t *t, ...); test_status_t p_test(test_t *t, ...);

View File

@ -5,7 +5,7 @@ static test_status_t test_counts[test_status_count] = {0, 0, 0};
static test_status_t test_status = test_status_pass; static test_status_t test_status = test_status_pass;
static const char * test_name = ""; static const char * test_name = "";
JEMALLOC_ATTR(format(printf, 1, 2)) JEMALLOC_FORMAT_PRINTF(1, 2)
void void
test_skip(const char *format, ...) test_skip(const char *format, ...)
{ {
@ -18,7 +18,7 @@ test_skip(const char *format, ...)
test_status = test_status_skip; test_status = test_status_skip;
} }
JEMALLOC_ATTR(format(printf, 1, 2)) JEMALLOC_FORMAT_PRINTF(1, 2)
void void
test_fail(const char *format, ...) test_fail(const char *format, ...)
{ {