[glib/wip/pwithnall/meson-cleanups: 31/31] build: Factor out some size_t checks




commit e684cddb133f08e205ab51cadec4833c078a319e
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu May 12 11:19:15 2022 +0100

    build: Factor out some size_t checks
    
    With Meson 0.60 (or possibly some earlier versions) we can factor the
    checks out as a variable can now be used as an array key. This
    simplifies the checks a little, while introducing no functional
    differences.
    
    The contents of `g_sizet_compatibility` after this block are identical
    with and without the changes applied.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 meson.build | 44 ++++++--------------------------------------
 1 file changed, 6 insertions(+), 38 deletions(-)
---
diff --git a/meson.build b/meson.build
index 53012a9213..25c95eb8db 100644
--- a/meson.build
+++ b/meson.build
@@ -1511,52 +1511,20 @@ g_sizet_compatibility = {
 # Do separate checks for gcc/clang (and ignore other compilers for now), since
 # we need to explicitly pass -Werror to the compilers.
 # FIXME: https://github.com/mesonbuild/meson/issues/5399
-# We can’t simplify these checks using a foreach loop because dictionary keys
-# have to be string literals.
-# FIXME: https://github.com/mesonbuild/meson/issues/5231
 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
-  g_sizet_compatibility += {
-    'short': g_sizet_compatibility['short'] and cc.compiles(
+  foreach type_name, size_compatibility : g_sizet_compatibility
+    g_sizet_compatibility += { type_name: size_compatibility and
+      cc.compiles(
         '''#include <stddef.h>
         size_t f (size_t *i) { return *i + 1; }
         int main (void) {
-          unsigned short i = 0;
+          unsigned ''' + type_name + ''' i = 0;
           f (&i);
           return 0;
         }''',
         args: ['-Werror'],
-        name : 'GCC size_t typedef is short'),
-    'int': g_sizet_compatibility['int'] and cc.compiles(
-        '''#include <stddef.h>
-        size_t f (size_t *i) { return *i + 1; }
-        int main (void) {
-          unsigned int i = 0;
-          f (&i);
-          return 0;
-        }''',
-        args: ['-Werror'],
-        name : 'GCC size_t typedef is int'),
-    'long': g_sizet_compatibility['long'] and cc.compiles(
-        '''#include <stddef.h>
-        size_t f (size_t *i) { return *i + 1; }
-        int main (void) {
-          unsigned long i = 0;
-          f (&i);
-          return 0;
-        }''',
-        args: ['-Werror'],
-        name : 'GCC size_t typedef is long'),
-    'long long': g_sizet_compatibility['long long'] and cc.compiles(
-        '''#include <stddef.h>
-        size_t f (size_t *i) { return *i + 1; }
-        int main (void) {
-          unsigned long long i = 0;
-          f (&i);
-          return 0;
-        }''',
-        args: ['-Werror'],
-        name : 'GCC size_t typedef is long long'),
-  }
+        name : 'GCC size_t typedef is ' + type_name), }
+  endforeach
 endif
 
 if g_sizet_compatibility['short']


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]