}
/* They want something really big. Aim for contiguous pages (slow). */
-static COLD_ATTRIBUTE
-void *huge_alloc(void *pool, unsigned long poolsize,
- unsigned long size, unsigned long align)
+static COLD void *huge_alloc(void *pool, unsigned long poolsize,
+ unsigned long size, unsigned long align)
{
struct header *head = pool;
struct huge_alloc *ha;
return (char *)pool + ha->off;
}
-static COLD_ATTRIBUTE void
+static COLD void
huge_free(struct header *head, unsigned long poolsize, void *free)
{
unsigned long i, off, pgnum, free_off = (char *)free - (char *)head;
alloc_free(head, poolsize, ha);
}
-static COLD_ATTRIBUTE unsigned long
-huge_size(struct header *head, void *p)
+static COLD unsigned long huge_size(struct header *head, void *p)
{
unsigned long i, off = (char *)p - (char *)head;
struct huge_alloc *ha;
* compiler - macros for common compiler extensions
*
* Abstracts away some compiler hints. Currently these include:
- * - COLD_ATTRIBUTE
+ * - COLD
* For functions not called in fast paths (aka. cold functions)
- * - PRINTF_ATTRIBUTE
+ * - PRINTF_FMT
* For functions which take printf-style parameters.
- * - IDEMPOTENT_ATTRIBUTE
+ * - IDEMPOTENT
* For functions which return the same value for same parameters.
- * - NEEDED_ATTRIBUTE
+ * - NEEDED
* For functions and variables which must be emitted even if unused.
- * - UNNEEDED_ATTRIBUTE
+ * - UNNEEDED
* For functions and variables which need not be emitted if unused.
+ * - UNUSED
+ * For parameters which are not used.
* - IS_COMPILE_CONSTANT
* For using different tradeoffs for compiletime vs runtime evaluation.
*
*
* // Example of a (slow-path) logging function.
* static int log_threshold = 2;
- * static void COLD_ATTRIBUTE PRINTF_ATTRIBUTE(2,3)
+ * static void COLD PRINTF_FMT(2,3)
* logger(int level, const char *fmt, ...)
* {
* va_list ap;
#if HAVE_ATTRIBUTE_COLD
/**
- * COLD_ATTRIBUTE - a function is unlikely to be called.
+ * COLD - a function is unlikely to be called.
*
* Used to mark an unlikely code path and optimize appropriately.
* It is usually used on logging or error routines.
*
* Example:
- * static void COLD_ATTRIBUTE moan(const char *reason)
+ * static void COLD moan(const char *reason)
* {
* fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
* }
*/
-#define COLD_ATTRIBUTE __attribute__((cold))
+#define COLD __attribute__((cold))
#else
-#define COLD_ATTRIBUTE
+#define COLD
#endif
#if HAVE_ATTRIBUTE_PRINTF
/**
- * PRINTF_ATTRIBUTE - a function takes printf-style arguments
+ * PRINTF_FMT - a function takes printf-style arguments
* @nfmt: the 1-based number of the function's format argument.
* @narg: the 1-based number of the function's first variable argument.
*
* This allows the compiler to check your parameters as it does for printf().
*
* Example:
- * void PRINTF_ATTRIBUTE(2,3) my_printf(const char *prefix,
- * const char *fmt, ...);
+ * void PRINTF_FMT(2,3) my_printf(const char *prefix, const char *fmt, ...);
*/
-#define PRINTF_ATTRIBUTE(nfmt, narg) \
+#define PRINTF_FMT(nfmt, narg) \
__attribute__((format(__printf__, nfmt, narg)))
#else
-#define PRINTF_ATTRIBUTE(nfmt, narg)
+#define PRINTF_FMT(nfmt, narg)
#endif
#if HAVE_ATTRIBUTE_CONST
/**
- * IDEMPOTENT_ATTRIBUTE - a function's return depends only on its argument
+ * IDEMPOTENT - a function's return depends only on its argument
*
* This allows the compiler to assume that the function will return the exact
* same value for the exact same arguments. This implies that the function
* must not use global variables, or dereference pointer arguments.
*/
-#define IDEMPOTENT_ATTRIBUTE __attribute__((const))
+#define IDEMPOTENT __attribute__((const))
#else
-#define IDEMPOTENT_ATTRIBUTE
+#define IDEMPOTENT
#endif
#if HAVE_ATTRIBUTE_UNUSED
/**
- * UNNEEDED_ATTRIBUTE - a parameter/variable/function may not be needed
+ * UNNEEDED - a variable/function may not be needed
*
- * This suppresses warnings about unused variables or parameters, but tells
+ * This suppresses warnings about unused variables or functions, but tells
* the compiler that if it is unused it need not emit it into the source code.
*
* Example:
* // With some preprocessor options, this is unnecessary.
- * static UNNEEDED_ATTRIBUTE int counter;
+ * static UNNEEDED int counter;
*
* // With some preprocessor options, this is unnecessary.
- * static UNNEEDED_ATTRIBUTE void add_to_counter(int add)
+ * static UNNEEDED void add_to_counter(int add)
* {
* counter += add;
* }
*/
-#define UNNEEDED_ATTRIBUTE __attribute__((unused))
+#define UNNEEDED __attribute__((unused))
#if HAVE_ATTRIBUTE_USED
/**
- * NEEDED_ATTRIBUTE - a parameter/variable/function is needed
+ * NEEDED - a variable/function is needed
*
- * This suppresses warnings about unused variables or parameters, but tells
+ * This suppresses warnings about unused variables or functions, but tells
* the compiler that it must exist even if it (seems) unused.
*
* Example:
* // Even if this is unused, these are vital for debugging.
- * static UNNEEDED_ATTRIBUTE int counter;
- * static UNNEEDED_ATTRIBUTE void dump_counter(void)
+ * static NEEDED int counter;
+ * static NEEDED void dump_counter(void)
* {
* printf("Counter is %i\n", counter);
* }
*/
-#define NEEDED_ATTRIBUTE __attribute__((used))
+#define NEEDED __attribute__((used))
#else
/* Before used, unused functions and vars were always emitted. */
-#define NEEDED_ATTRIBUTE __attribute__((unused))
+#define NEEDED __attribute__((unused))
#endif
+
+/**
+ * UNUSED - a parameter is unused
+ *
+ * Some compilers (eg. gcc with -W or -Wunused) warn about unused
+ * function parameters. This suppresses such warnings and indicates
+ * to the reader that it's deliberate.
+ *
+ * Example:
+ * // This is used as a callback, so needs to have this prototype.
+ * static int some_callback(void *unused UNUSED)
+ * {
+ * return 0;
+ * }
+ */
+#define UNUSED __attribute__((unused))
#else
-#define UNNEEDED_ATTRIBUTE
-#define NEEDED_ATTRIBUTE
+#define UNNEEDED
+#define NEEDED
+#define UNUSED
#endif
#if HAVE_BUILTIN_CONSTANT_P
#include <ccan/compiler/compiler.h>
-static void PRINTF_ATTRIBUTE(2,3) my_printf(int x, const char *fmt, ...)
+static void PRINTF_FMT(2,3) my_printf(int x, const char *fmt, ...)
{
}
ht->table[i] = make_hval(ht, new, get_hash_ptr_bits(ht, h)|perfect);
}
-static COLD_ATTRIBUTE bool double_table(struct htable *ht)
+static COLD bool double_table(struct htable *ht)
{
unsigned int i;
size_t oldnum = (size_t)1 << ht->bits;
return true;
}
-static COLD_ATTRIBUTE void rehash_table(struct htable *ht)
+static COLD void rehash_table(struct htable *ht)
{
size_t start, i;
uintptr_t e;
}
/* We stole some bits, now we need to put them back... */
-static COLD_ATTRIBUTE void update_common(struct htable *ht, const void *p)
+static COLD void update_common(struct htable *ht, const void *p)
{
unsigned int i;
uintptr_t maskdiff, bitsdiff;
year=1998,
note="\url{http://supertech.csail.mit.edu/papers/debruijn.pdf}"
}*/
-static UNNEEDED_ATTRIBUTE const unsigned char DEBRUIJN_IDX32[32]={
+static UNNEEDED const unsigned char DEBRUIJN_IDX32[32]={
0, 1,28, 2,29,14,24, 3,30,22,20,15,25,17, 4, 8,
31,27,13,23,21,19,16, 7,26,12,18, 6,11, 5,10, 9
};
* return 1U << ilog32(i-1);
* }
*/
-int ilog32(uint32_t _v) IDEMPOTENT_ATTRIBUTE;
+int ilog32(uint32_t _v) IDEMPOTENT;
/**
* ilog32_nz - Integer binary logarithm of a non-zero 32-bit value.
* return ilog32_nz(i) - 1;
* }
*/
-int ilog32_nz(uint32_t _v) IDEMPOTENT_ATTRIBUTE;
+int ilog32_nz(uint32_t _v) IDEMPOTENT;
/**
* ilog64 - Integer binary logarithm of a 64-bit value.
* See Also:
* ilog64_nz(), ilog32()
*/
-int ilog64(uint64_t _v) IDEMPOTENT_ATTRIBUTE;
+int ilog64(uint64_t _v) IDEMPOTENT;
/**
* ilog64_nz - Integer binary logarithm of a non-zero 64-bit value.
* See Also:
* ilog64(), ilog32_nz()
*/
-int ilog64_nz(uint64_t _v) IDEMPOTENT_ATTRIBUTE;
+int ilog64_nz(uint64_t _v) IDEMPOTENT;
/**
* STATIC_ILOG_32 - The integer logarithm of an (unsigned, 32-bit) constant.
return 0;
}
-int iscsi_process_logout_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size UNNEEDED_ATTRIBUTE)
+int iscsi_process_logout_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size UNUSED)
{
iscsi->is_loggedin = 0;
pdu->callback(iscsi, ISCSI_STATUS_GOOD, NULL, pdu->private_data);
* parse the data in blob and calcualte the size of a full readcapacity10 datain structure
*/
static int scsi_readcapacity10_datain_getfullsize(struct scsi_task *task
- UNNEEDED_ATTRIBUTE)
+ UNUSED)
{
return 8;
}
JError_t err;
const char *errstr;
};
-const char *COLD_ATTRIBUTE jbit_error_(struct jbitset *set);
+const char *COLD jbit_error_(struct jbitset *set);
/**
* jbit_error - test for an error in the a previous jbit_ operation.
unsigned long acc_index;
const char *funcname;
};
-const char *COLD_ATTRIBUTE jmap_error_(struct jmap *map);
+const char *COLD jmap_error_(struct jmap *map);
/* Debugging checks. */
static inline void jmap_debug_add_access(const struct jmap *map,
* code path and optimize appropriately; see likely() above.
*
* See Also:
- * likely(), likely_stats(), UNLIKELY_FUNCTION_ATTRIBUTE (compiler.h)
+ * likely(), likely_stats(), COLD (compiler.h)
*
* Example:
* // Prints a warning if we overflow.
/*
add a name to an existing pointer - va_list version
*/
-static inline const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
+static inline const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap) PRINTF_FMT(2,0);
static inline const char *talloc_set_name_v(const void *ptr, const char *fmt, va_list ap)
{
*
* talloc_set_name_const(ptr, ptr)
*/
-char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_FMT(2,3);
/**
* talloc_append_string - concatenate onto a tallocated string
* talloc_set_name_const(ptr, ptr)
*/
char *WARN_UNUSED_RESULT talloc_asprintf_append(char *s, const char *fmt, ...)
- PRINTF_ATTRIBUTE(2,3);
+ PRINTF_FMT(2,3);
/**
* talloc_vasprintf - vsprintf into a talloc buffer.
*
* talloc_set_name_const(ptr, ptr)
*/
-char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
+char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
+ PRINTF_FMT(2,0);
/**
* talloc_vasprintf_append - sprintf onto the end of a talloc buffer.
* talloc_asprintf_append(), except it takes a va_list.
*/
char *WARN_UNUSED_RESULT talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
- PRINTF_ATTRIBUTE(2,0);
+ PRINTF_FMT(2,0);
/**
* talloc_set_type - force the name of a pointer to a particular type
* without releasing the name. All of the memory is released when the ptr is
* freed using talloc_free().
*/
-const char *talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+const char *talloc_set_name(const void *ptr, const char *fmt, ...)
+ PRINTF_FMT(2,3);
/**
* talloc_set_name_const - set a talloc pointer name to a string constant
* talloc_set_name(ptr, fmt, ....);
*/
void *talloc_named(const void *context, size_t size,
- const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
+ const char *fmt, ...) PRINTF_FMT(3,4);
/**
* talloc_named_const - create a specifically-named talloc pointer
*
* talloc_named(NULL, 0, fmt, ...);
*/
-void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
+void *talloc_init(const char *fmt, ...) PRINTF_FMT(1,2);
/**
* talloc_total_size - get the bytes used by the pointer and its children
# define skip_end } while(0)
unsigned int _gen_result(int, const char *, const char *, unsigned int,
- const char *, ...) PRINTF_ATTRIBUTE(5, 6);
+ const char *, ...) PRINTF_FMT(5, 6);
/**
* diag - print a diagnostic message (use instead of printf/fprintf)
* Example:
* diag("Now running complex tests");
*/
-void diag(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
+void diag(const char *fmt, ...) PRINTF_FMT(1, 2);
/**
* skip - print a diagnostic message (use instead of printf/fprintf)
* skip(1, "Don't have SOME_FEATURE");
* #endif
*/
-void skip(unsigned int n, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
+void skip(unsigned int n, const char *fmt, ...) PRINTF_FMT(2, 3);
/**
* todo_start - mark tests that you expect to fail.
* ok(dwim(), "Did what the user wanted");
* todo_end();
*/
-void todo_start(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
+void todo_start(const char *fmt, ...) PRINTF_FMT(1, 2);
/**
* todo_end - end of tests you expect to fail.
}
/* a default logging function */
-static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
+static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) PRINTF_FMT(3, 4);
static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
{
}
typedef struct tdb_context TDB_CONTEXT;
typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
-typedef void (*tdb_log_func)(struct tdb_context *, enum tdb_debug_level, const char *, ...) PRINTF_ATTRIBUTE(3, 4);
+typedef void (*tdb_log_func)(struct tdb_context *, enum tdb_debug_level, const char *, ...) PRINTF_FMT(3, 4);
typedef unsigned int (*tdb_hash_func)(TDB_DATA *key);
struct tdb_logging_context {
static int count_pipe;
static struct tdb_logging_context log_ctx;
-#ifdef PRINTF_ATTRIBUTE
-static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4);
+#ifdef PRINTF_FMT
+static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_FMT(3,4);
#endif
static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...)
{
/* all contexts, to ensure no double-opens (fcntl locks don't nest!) */
static struct tdb_context *tdbs = NULL;
-PRINTF_ATTRIBUTE(4, 5) static void
+PRINTF_FMT(4, 5) static void
null_log_fn(struct tdb_context *tdb,
enum tdb_debug_level level, void *priv,
const char *fmt, ...)
/* FIXME: Make typesafe */
typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
-typedef void (*tdb_logfn_t)(struct tdb_context *, enum tdb_debug_level, void *priv, const char *, ...) PRINTF_ATTRIBUTE(4, 5);
+typedef void (*tdb_logfn_t)(struct tdb_context *, enum tdb_debug_level, void *priv, const char *, ...) PRINTF_FMT(4, 5);
typedef uint64_t (*tdb_hashfn_t)(const void *key, size_t len, uint64_t seed,
void *priv);
static union tdb_attribute log_attr;
static union tdb_attribute seed_attr;
-#ifdef PRINTF_ATTRIBUTE
-static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, void *private, const char *format, ...) PRINTF_ATTRIBUTE(4,5);
+#ifdef PRINTF_FMT
+static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, void *private, const char *format, ...) PRINTF_FMT(4,5);
#endif
static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, void *private, const char *format, ...)
{