diff options
Diffstat (limited to 'gl/m4/stddef_h.m4')
-rw-r--r-- | gl/m4/stddef_h.m4 | 81 |
1 files changed, 69 insertions, 12 deletions
diff --git a/gl/m4/stddef_h.m4 b/gl/m4/stddef_h.m4 index 5da8ab1..a2322eb 100644 --- a/gl/m4/stddef_h.m4 +++ b/gl/m4/stddef_h.m4 | |||
@@ -1,19 +1,61 @@ | |||
1 | dnl A placeholder for POSIX 2008 <stddef.h>, for platforms that have issues. | 1 | # stddef_h.m4 serial 13 |
2 | # stddef_h.m4 serial 4 | 2 | dnl Copyright (C) 2009-2023 Free Software Foundation, Inc. |
3 | dnl Copyright (C) 2009-2013 Free Software Foundation, Inc. | ||
4 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
5 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
6 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
7 | 6 | ||
8 | AC_DEFUN([gl_STDDEF_H], | 7 | dnl A placeholder for <stddef.h>, for platforms that have issues. |
8 | |||
9 | AC_DEFUN_ONCE([gl_STDDEF_H], | ||
9 | [ | 10 | [ |
10 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) | 11 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) |
11 | AC_REQUIRE([gt_TYPE_WCHAR_T]) | 12 | AC_REQUIRE([gt_TYPE_WCHAR_T]) |
12 | STDDEF_H= | 13 | |
14 | dnl Persuade OpenBSD <stddef.h> to declare max_align_t. | ||
15 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | ||
16 | |||
17 | GL_GENERATE_STDDEF_H=false | ||
18 | |||
19 | dnl Test whether the type max_align_t exists and whether its alignment | ||
20 | dnl "is as great as is supported by the implementation in all contexts". | ||
21 | AC_CACHE_CHECK([for good max_align_t], | ||
22 | [gl_cv_type_max_align_t], | ||
23 | [AC_COMPILE_IFELSE( | ||
24 | [AC_LANG_PROGRAM( | ||
25 | [[/* On FreeBSD 12.0/x86, max_align_t defined by <stddef.h> has | ||
26 | the correct alignment with the default (wrong) definition of | ||
27 | _Alignof, but a wrong alignment as soon as we activate an | ||
28 | ISO C compliant _Alignof definition. */ | ||
29 | #if ((defined __GNUC__ && 4 <= __GNUC__) || defined __clang__) && !defined __cplusplus | ||
30 | #define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b) | ||
31 | #endif | ||
32 | #include <stddef.h> | ||
33 | unsigned int s = sizeof (max_align_t); | ||
34 | #if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__ | ||
35 | int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1]; | ||
36 | int check2[2 * (__alignof__ (long double) <= __alignof__ (max_align_t)) - 1]; | ||
37 | #endif | ||
38 | typedef struct { char a; max_align_t b; } max_helper; | ||
39 | typedef struct { char a; long b; } long_helper; | ||
40 | typedef struct { char a; double b; } double_helper; | ||
41 | typedef struct { char a; long double b; } long_double_helper; | ||
42 | int check3[2 * (offsetof (long_helper, b) <= offsetof (max_helper, b)) - 1]; | ||
43 | int check4[2 * (offsetof (double_helper, b) <= offsetof (max_helper, b)) - 1]; | ||
44 | int check5[2 * (offsetof (long_double_helper, b) <= offsetof (max_helper, b)) - 1]; | ||
45 | ]])], | ||
46 | [gl_cv_type_max_align_t=yes], | ||
47 | [gl_cv_type_max_align_t=no]) | ||
48 | ]) | ||
49 | if test $gl_cv_type_max_align_t = no; then | ||
50 | HAVE_MAX_ALIGN_T=0 | ||
51 | GL_GENERATE_STDDEF_H=true | ||
52 | fi | ||
53 | |||
13 | if test $gt_cv_c_wchar_t = no; then | 54 | if test $gt_cv_c_wchar_t = no; then |
14 | HAVE_WCHAR_T=0 | 55 | HAVE_WCHAR_T=0 |
15 | STDDEF_H=stddef.h | 56 | GL_GENERATE_STDDEF_H=true |
16 | fi | 57 | fi |
58 | |||
17 | AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions], | 59 | AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions], |
18 | [gl_cv_decl_null_works], | 60 | [gl_cv_decl_null_works], |
19 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h> | 61 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h> |
@@ -23,25 +65,40 @@ AC_DEFUN([gl_STDDEF_H], | |||
23 | [gl_cv_decl_null_works=no])]) | 65 | [gl_cv_decl_null_works=no])]) |
24 | if test $gl_cv_decl_null_works = no; then | 66 | if test $gl_cv_decl_null_works = no; then |
25 | REPLACE_NULL=1 | 67 | REPLACE_NULL=1 |
26 | STDDEF_H=stddef.h | 68 | GL_GENERATE_STDDEF_H=true |
27 | fi | 69 | fi |
28 | AC_SUBST([STDDEF_H]) | 70 | |
29 | AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"]) | 71 | if $GL_GENERATE_STDDEF_H; then |
30 | if test -n "$STDDEF_H"; then | ||
31 | gl_NEXT_HEADERS([stddef.h]) | 72 | gl_NEXT_HEADERS([stddef.h]) |
32 | fi | 73 | fi |
33 | ]) | 74 | ]) |
34 | 75 | ||
76 | # gl_STDDEF_MODULE_INDICATOR([modulename]) | ||
77 | # sets the shell variable that indicates the presence of the given module | ||
78 | # to a C preprocessor expression that will evaluate to 1. | ||
79 | # This macro invocation must not occur in macros that are AC_REQUIREd. | ||
35 | AC_DEFUN([gl_STDDEF_MODULE_INDICATOR], | 80 | AC_DEFUN([gl_STDDEF_MODULE_INDICATOR], |
36 | [ | 81 | [ |
37 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. | 82 | dnl Ensure to expand the default settings once only. |
38 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) | 83 | gl_STDDEF_H_REQUIRE_DEFAULTS |
39 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) | 84 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) |
40 | ]) | 85 | ]) |
41 | 86 | ||
87 | # Initializes the default values for AC_SUBSTed shell variables. | ||
88 | # This macro must not be AC_REQUIREd. It must only be invoked, and only | ||
89 | # outside of macros or in macros that are not AC_REQUIREd. | ||
90 | AC_DEFUN([gl_STDDEF_H_REQUIRE_DEFAULTS], | ||
91 | [ | ||
92 | m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS], [ | ||
93 | ]) | ||
94 | m4_require(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS]) | ||
95 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) | ||
96 | ]) | ||
97 | |||
42 | AC_DEFUN([gl_STDDEF_H_DEFAULTS], | 98 | AC_DEFUN([gl_STDDEF_H_DEFAULTS], |
43 | [ | 99 | [ |
44 | dnl Assume proper GNU behavior unless another module says otherwise. | 100 | dnl Assume proper GNU behavior unless another module says otherwise. |
45 | REPLACE_NULL=0; AC_SUBST([REPLACE_NULL]) | 101 | REPLACE_NULL=0; AC_SUBST([REPLACE_NULL]) |
102 | HAVE_MAX_ALIGN_T=1; AC_SUBST([HAVE_MAX_ALIGN_T]) | ||
46 | HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T]) | 103 | HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T]) |
47 | ]) | 104 | ]) |