diff options
| author | Paul Eggert | 2019-05-29 16:33:51 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-05-29 16:34:57 -0700 |
| commit | 10582d0511f4455d5c0449fd8a1e0eca9be06d7b (patch) | |
| tree | 24381cefbeedcf69b74bfc3968ccb3d71ac6199a /lib | |
| parent | fe0cb43fb80db52a79ef898f8de49560cc5cdd90 (diff) | |
| download | emacs-10582d0511f4455d5c0449fd8a1e0eca9be06d7b.tar.gz emacs-10582d0511f4455d5c0449fd8a1e0eca9be06d7b.zip | |
Update from Gnulib
This incorporates:
2019-05-24 flexmember: update comments
2019-05-18 pthread_sigmask: fix --enable-threads=windows compilation
2019-05-14 close-stream, closein, closeout: simplify
2019-05-09 verify: remove verify_true
2019-05-09 verify: support C2X and C++17 static_assert
* build-aux/config.guess, build-aux/config.sub:
* doc/misc/texinfo.tex, lib/flexmember.h, lib/verify.h:
* m4/flexmember.m4, m4/pthread_sigmask.m4:
Copy from Gnulib
* m4/gnulib-comp.m4: Regenerate.
2019-05-26 Paul Eggert <eggert@cs.ucla.edu>
Update author/maintainer info
This mostly updates email addresses and fixes spellings of
author and maintainer names.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/flexmember.h | 25 | ||||
| -rw-r--r-- | lib/verify.h | 110 |
2 files changed, 76 insertions, 59 deletions
diff --git a/lib/flexmember.h b/lib/flexmember.h index 0d65f6da60f..af17b41d29f 100644 --- a/lib/flexmember.h +++ b/lib/flexmember.h | |||
| @@ -33,11 +33,26 @@ | |||
| 33 | # define FLEXALIGNOF(type) _Alignof (type) | 33 | # define FLEXALIGNOF(type) _Alignof (type) |
| 34 | #endif | 34 | #endif |
| 35 | 35 | ||
| 36 | /* Upper bound on the size of a struct of type TYPE with a flexible | 36 | /* Yield a properly aligned upper bound on the size of a struct of |
| 37 | array member named MEMBER that is followed by N bytes of other data. | 37 | type TYPE with a flexible array member named MEMBER that is |
| 38 | This is not simply sizeof (TYPE) + N, since it may require | 38 | followed by N bytes of other data. The result is suitable as an |
| 39 | alignment on unusually picky C11 platforms, and | 39 | argument to malloc. For example: |
| 40 | FLEXIBLE_ARRAY_MEMBER may be 1 on pre-C11 platforms. | 40 | |
| 41 | struct s { int n; char d[FLEXIBLE_ARRAY_MEMBER]; }; | ||
| 42 | struct s *p = malloc (FLEXSIZEOF (struct s, d, n * sizeof (char))); | ||
| 43 | |||
| 44 | FLEXSIZEOF (TYPE, MEMBER, N) is not simply (sizeof (TYPE) + N), | ||
| 45 | since FLEXIBLE_ARRAY_MEMBER may be 1 on pre-C11 platforms. Nor is | ||
| 46 | it simply (offsetof (TYPE, MEMBER) + N), as that might yield a size | ||
| 47 | that causes malloc to yield a pointer that is not properly aligned | ||
| 48 | for TYPE; for example, if sizeof (int) == alignof (int) == 4, | ||
| 49 | malloc (offsetof (struct s, d) + 3 * sizeof (char)) is equivalent | ||
| 50 | to malloc (7) and might yield a pointer that is not a multiple of 4 | ||
| 51 | (which means the pointer is not properly aligned for struct s), | ||
| 52 | whereas malloc (FLEXSIZEOF (struct s, d, 3 * sizeof (char))) is | ||
| 53 | equivalent to malloc (8) and must yield a pointer that is a | ||
| 54 | multiple of 4. | ||
| 55 | |||
| 41 | Yield a value less than N if and only if arithmetic overflow occurs. */ | 56 | Yield a value less than N if and only if arithmetic overflow occurs. */ |
| 42 | 57 | ||
| 43 | #define FLEXSIZEOF(type, member, n) \ | 58 | #define FLEXSIZEOF(type, member, n) \ |
diff --git a/lib/verify.h b/lib/verify.h index 6930645a350..f8e4eff026d 100644 --- a/lib/verify.h +++ b/lib/verify.h | |||
| @@ -21,29 +21,37 @@ | |||
| 21 | #define _GL_VERIFY_H | 21 | #define _GL_VERIFY_H |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11. | 24 | /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC) |
| 25 | This is supported by GCC 4.6.0 and later, in C mode, and its use | 25 | works as per C11. This is supported by GCC 4.6.0 and later, in C |
| 26 | here generates easier-to-read diagnostics when verify (R) fails. | 26 | mode. |
| 27 | 27 | ||
| 28 | Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per C++11. | 28 | Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as |
| 29 | This is supported by GCC 6.1.0 and later, in C++ mode. | 29 | per C2X, and define _GL_HAVE_STATIC_ASSERT1 if static_assert (R) |
| 30 | 30 | works as per C++17. This is supported by GCC 9.1 and later. | |
| 31 | Use this only with GCC. If we were willing to slow 'configure' | 31 | |
| 32 | down we could also use it with other compilers, but since this | 32 | Support compilers claiming conformance to the relevant standard, |
| 33 | affects only the quality of diagnostics, why bother? */ | 33 | and also support GCC when not pedantic. If we were willing to slow |
| 34 | #if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \ | 34 | 'configure' down we could also use it with other compilers, but |
| 35 | && (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \ | 35 | since this affects only the quality of diagnostics, why bother? */ |
| 36 | && !defined __cplusplus) | 36 | #ifndef __cplusplus |
| 37 | # define _GL_HAVE__STATIC_ASSERT 1 | 37 | # if (201112L <= __STDC_VERSION__ \ |
| 38 | #endif | 38 | || (!defined __STRICT_ANSI__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__))) |
| 39 | #if (6 <= __GNUC__) && defined __cplusplus | 39 | # define _GL_HAVE__STATIC_ASSERT 1 |
| 40 | # define _GL_HAVE_STATIC_ASSERT 1 | 40 | # endif |
| 41 | # if (202000L <= __STDC_VERSION__ \ | ||
| 42 | || (!defined __STRICT_ANSI__ && 9 <= __GNUC__)) | ||
| 43 | # define _GL_HAVE__STATIC_ASSERT1 1 | ||
| 44 | # endif | ||
| 45 | #else | ||
| 46 | # if 201703L <= __cplusplus || 9 <= __GNUC__ | ||
| 47 | # define _GL_HAVE_STATIC_ASSERT1 1 | ||
| 48 | # endif | ||
| 41 | #endif | 49 | #endif |
| 42 | 50 | ||
| 43 | /* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other | 51 | /* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other |
| 44 | system headers, defines a conflicting _Static_assert that is no | 52 | system headers, defines a conflicting _Static_assert that is no |
| 45 | better than ours; override it. */ | 53 | better than ours; override it. */ |
| 46 | #ifndef _GL_HAVE_STATIC_ASSERT | 54 | #ifndef _GL_HAVE__STATIC_ASSERT |
| 47 | # include <stddef.h> | 55 | # include <stddef.h> |
| 48 | # undef _Static_assert | 56 | # undef _Static_assert |
| 49 | #endif | 57 | #endif |
| @@ -141,9 +149,9 @@ | |||
| 141 | which do not support _Static_assert, also do not warn about the | 149 | which do not support _Static_assert, also do not warn about the |
| 142 | last declaration mentioned above. | 150 | last declaration mentioned above. |
| 143 | 151 | ||
| 144 | * GCC warns if -Wnested-externs is enabled and verify() is used | 152 | * GCC warns if -Wnested-externs is enabled and 'verify' is used |
| 145 | within a function body; but inside a function, you can always | 153 | within a function body; but inside a function, you can always |
| 146 | arrange to use verify_expr() instead. | 154 | arrange to use verify_expr instead. |
| 147 | 155 | ||
| 148 | * In C++, any struct definition inside sizeof is invalid. | 156 | * In C++, any struct definition inside sizeof is invalid. |
| 149 | Use a template type to work around the problem. */ | 157 | Use a template type to work around the problem. */ |
| @@ -167,11 +175,9 @@ | |||
| 167 | #define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) | 175 | #define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) |
| 168 | 176 | ||
| 169 | /* Verify requirement R at compile-time, as an integer constant expression | 177 | /* Verify requirement R at compile-time, as an integer constant expression |
| 170 | that returns 1. If R is false, fail at compile-time, preferably | 178 | that returns 1. If R is false, fail at compile-time. */ |
| 171 | with a diagnostic that includes the string-literal DIAGNOSTIC. */ | ||
| 172 | 179 | ||
| 173 | #define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \ | 180 | #define _GL_VERIFY_TRUE(R) (!!sizeof (_GL_VERIFY_TYPE (R))) |
| 174 | (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC))) | ||
| 175 | 181 | ||
| 176 | #ifdef __cplusplus | 182 | #ifdef __cplusplus |
| 177 | # if !GNULIB_defined_struct__gl_verify_type | 183 | # if !GNULIB_defined_struct__gl_verify_type |
| @@ -181,40 +187,43 @@ template <int w> | |||
| 181 | }; | 187 | }; |
| 182 | # define GNULIB_defined_struct__gl_verify_type 1 | 188 | # define GNULIB_defined_struct__gl_verify_type 1 |
| 183 | # endif | 189 | # endif |
| 184 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | 190 | # define _GL_VERIFY_TYPE(R) _gl_verify_type<(R) ? 1 : -1> |
| 185 | _gl_verify_type<(R) ? 1 : -1> | 191 | #elif defined _GL_HAVE__STATIC_ASSERT1 |
| 186 | #elif defined _GL_HAVE__STATIC_ASSERT | 192 | # define _GL_VERIFY_TYPE(R) \ |
| 187 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 188 | struct { \ | 193 | struct { \ |
| 189 | _Static_assert (R, DIAGNOSTIC); \ | 194 | _Static_assert (R); \ |
| 190 | int _gl_dummy; \ | 195 | int _gl_dummy; \ |
| 191 | } | 196 | } |
| 192 | #else | 197 | #else |
| 193 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | 198 | # define _GL_VERIFY_TYPE(R) \ |
| 194 | struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; } | 199 | struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; } |
| 195 | #endif | 200 | #endif |
| 196 | 201 | ||
| 197 | /* Verify requirement R at compile-time, as a declaration without a | 202 | /* Verify requirement R at compile-time, as a declaration without a |
| 198 | trailing ';'. If R is false, fail at compile-time, preferably | 203 | trailing ';'. If R is false, fail at compile-time. |
| 199 | with a diagnostic that includes the string-literal DIAGNOSTIC. | 204 | |
| 205 | This macro requires three or more arguments but uses at most the first | ||
| 206 | two, so that the _Static_assert macro optionally defined below supports | ||
| 207 | both the C11 two-argument syntax and the C2X one-argument syntax. | ||
| 200 | 208 | ||
| 201 | Unfortunately, unlike C11, this implementation must appear as an | 209 | Unfortunately, unlike C11, this implementation must appear as an |
| 202 | ordinary declaration, and cannot appear inside struct { ... }. */ | 210 | ordinary declaration, and cannot appear inside struct { ... }. */ |
| 203 | 211 | ||
| 204 | #ifdef _GL_HAVE__STATIC_ASSERT | 212 | #if defined _GL_HAVE__STATIC_ASSERT |
| 205 | # define _GL_VERIFY _Static_assert | 213 | # define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC) |
| 206 | #else | 214 | #else |
| 207 | # define _GL_VERIFY(R, DIAGNOSTIC) \ | 215 | # define _GL_VERIFY(R, DIAGNOSTIC, ...) \ |
| 208 | extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ | 216 | extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ |
| 209 | [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] | 217 | [_GL_VERIFY_TRUE (R)] |
| 210 | #endif | 218 | #endif |
| 211 | 219 | ||
| 212 | /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ | 220 | /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ |
| 213 | #ifdef _GL_STATIC_ASSERT_H | 221 | #ifdef _GL_STATIC_ASSERT_H |
| 214 | # if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert | 222 | # if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert |
| 215 | # define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) | 223 | # define _Static_assert(...) \ |
| 224 | _GL_VERIFY (__VA_ARGS__, "static assertion failed", -) | ||
| 216 | # endif | 225 | # endif |
| 217 | # if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert | 226 | # if !defined _GL_HAVE_STATIC_ASSERT1 && !defined static_assert |
| 218 | # define static_assert _Static_assert /* C11 requires this #define. */ | 227 | # define static_assert _Static_assert /* C11 requires this #define. */ |
| 219 | # endif | 228 | # endif |
| 220 | #endif | 229 | #endif |
| @@ -226,31 +235,24 @@ template <int w> | |||
| 226 | assert (R), there is no run-time overhead. | 235 | assert (R), there is no run-time overhead. |
| 227 | 236 | ||
| 228 | There are two macros, since no single macro can be used in all | 237 | There are two macros, since no single macro can be used in all |
| 229 | contexts in C. verify_true (R) is for scalar contexts, including | 238 | contexts in C. verify_expr (R, E) is for scalar contexts, including |
| 230 | integer constant expression contexts. verify (R) is for declaration | 239 | integer constant expression contexts. verify (R) is for declaration |
| 231 | contexts, e.g., the top level. */ | 240 | contexts, e.g., the top level. */ |
| 232 | 241 | ||
| 233 | /* Verify requirement R at compile-time, as an integer constant expression. | ||
| 234 | Return 1. This is equivalent to verify_expr (R, 1). | ||
| 235 | |||
| 236 | verify_true is obsolescent; please use verify_expr instead. */ | ||
| 237 | |||
| 238 | #define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")") | ||
| 239 | |||
| 240 | /* Verify requirement R at compile-time. Return the value of the | 242 | /* Verify requirement R at compile-time. Return the value of the |
| 241 | expression E. */ | 243 | expression E. */ |
| 242 | 244 | ||
| 243 | #define verify_expr(R, E) \ | 245 | #define verify_expr(R, E) (_GL_VERIFY_TRUE (R) ? (E) : (E)) |
| 244 | (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) | ||
| 245 | 246 | ||
| 246 | /* Verify requirement R at compile-time, as a declaration without a | 247 | /* Verify requirement R at compile-time, as a declaration without a |
| 247 | trailing ';'. */ | 248 | trailing ';'. verify (R) acts like static_assert (R) except that |
| 249 | it is portable to C11/C++14 and earlier, and its name is shorter | ||
| 250 | and may be more convenient. */ | ||
| 248 | 251 | ||
| 249 | #ifdef __GNUC__ | 252 | #ifdef _GL_HAVE__STATIC_ASSERT1 |
| 250 | # define verify(R) _GL_VERIFY (R, "verify (" #R ")") | 253 | # define verify(R) _Static_assert (R) |
| 251 | #else | 254 | #else |
| 252 | /* PGI barfs if R is long. Play it safe. */ | 255 | # define verify(R) _GL_VERIFY (R, "verify (...)", -) |
| 253 | # define verify(R) _GL_VERIFY (R, "verify (...)") | ||
| 254 | #endif | 256 | #endif |
| 255 | 257 | ||
| 256 | #ifndef __has_builtin | 258 | #ifndef __has_builtin |