]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Convert most #ifdef HAVE_FOO checks to #if HAVE_FOO
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 24 May 2025 15:21:18 +0000 (16:21 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 30 May 2025 14:02:15 +0000 (09:02 -0500)
The former is somewhat error prone, since the pre-processor will
evaluate the presence of the define, which might have been omitted due
to wrong include or otherwise.

Swap for the other solution we already have in-tree - always set the
relevant define(s) and evaluate them numerically. That combined with
-Wundef means that we'll get meaningful compiler warning when we get
something wrong.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/356
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-internal.h
meson.build
shared/macro.h
testsuite/path.c

index d78a275691c240223c5317d99470278aa4f71243..547b8369044f3fb99462a4ef38893d9d9e37486d 100644 (file)
@@ -27,7 +27,7 @@
 
 #define KCMD_LINE_SIZE 4096
 
-#ifndef HAVE_SECURE_GETENV
+#if !HAVE_SECURE_GETENV
 #warning secure_getenv is not available
 #define secure_getenv getenv
 #endif
index 4f3e9551fc925957f356c6493d1d6ab7b55460f3..4a718275d7cb1711bd18f6a3ac920bbc478ccadb 100644 (file)
@@ -27,8 +27,6 @@ cc = meson.get_compiler('c')
 # We rely on the glibc variant of basename, et al.
 cdata.set10('_GNU_SOURCE', true)
 
-# TODO: Once meson-only, adjust all #ifdef X to if X and convert .set to .set10
-
 ################################################################################
 # Function and structure checks
 ################################################################################
@@ -38,9 +36,7 @@ _funcs = [
   'secure_getenv',
 ]
 foreach func : _funcs
-  if cc.has_function(func, args : '-D_GNU_SOURCE')
-    cdata.set('HAVE_@0@'.format(func.to_upper()), true)
-  endif
+  cdata.set10('HAVE_@0@'.format(func.to_upper()), cc.has_function(func, args : '-D_GNU_SOURCE'))
 endforeach
 
 # Meson has some amount of support for finding builtins by passing the symbol
@@ -94,17 +90,8 @@ foreach tuple : _decls
   cdata.set10('HAVE_DECL_@0@'.format(decl.to_upper()), have)
 endforeach
 
-if cc.compiles('_Static_assert(1, "Test");', name : '_Static_assert')
-  cdata.set('HAVE_STATIC_ASSERT', true)
-endif
-
-if cc.compiles('''
-    #include <stdlib.h>
-    _Noreturn int foo(void) { exit(0); }
-    ''',
-    name : '_Noreturn')
-  cdata.set('HAVE_NORETURN', true)
-endif
+cdata.set10('HAVE_STATIC_ASSERT', cc.compiles('_Static_assert(1, "Test");', name : '_Static_assert'))
+cdata.set10('HAVE_NORETURN', cc.compiles('#include <stdlib.h>; _Noreturn int foo(void) { exit(0); }', name : '_Noreturn'))
 
 ################################################################################
 # Default CFLAGS and LDFLAGS
index 8829d0b65df17ab7963303a0480dd62b2ef66d63..15a95a3b0d8770e0d090fac42258fe6ae7cb0e11 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <stddef.h>
 
-#if defined(HAVE_STATIC_ASSERT)
+#if HAVE_STATIC_ASSERT
 #define assert_cc(expr) _Static_assert((expr), #expr)
 #else
 #define assert_cc(expr)                              \
@@ -73,7 +73,7 @@ static inline void freep(void *p)
 /* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
  * compiler versions */
 #ifndef noreturn
-#if defined(HAVE_NORETURN)
+#if HAVE_NORETURN
 #define noreturn _Noreturn
 #else
 #define noreturn __attribute__((noreturn))
index 25548f491fe04a4f6f523eb7b6314348a1c60565..3024d50e0d397dbaaa188466540a948b63696178 100644 (file)
@@ -175,19 +175,19 @@ WRAP_2ARGS(int, -1, stat, struct stat *);
 
 WRAP_OPEN();
 
-#ifdef HAVE_FOPEN64
+#if HAVE_FOPEN64
 WRAP_2ARGS(FILE *, NULL, fopen64, const char *);
 #endif
-#ifdef HAVE_STAT64
+#if HAVE_STAT64
 WRAP_2ARGS(int, -1, stat64, struct stat64 *);
 #endif
 
-#ifdef HAVE___STAT64_TIME64
+#if HAVE___STAT64_TIME64
 extern int __stat64_time64(const char *file, void *buf);
 WRAP_2ARGS(int, -1, __stat64_time64, void *);
 #endif
 
-#ifdef HAVE_OPEN64
+#if HAVE_OPEN64
 WRAP_OPEN(64);
 #endif