]> git.ozlabs.org Git - ccan/blobdiff - ccan/compiler/compiler.h
compiler: RETURNS_NONNULL macro
[ccan] / ccan / compiler / compiler.h
index 624474b7e3b9fd030b3c8b953c8e531d14914819..562b29ec71cc13969ab0d111477608cdbc9d9c36 100644 (file)
 #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
 /**
 #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 */