util: Add NONNULL macro
authorRoman Stratiienko <r.stratiienko@gmail.com>
Thu, 10 Aug 2023 13:14:02 +0000 (16:14 +0300)
committerMarge Bot <emma+marge@anholt.net>
Sat, 12 Aug 2023 18:46:57 +0000 (18:46 +0000)
Macro leverages __attribute__((__nonnull__)) to help users mark
the function parameter that isn't allowed to be NULL.

Suggested-by: Eric Engestrom <eric@igalia.com>
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Eric Engestrom <eric@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18215>

meson.build
src/util/macros.h

index 83f4e9c..3fac5d2 100644 (file)
@@ -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())
index bffabfb..0bf1dac 100644 (file)
@@ -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