X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fcompiler%2Fcompiler.h;h=651b47cee9dcd611ad7c8513d92ec06ba852bb63;hb=HEAD;hp=624474b7e3b9fd030b3c8b953c8e531d14914819;hpb=9f06b8f85927202c05751e43f285cbef8054052b;p=ccan diff --git a/ccan/compiler/compiler.h b/ccan/compiler/compiler.h index 624474b7..562b29ec 100644 --- a/ccan/compiler/compiler.h +++ b/ccan/compiler/compiler.h @@ -271,6 +271,19 @@ #define NON_NULL_ARGS(...) #endif +#if HAVE_ATTRIBUTE_RETURNS_NONNULL +/** + * RETURNS_NONNULL - specify that this function cannot return NULL. + * + * Mainly an optimization opportunity, but can also suppress warnings. + * + * Example: + * RETURNS_NONNULL char *my_copy(char *buf); + */ +#define RETURNS_NONNULL __attribute__((__returns_nonnull__)) +#else +#define RETURNS_NONNULL +#endif #if HAVE_ATTRIBUTE_SENTINEL /** @@ -286,4 +299,19 @@ #define LAST_ARG_NULL #endif +#if HAVE_BUILTIN_CPU_SUPPORTS +/** + * cpu_supports - test if current CPU supports the named feature. + * + * This takes a literal string, and currently only works on glibc platforms. + * + * Example: + * if (cpu_supports("mmx")) + * printf("MMX support engaged!\n"); + */ +#define cpu_supports(x) __builtin_cpu_supports(x) +#else +#define cpu_supports(x) 0 +#endif /* HAVE_BUILTIN_CPU_SUPPORTS */ + #endif /* CCAN_COMPILER_H */