if (strcmp(argv[1], "depends") == 0) {
printf("ccan/alignof\n");
printf("ccan/build_assert\n");
+ printf("ccan/compiler\n");
printf("ccan/likely\n");
printf("ccan/short_types\n");
return 0;
#include <ccan/likely/likely.h>
#include <ccan/alignof/alignof.h>
#include <ccan/short_types/short_types.h>
+#include <ccan/compiler/compiler.h>
#include "config.h"
/*
}
/* They want something really big. Aim for contiguous pages (slow). */
-static void *unlikely_func huge_alloc(void *pool, unsigned long poolsize,
- unsigned long size, unsigned long align)
+static COLD_ATTRIBUTE
+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 void unlikely_func huge_free(struct header *head,
- unsigned long poolsize, void *free)
+static COLD_ATTRIBUTE void
+huge_free(struct header *head, unsigned long poolsize, void *free)
{
unsigned long i, off, pgnum, free_off = (char *)free - (char *)head;
unsigned int sp_bits, lp_bits;
alloc_free(head, poolsize, ha);
}
-static unsigned long unlikely_func huge_size(struct header *head, void *p)
+static COLD_ATTRIBUTE unsigned long
+huge_size(struct header *head, void *p)
{
unsigned long i, off = (char *)p - (char *)head;
struct huge_alloc *ha;
#include <ccan/talloc/talloc.h>
#endif
-#ifndef HAVE_ATTRIBUTE_MAY_ALIAS
-#define HAVE_ATTRIBUTE_MAY_ALIAS 1
-#endif
-
//Use the array_alias macro to indicate that a pointer has changed but strict aliasing rules are too stupid to know it
-#if HAVE_ATTRIBUTE_MAY_ALIAS==1
+#if HAVE_ATTRIBUTE_MAY_ALIAS
#define array_alias(ptr) /* nothing */
#define array(type) struct {type *item; size_t size; size_t alloc;} __attribute__((__may_alias__))
#else
#if HAVE_ATTRIBUTE_COLD
/**
- * UNLIKELY_FUNCTION_ATTRIBUTE - a function is unlikely to be called.
+ * COLD_ATTRIBUTE - 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:
- * void UNLIKELY_FUNCTION_ATTRIBUTE moan(const char *reason)
+ * void COLD_ATTRIBUTE moan(const char *reason)
* {
* fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
* }
*/
-#define UNLIKELY_FUNCTION_ATTRIBUTE __attribute__((cold))
+#define COLD_ATTRIBUTE __attribute__((cold))
#else
-#define UNLIKELY_FUNCTION_ATTRIBUTE
+#define COLD_ATTRIBUTE
#endif
#if HAVE_ATTRIBUTE_PRINTF
#if !defined(_ilog_H)
# define _ilog_H (1)
+# include "config.h"
# include <stdint.h>
-
-# ifdef __GNUC_PREREQ
-/*Tag our functions as idempotent to aid optimization, if possible.*/
-# if __GNUC_PREREQ(2,5)
-# define IDEMPOTENT __attribute__((const))
-# endif
-# if __GNUC_PREREQ(3,4)
-# include <limits.h>
+# include <ccan/compiler/compiler.h>
+# include <limits.h>
/*Note the casts to (int) below: this prevents CLZ{32|64}_OFFS from "upgrading"
the type of an entire expression to an (unsigned) size_t.*/
-# if INT_MAX>=2147483647
-# define CLZ32_OFFS ((int)sizeof(unsigned)*CHAR_BIT)
-# define CLZ32(_x) (__builtin_clz(_x))
-# elif LONG_MAX>=2147483647L
-# define CLZ32_OFFS ((int)sizeof(unsigned long)*CHAR_BIT)
-# define CLZ32(_x) (__builtin_clzl(_x))
-# endif
-# if INT_MAX>=9223372036854775807LL
-# define CLZ64_OFFS ((int)sizeof(unsigned)*CHAR_BIT)
-# define CLZ64(_x) (__builtin_clz(_x))
-# elif LONG_MAX>=9223372036854775807LL
-# define CLZ64_OFFS ((int)sizeof(unsigned long)*CHAR_BIT)
-# define CLZ64(_x) (__builtin_clzl(_x))
-# else /* long long must be >= 64 bits according to ISO C */
-# define CLZ64_OFFS ((int)sizeof(unsigned long long)*CHAR_BIT)
-# define CLZ64(_x) (__builtin_clzll(_x))
-# endif
-# endif
+# if HAVE_BUILTIN_CLZ && INT_MAX>=2147483647
+# define CLZ32_OFFS ((int)sizeof(unsigned)*CHAR_BIT)
+# define CLZ32(_x) (__builtin_clz(_x))
+# elif HAVE_BUILTIN_CLZL && LONG_MAX>=2147483647L
+# define CLZ32_OFFS ((int)sizeof(unsigned long)*CHAR_BIT)
+# define CLZ32(_x) (__builtin_clzl(_x))
# endif
-/*If you have some other compiler which defines its own clz-style builtin,
- implement a check for it here.*/
-
-# if !defined(IDEMPOTENT)
-# define IDEMPOTENT
+# if HAVE_BUILTIN_CLZ && INT_MAX>=9223372036854775807LL
+# define CLZ64_OFFS ((int)sizeof(unsigned)*CHAR_BIT)
+# define CLZ64(_x) (__builtin_clz(_x))
+# elif HAVE_BUILTIN_CLZL && LONG_MAX>=9223372036854775807LL
+# define CLZ64_OFFS ((int)sizeof(unsigned long)*CHAR_BIT)
+# define CLZ64(_x) (__builtin_clzl(_x))
+# elif HAVE_BUILTIN_CLZLL /* long long must be >= 64 bits according to ISO C */
+# define CLZ64_OFFS ((int)sizeof(unsigned long long)*CHAR_BIT)
+# define CLZ64(_x) (__builtin_clzll(_x))
# endif
* The ILOG_32() or ILOGNZ_32() macros may be able to use a builtin function
* instead, which should be faster.
*/
-int ilog32(uint32_t _v)IDEMPOTENT;
+int ilog32(uint32_t _v) IDEMPOTENT_ATTRIBUTE;
/**
* ilog64 - Integer binary logarithm of a 64-bit value.
* @_v: A 64-bit value.
* The ILOG_64() or ILOGNZ_64() macros may be able to use a builtin function
* instead, which should be faster.
*/
-int ilog64(uint64_t _v)IDEMPOTENT;
-
-# undef IDEMPOTENT
+int ilog64(uint64_t _v) IDEMPOTENT_ATTRIBUTE;
# if defined(CLZ32)
* 99%; marginal cases should not be marked either way.
*
* See Also:
- * unlikely(), unlikely_func, likely_stats()
+ * unlikely(), likely_stats()
*
* Example:
* // Returns false if we overflow.
* code path and optimize appropriately; see likely() above.
*
* See Also:
- * likely(), unlikely_func, likely_stats()
+ * likely(), likely_stats(), UNLIKELY_FUNCTION_ATTRIBUTE (compiler.h)
*
* Example:
* // Prints a warning if we overflow.
const char *file, unsigned int line);
#endif
-#if HAVE_ATTRIBUTE_COLD
-/**
- * unlikely_func - indicate that a function is unlikely to be called.
- *
- * This uses a compiler extension where available to indicate an unlikely
- * code path and optimize appropriately; see unlikely() above.
- *
- * It is usually used on logging or error routines.
- *
- * See Also:
- * unlikely()
- *
- * Example:
- * void unlikely_func die_moaning(const char *reason)
- * {
- * fprintf(stderr, "Dying: %s\n", reason);
- * exit(1);
- * }
- */
-#define unlikely_func __attribute__((cold))
-#else
-#define unlikely_func
-#endif
-
#ifdef DEBUG
/**
* likely_stats - return description of abused likely()/unlikely()
*
* When DEBUG is defined, likely() and unlikely() trace their results: this
* causes a significant slowdown, but allows analysis of whether the stats
- * are correct (unlikely_func can't traced).
+ * are correct.
*
* This function returns a malloc'ed description of the least-correct
* usage of likely() or unlikely(). It ignores places which have been
return false;
}
-static unlikely_func bool calling_is_unlikely(void)
-{
- return true;
-}
-
int main(int argc, char *argv[])
{
- plan_tests(5);
+ plan_tests(4);
/* Without debug, we can only check that it doesn't effect functions. */
ok1(one_seems_likely(1));
ok1(!one_seems_likely(2));
ok1(one_seems_unlikely(1));
ok1(!one_seems_unlikely(2));
- ok1(calling_is_unlikely());
exit(exit_status());
}
return 1;
if (strcmp(argv[1], "depends") == 0) {
+ printf("ccan/compiler\n");
printf("ccan/typesafe_cb\n");
return 0;
}
#include <stdio.h>
#include <stdarg.h>
#include <ccan/typesafe_cb/typesafe_cb.h>
+#include <ccan/compiler/compiler.h>
#include "config.h"
/*
#define __location__ __FILE__ ":" __TALLOC_STRING_LINE3__
#endif
-#if HAVE_ATTRIBUTE_PRINTF
-/** Use gcc attribute to check printf fns. a1 is the 1-based index of
- * the parameter containing the format, and a2 the index of the first
- * argument. Note that some gcc 2.x versions don't handle this
- * properly **/
-#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
-#else
-#define PRINTF_ATTRIBUTE(a1, a2)
-#endif
-
/* try to make talloc_set_destructor() and talloc_steal() type safe,
if we have a recent gcc */
#if HAVE_TYPEOF
if (argc != 2)
return 1;
- if (strcmp(argv[1], "depends") == 0)
+ if (strcmp(argv[1], "depends") == 0) {
+ printf("ccan/compiler\n");
return 0;
+ }
return 1;
}
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+#include <ccan/compiler/compiler.h>
/**
* plan_tests - announce the number of tests you plan to run
# define skip_end } while(0)
-#ifndef PRINTF_ATTRIBUTE
-#ifdef __GNUC__
-#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
-#else
-#define PRINTF_ATTRIBUTE(a1, a2)
-#endif
-#endif
-
unsigned int _gen_result(int, const char *, const char *, unsigned int,
const char *, ...) PRINTF_ATTRIBUTE(5, 6);
return 1;
if (strcmp(argv[1], "depends") == 0) {
+ printf("ccan/compiler\n");
printf("ccan/tally\n");
return 0;
}
/* For sig_atomic_t. */
#include <signal.h>
#endif
+#include <ccan/compiler/compiler.h>
/* flags to tdb_store() */
#define TDB_REPLACE 1 /* Unused */
size_t dsize;
} TDB_DATA;
-#ifndef PRINTF_ATTRIBUTE
-#if (__GNUC__ >= 3)
-/** Use gcc attribute to check printf fns. a1 is the 1-based index of
- * the parameter containing the format, and a2 the index of the first
- * argument. Note that some gcc 2.x versions don't handle this
- * properly **/
-#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
-#else
-#define PRINTF_ATTRIBUTE(a1, a2)
-#endif
-#endif
-
/* this is the context structure that is returned from a db open */
typedef struct tdb_context TDB_CONTEXT;
printf("ccan/hash\n");
printf("ccan/likely\n");
printf("ccan/asearch\n");
+ printf("ccan/compiler\n");
printf("ccan/build_assert\n");
printf("ccan/tally\n");
return 0;
/* For uint64_t */
#include <stdint.h>
#endif
+#include <ccan/compiler/compiler.h>
/* flags to tdb_store() */
#define TDB_REPLACE 1 /* Unused */
size_t dsize;
} TDB_DATA;
-#ifndef PRINTF_ATTRIBUTE
-#if (__GNUC__ >= 3)
-/** Use gcc attribute to check printf fns. a1 is the 1-based index of
- * the parameter containing the format, and a2 the index of the first
- * argument. Note that some gcc 2.x versions don't handle this
- * properly **/
-#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
-#else
-#define PRINTF_ATTRIBUTE(a1, a2)
-#endif
-#endif
-
struct tdb_context;
/* FIXME: Make typesafe */