From 21dcde096f351f83a2df7aa9f42a7276b5454c81 Mon Sep 17 00:00:00 2001 From: Roman Stratiienko Date: Thu, 10 Aug 2023 16:14:02 +0300 Subject: [PATCH] util: Add NONNULL macro Macro leverages __attribute__((__nonnull__)) to help users mark the function parameter that isn't allowed to be NULL. Suggested-by: Eric Engestrom Signed-off-by: Roman Stratiienko Reviewed-by: Eric Engestrom Part-of: --- meson.build | 1 + src/util/macros.h | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/meson.build b/meson.build index 83f4e9cf66d..3fac5d2eb58 100644 --- a/meson.build +++ b/meson.build @@ -916,6 +916,7 @@ endforeach _attributes = [ 'const', 'flatten', 'malloc', 'pure', 'unused', 'warn_unused_result', 'weak', 'format', 'packed', 'returns_nonnull', 'alias', 'noreturn', + 'nonnull', ] foreach a : cc.get_supported_function_attributes(_attributes) pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper()) diff --git a/src/util/macros.h b/src/util/macros.h index bffabfb52a8..0bf1dac413f 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -317,6 +317,12 @@ do { \ #define ASSERTED #endif +#ifdef HAVE_FUNC_ATTRIBUTE_NONNULL +#define NONNULL __attribute__((__nonnull__)) +#else +#define NONNULL +#endif + #ifdef HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT #define MUST_CHECK __attribute__((warn_unused_result)) #else