aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndrea Corallo2020-08-29 11:33:37 +0200
committerAndrea Corallo2020-08-29 11:33:37 +0200
commitc3514a6274cd6c6ddf2c133ccc708b7875aab90e (patch)
tree5f76eefdfef645bca9bc8640accb77c53704116a /lib
parentaa526c9470d679e9144af55d9e56928a111d2ceb (diff)
parent7d5807277ff614a337c7e4530bb8d0e0188c189b (diff)
downloademacs-c3514a6274cd6c6ddf2c133ccc708b7875aab90e.tar.gz
emacs-c3514a6274cd6c6ddf2c133ccc708b7875aab90e.zip
Merge remote-tracking branch 'savannah/master' into HEAD
Diffstat (limited to 'lib')
-rw-r--r--lib/cdefs.h6
-rw-r--r--lib/diffseq.h128
-rw-r--r--lib/gnulib.mk.in16
-rw-r--r--lib/intprops.h15
-rw-r--r--lib/sig2str.c17
-rw-r--r--lib/sigdescr_np.c376
-rw-r--r--lib/string.in.h15
-rw-r--r--lib/verify.h45
8 files changed, 558 insertions, 60 deletions
diff --git a/lib/cdefs.h b/lib/cdefs.h
index b1870fd0a93..ff7c628a264 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -148,7 +148,11 @@
148# define __warnattr(msg) __attribute__((__warning__ (msg))) 148# define __warnattr(msg) __attribute__((__warning__ (msg)))
149# define __errordecl(name, msg) \ 149# define __errordecl(name, msg) \
150 extern void name (void) __attribute__((__error__ (msg))) 150 extern void name (void) __attribute__((__error__ (msg)))
151#elif __glibc_clang_has_attribute (__diagnose_if__) && 0 /* fails on Fedora 31 with Clang 9. */ 151#elif __glibc_clang_has_attribute (__diagnose_if__) && 0
152/* These definitions are not enabled, because they produce bogus warnings
153 in the glibc Fortify functions. These functions are written in a style
154 that works with GCC. In order to work with clang, these functions would
155 need to be modified. */
152# define __warndecl(name, msg) \ 156# define __warndecl(name, msg) \
153 extern void name (void) __attribute__((__diagnose_if__ (1, msg, "warning"))) 157 extern void name (void) __attribute__((__diagnose_if__ (1, msg, "warning")))
154# define __warnattr(msg) __attribute__((__diagnose_if__ (1, msg, "warning"))) 158# define __warnattr(msg) __attribute__((__diagnose_if__ (1, msg, "warning")))
diff --git a/lib/diffseq.h b/lib/diffseq.h
index c89363ac9ee..26e10bdd043 100644
--- a/lib/diffseq.h
+++ b/lib/diffseq.h
@@ -51,10 +51,14 @@
51 EXTRA_CONTEXT_FIELDS Declarations of fields for 'struct context'. 51 EXTRA_CONTEXT_FIELDS Declarations of fields for 'struct context'.
52 NOTE_DELETE(ctxt, xoff) Record the removal of the object xvec[xoff]. 52 NOTE_DELETE(ctxt, xoff) Record the removal of the object xvec[xoff].
53 NOTE_INSERT(ctxt, yoff) Record the insertion of the object yvec[yoff]. 53 NOTE_INSERT(ctxt, yoff) Record the insertion of the object yvec[yoff].
54 NOTE_ORDERED (Optional) A boolean expression saying that
55 NOTE_DELETE and NOTE_INSERT calls must be
56 issued in offset order.
54 EARLY_ABORT(ctxt) (Optional) A boolean expression that triggers an 57 EARLY_ABORT(ctxt) (Optional) A boolean expression that triggers an
55 early abort of the computation. 58 early abort of the computation.
56 USE_HEURISTIC (Optional) Define if you want to support the 59 USE_HEURISTIC (Optional) Define if you want to support the
57 heuristic for large vectors. 60 heuristic for large vectors.
61
58 It is also possible to use this file with abstract arrays. In this case, 62 It is also possible to use this file with abstract arrays. In this case,
59 xvec and yvec are not represented in memory. They only exist conceptually. 63 xvec and yvec are not represented in memory. They only exist conceptually.
60 In this case, the list of defines above is amended as follows: 64 In this case, the list of defines above is amended as follows:
@@ -63,6 +67,7 @@
63 XVECREF_YVECREF_EQUAL(ctxt, xoff, yoff) 67 XVECREF_YVECREF_EQUAL(ctxt, xoff, yoff)
64 A three-argument macro: References xvec[xoff] and 68 A three-argument macro: References xvec[xoff] and
65 yvec[yoff] and tests these elements for equality. 69 yvec[yoff] and tests these elements for equality.
70
66 Before including this file, you also need to include: 71 Before including this file, you also need to include:
67 #include <limits.h> 72 #include <limits.h>
68 #include <stdbool.h> 73 #include <stdbool.h>
@@ -78,6 +83,10 @@
78# define EARLY_ABORT(ctxt) false 83# define EARLY_ABORT(ctxt) false
79#endif 84#endif
80 85
86#ifndef NOTE_ORDERED
87# define NOTE_ORDERED false
88#endif
89
81/* Use this to suppress gcc's "...may be used before initialized" warnings. 90/* Use this to suppress gcc's "...may be used before initialized" warnings.
82 Beware: The Code argument must not contain commas. */ 91 Beware: The Code argument must not contain commas. */
83#ifndef IF_LINT 92#ifndef IF_LINT
@@ -88,15 +97,6 @@
88# endif 97# endif
89#endif 98#endif
90 99
91/* As above, but when Code must contain one comma. */
92#ifndef IF_LINT2
93# if defined GCC_LINT || defined lint
94# define IF_LINT2(Code1, Code2) Code1, Code2
95# else
96# define IF_LINT2(Code1, Code2) /* empty */
97# endif
98#endif
99
100/* 100/*
101 * Context of comparison operation. 101 * Context of comparison operation.
102 */ 102 */
@@ -468,49 +468,89 @@ compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim,
468 #define XREF_YREF_EQUAL(x,y) XVECREF_YVECREF_EQUAL (ctxt, x, y) 468 #define XREF_YREF_EQUAL(x,y) XVECREF_YVECREF_EQUAL (ctxt, x, y)
469#endif 469#endif
470 470
471 /* Slide down the bottom initial diagonal. */ 471 while (true)
472 while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xoff, yoff))
473 { 472 {
474 xoff++; 473 /* Slide down the bottom initial diagonal. */
475 yoff++; 474 while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xoff, yoff))
476 } 475 {
476 xoff++;
477 yoff++;
478 }
477 479
478 /* Slide up the top initial diagonal. */ 480 /* Slide up the top initial diagonal. */
479 while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xlim - 1, ylim - 1)) 481 while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xlim - 1, ylim - 1))
480 { 482 {
481 xlim--; 483 xlim--;
482 ylim--; 484 ylim--;
483 } 485 }
484 486
485 /* Handle simple cases. */ 487 /* Handle simple cases. */
486 if (xoff == xlim) 488 if (xoff == xlim)
487 while (yoff < ylim) 489 {
488 { 490 while (yoff < ylim)
489 NOTE_INSERT (ctxt, yoff); 491 {
490 if (EARLY_ABORT (ctxt)) 492 NOTE_INSERT (ctxt, yoff);
491 return true; 493 if (EARLY_ABORT (ctxt))
492 yoff++; 494 return true;
493 } 495 yoff++;
494 else if (yoff == ylim) 496 }
495 while (xoff < xlim) 497 break;
496 { 498 }
497 NOTE_DELETE (ctxt, xoff); 499 if (yoff == ylim)
498 if (EARLY_ABORT (ctxt)) 500 {
499 return true; 501 while (xoff < xlim)
500 xoff++; 502 {
501 } 503 NOTE_DELETE (ctxt, xoff);
502 else 504 if (EARLY_ABORT (ctxt))
503 { 505 return true;
504 struct partition part IF_LINT2 (= { .xmid = 0, .ymid = 0 }); 506 xoff++;
507 }
508 break;
509 }
510
511 struct partition part;
505 512
506 /* Find a point of correspondence in the middle of the vectors. */ 513 /* Find a point of correspondence in the middle of the vectors. */
507 diag (xoff, xlim, yoff, ylim, find_minimal, &part, ctxt); 514 diag (xoff, xlim, yoff, ylim, find_minimal, &part, ctxt);
508 515
509 /* Use the partitions to split this problem into subproblems. */ 516 /* Use the partitions to split this problem into subproblems. */
510 if (compareseq (xoff, part.xmid, yoff, part.ymid, part.lo_minimal, ctxt)) 517 OFFSET xoff1, xlim1, yoff1, ylim1, xoff2, xlim2, yoff2, ylim2;
511 return true; 518 bool find_minimal1, find_minimal2;
512 if (compareseq (part.xmid, xlim, part.ymid, ylim, part.hi_minimal, ctxt)) 519 if (!NOTE_ORDERED
513 return true; 520 && ((xlim + ylim) - (part.xmid + part.ymid)
521 < (part.xmid + part.ymid) - (xoff + yoff)))
522 {
523 /* The second problem is smaller and the caller doesn't
524 care about order, so do the second problem first to
525 lessen recursion. */
526 xoff1 = part.xmid; xlim1 = xlim;
527 yoff1 = part.ymid; ylim1 = ylim;
528 find_minimal1 = part.hi_minimal;
529
530 xoff2 = xoff; xlim2 = part.xmid;
531 yoff2 = yoff; ylim2 = part.ymid;
532 find_minimal2 = part.lo_minimal;
533 }
534 else
535 {
536 xoff1 = xoff; xlim1 = part.xmid;
537 yoff1 = yoff; ylim1 = part.ymid;
538 find_minimal1 = part.lo_minimal;
539
540 xoff2 = part.xmid; xlim2 = xlim;
541 yoff2 = part.ymid; ylim2 = ylim;
542 find_minimal2 = part.hi_minimal;
543 }
544
545 /* Recurse to do one subproblem. */
546 bool early = compareseq (xoff1, xlim1, yoff1, ylim1, find_minimal1, ctxt);
547 if (early)
548 return early;
549
550 /* Iterate to do the other subproblem. */
551 xoff = xoff2; xlim = xlim2;
552 yoff = yoff2; ylim = ylim2;
553 find_minimal = find_minimal2;
514 } 554 }
515 555
516 return false; 556 return false;
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 78b4542d80a..f564d501222 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -136,6 +136,7 @@
136# readlinkat \ 136# readlinkat \
137# regex \ 137# regex \
138# sig2str \ 138# sig2str \
139# sigdescr_np \
139# socklen \ 140# socklen \
140# stat-time \ 141# stat-time \
141# std-gnu11 \ 142# std-gnu11 \
@@ -426,6 +427,7 @@ GNULIB_SETENV = @GNULIB_SETENV@
426GNULIB_SETHOSTNAME = @GNULIB_SETHOSTNAME@ 427GNULIB_SETHOSTNAME = @GNULIB_SETHOSTNAME@
427GNULIB_SIGABBREV_NP = @GNULIB_SIGABBREV_NP@ 428GNULIB_SIGABBREV_NP = @GNULIB_SIGABBREV_NP@
428GNULIB_SIGACTION = @GNULIB_SIGACTION@ 429GNULIB_SIGACTION = @GNULIB_SIGACTION@
430GNULIB_SIGDESCR_NP = @GNULIB_SIGDESCR_NP@
429GNULIB_SIGNAL_H_SIGPIPE = @GNULIB_SIGNAL_H_SIGPIPE@ 431GNULIB_SIGNAL_H_SIGPIPE = @GNULIB_SIGNAL_H_SIGPIPE@
430GNULIB_SIGPROCMASK = @GNULIB_SIGPROCMASK@ 432GNULIB_SIGPROCMASK = @GNULIB_SIGPROCMASK@
431GNULIB_SLEEP = @GNULIB_SLEEP@ 433GNULIB_SLEEP = @GNULIB_SLEEP@
@@ -647,6 +649,7 @@ HAVE_SETHOSTNAME = @HAVE_SETHOSTNAME@
647HAVE_SETSTATE = @HAVE_SETSTATE@ 649HAVE_SETSTATE = @HAVE_SETSTATE@
648HAVE_SIGABBREV_NP = @HAVE_SIGABBREV_NP@ 650HAVE_SIGABBREV_NP = @HAVE_SIGABBREV_NP@
649HAVE_SIGACTION = @HAVE_SIGACTION@ 651HAVE_SIGACTION = @HAVE_SIGACTION@
652HAVE_SIGDESCR_NP = @HAVE_SIGDESCR_NP@
650HAVE_SIGHANDLER_T = @HAVE_SIGHANDLER_T@ 653HAVE_SIGHANDLER_T = @HAVE_SIGHANDLER_T@
651HAVE_SIGINFO_T = @HAVE_SIGINFO_T@ 654HAVE_SIGINFO_T = @HAVE_SIGINFO_T@
652HAVE_SIGNED_SIG_ATOMIC_T = @HAVE_SIGNED_SIG_ATOMIC_T@ 655HAVE_SIGNED_SIG_ATOMIC_T = @HAVE_SIGNED_SIG_ATOMIC_T@
@@ -2312,6 +2315,17 @@ EXTRA_libgnu_a_SOURCES += sig2str.c
2312endif 2315endif
2313## end gnulib module sig2str 2316## end gnulib module sig2str
2314 2317
2318## begin gnulib module sigdescr_np
2319ifeq (,$(OMIT_GNULIB_MODULE_sigdescr_np))
2320
2321
2322EXTRA_DIST += sigdescr_np.c
2323
2324EXTRA_libgnu_a_SOURCES += sigdescr_np.c
2325
2326endif
2327## end gnulib module sigdescr_np
2328
2315## begin gnulib module signal-h 2329## begin gnulib module signal-h
2316ifeq (,$(OMIT_GNULIB_MODULE_signal-h)) 2330ifeq (,$(OMIT_GNULIB_MODULE_signal-h))
2317 2331
@@ -2846,6 +2860,7 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
2846 -e 's/@''GNULIB_STRERROR''@/$(GNULIB_STRERROR)/g' \ 2860 -e 's/@''GNULIB_STRERROR''@/$(GNULIB_STRERROR)/g' \
2847 -e 's/@''GNULIB_STRERROR_R''@/$(GNULIB_STRERROR_R)/g' \ 2861 -e 's/@''GNULIB_STRERROR_R''@/$(GNULIB_STRERROR_R)/g' \
2848 -e 's/@''GNULIB_SIGABBREV_NP''@/$(GNULIB_SIGABBREV_NP)/g' \ 2862 -e 's/@''GNULIB_SIGABBREV_NP''@/$(GNULIB_SIGABBREV_NP)/g' \
2863 -e 's/@''GNULIB_SIGDESCR_NP''@/$(GNULIB_SIGDESCR_NP)/g' \
2849 -e 's/@''GNULIB_STRSIGNAL''@/$(GNULIB_STRSIGNAL)/g' \ 2864 -e 's/@''GNULIB_STRSIGNAL''@/$(GNULIB_STRSIGNAL)/g' \
2850 -e 's/@''GNULIB_STRVERSCMP''@/$(GNULIB_STRVERSCMP)/g' \ 2865 -e 's/@''GNULIB_STRVERSCMP''@/$(GNULIB_STRVERSCMP)/g' \
2851 < $(srcdir)/string.in.h | \ 2866 < $(srcdir)/string.in.h | \
@@ -2869,6 +2884,7 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
2869 -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ 2884 -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \
2870 -e 's|@''HAVE_DECL_STRERROR_R''@|$(HAVE_DECL_STRERROR_R)|g' \ 2885 -e 's|@''HAVE_DECL_STRERROR_R''@|$(HAVE_DECL_STRERROR_R)|g' \
2871 -e 's|@''HAVE_SIGABBREV_NP''@|$(HAVE_SIGABBREV_NP)|g' \ 2886 -e 's|@''HAVE_SIGABBREV_NP''@|$(HAVE_SIGABBREV_NP)|g' \
2887 -e 's|@''HAVE_SIGDESCR_NP''@|$(HAVE_SIGDESCR_NP)|g' \
2872 -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ 2888 -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \
2873 -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ 2889 -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \
2874 -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ 2890 -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \
diff --git a/lib/intprops.h b/lib/intprops.h
index f2f70b3e733..b27f2eea056 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -48,7 +48,7 @@
48/* Minimum and maximum values for integer types and expressions. */ 48/* Minimum and maximum values for integer types and expressions. */
49 49
50/* The width in bits of the integer type or expression T. 50/* The width in bits of the integer type or expression T.
51 Do not evaluate T. 51 Do not evaluate T. T must not be a bit-field expression.
52 Padding bits are not supported; this is checked at compile-time below. */ 52 Padding bits are not supported; this is checked at compile-time below. */
53#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT) 53#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
54 54
@@ -70,7 +70,7 @@
70 ? _GL_SIGNED_INT_MAXIMUM (e) \ 70 ? _GL_SIGNED_INT_MAXIMUM (e) \
71 : _GL_INT_NEGATE_CONVERT (e, 1)) 71 : _GL_INT_NEGATE_CONVERT (e, 1))
72#define _GL_SIGNED_INT_MAXIMUM(e) \ 72#define _GL_SIGNED_INT_MAXIMUM(e) \
73 (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1) 73 (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
74 74
75/* Work around OpenVMS incompatibility with C99. */ 75/* Work around OpenVMS incompatibility with C99. */
76#if !defined LLONG_MAX && defined __INT64_MAX 76#if !defined LLONG_MAX && defined __INT64_MAX
@@ -95,8 +95,9 @@
95#endif 95#endif
96 96
97/* Return 1 if the integer type or expression T might be signed. Return 0 97/* Return 1 if the integer type or expression T might be signed. Return 0
98 if it is definitely unsigned. This macro does not evaluate its argument, 98 if it is definitely unsigned. T must not be a bit-field expression.
99 and expands to an integer constant expression. */ 99 This macro does not evaluate its argument, and expands to an
100 integer constant expression. */
100#if _GL_HAVE___TYPEOF__ 101#if _GL_HAVE___TYPEOF__
101# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t)) 102# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t))
102#else 103#else
@@ -109,6 +110,8 @@
109#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485) 110#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
110 111
111/* Bound on length of the string representing an integer type or expression T. 112/* Bound on length of the string representing an integer type or expression T.
113 T must not be a bit-field expression.
114
112 Subtract 1 for the sign bit if T is signed, and then add 1 more for 115 Subtract 1 for the sign bit if T is signed, and then add 1 more for
113 a minus sign if needed. 116 a minus sign if needed.
114 117
@@ -120,7 +123,7 @@
120 + _GL_SIGNED_TYPE_OR_EXPR (t)) 123 + _GL_SIGNED_TYPE_OR_EXPR (t))
121 124
122/* Bound on buffer size needed to represent an integer type or expression T, 125/* Bound on buffer size needed to represent an integer type or expression T,
123 including the terminating null. */ 126 including the terminating null. T must not be a bit-field expression. */
124#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) 127#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
125 128
126 129
@@ -566,7 +569,7 @@
566 ? (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \ 569 ? (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \
567 ? (a) < (tmax) / (b) \ 570 ? (a) < (tmax) / (b) \
568 : ((INT_NEGATE_OVERFLOW (b) \ 571 : ((INT_NEGATE_OVERFLOW (b) \
569 ? _GL_INT_CONVERT (b, tmax) >> (TYPE_WIDTH (b) - 1) \ 572 ? _GL_INT_CONVERT (b, tmax) >> (TYPE_WIDTH (+ (b)) - 1) \
570 : (tmax) / -(b)) \ 573 : (tmax) / -(b)) \
571 <= -1 - (a))) \ 574 <= -1 - (a))) \
572 : INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (b, tmin)) && (b) == -1 \ 575 : INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (b, tmin)) && (b) == -1 \
diff --git a/lib/sig2str.c b/lib/sig2str.c
index 905daea2f20..cf7c3bb5c38 100644
--- a/lib/sig2str.c
+++ b/lib/sig2str.c
@@ -189,6 +189,11 @@ static struct numname { int num; char const name[8]; } numname_table[] =
189 NUMNAME (STKFLT), 189 NUMNAME (STKFLT),
190#endif 190#endif
191 191
192 /* AIX 7. */
193#ifdef SIGCPUFAIL
194 NUMNAME (CPUFAIL),
195#endif
196
192 /* AIX 5L. */ 197 /* AIX 5L. */
193#ifdef SIGDANGER 198#ifdef SIGDANGER
194 NUMNAME (DANGER), 199 NUMNAME (DANGER),
@@ -229,7 +234,12 @@ static struct numname { int num; char const name[8]; } numname_table[] =
229 NUMNAME (WINDOW), /* Older name for SIGWINCH. */ 234 NUMNAME (WINDOW), /* Older name for SIGWINCH. */
230#endif 235#endif
231 236
232 /* BeOS */ 237 /* OpenBSD. */
238#ifdef SIGTHR
239 NUMNAME (THR),
240#endif
241
242 /* BeOS, Haiku */
233#ifdef SIGKILLTHR 243#ifdef SIGKILLTHR
234 NUMNAME (KILLTHR), 244 NUMNAME (KILLTHR),
235#endif 245#endif
@@ -239,6 +249,11 @@ static struct numname { int num; char const name[8]; } numname_table[] =
239 NUMNAME (DIL), 249 NUMNAME (DIL),
240#endif 250#endif
241 251
252 /* native Windows */
253#ifdef SIGBREAK
254 NUMNAME (BREAK),
255#endif
256
242 /* Korn shell and Bash, of uncertain vintage. */ 257 /* Korn shell and Bash, of uncertain vintage. */
243 { 0, "EXIT" } 258 { 0, "EXIT" }
244 }; 259 };
diff --git a/lib/sigdescr_np.c b/lib/sigdescr_np.c
new file mode 100644
index 00000000000..fc9cd3c2369
--- /dev/null
+++ b/lib/sigdescr_np.c
@@ -0,0 +1,376 @@
1/* English descriptions of signals.
2 Copyright (C) 2020 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2020. */
18
19#include <config.h>
20
21/* Specification. */
22#include <string.h>
23
24#include <signal.h>
25
26const char *
27sigdescr_np (int sig)
28{
29 /* Note: Some platforms (glibc, FreeBSD, NetBSD, OpenBSD, AIX, IRIX, Haiku,
30 Android) have an array 'sys_siglist'. (On AIX, you need to declare it
31 yourself, and it has fewer than NSIG elements.) Its contents varies
32 depending on the OS.
33 On other OSes, you can invoke strsignal (sig) in the C locale.
34 In the code below, we show the differences.
35 You can see how cryptic some of these strings are. We try to pick more
36 understandable wordings. */
37
38 switch (sig)
39 {
40 /* Signals specified by ISO C. */
41 case SIGABRT:
42 /* glibc: "Aborted". *BSD: "Abort trap". Solaris: "Abort". */
43 return "Aborted";
44 case SIGFPE:
45 /* glibc, *BSD: "Floating point exception". Solaris: "Arithmetic exception".
46 The latter is more correct, because of integer division by 0 or -1. */
47 return "Arithmetic exception";
48 case SIGILL:
49 return "Illegal instruction";
50 case SIGINT:
51 return "Interrupt";
52 case SIGSEGV:
53 return "Segmentation fault";
54 case SIGTERM:
55 return "Terminated";
56
57 /* Signals specified by POSIX.
58 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html> */
59 #if defined SIGALRM
60 case SIGALRM:
61 return "Alarm clock";
62 #endif
63 #if defined SIGBUS
64 case SIGBUS:
65 return "Bus error";
66 #endif
67 #if defined SIGCHLD
68 case SIGCHLD:
69 /* glibc, *BSD: "Child exited". Solaris: "Child status changed". */
70 return "Child stopped or exited";
71 #endif
72 #if defined SIGCONT
73 case SIGCONT:
74 return "Continued";
75 #endif
76 #if defined SIGHUP
77 case SIGHUP:
78 return "Hangup";
79 #endif
80 #if defined SIGKILL
81 case SIGKILL:
82 return "Killed";
83 #endif
84 #if defined SIGPIPE
85 case SIGPIPE:
86 return "Broken pipe";
87 #endif
88 #if defined SIGQUIT
89 case SIGQUIT:
90 return "Quit";
91 #endif
92 #if defined SIGSTOP
93 case SIGSTOP:
94 /* glibc, Solaris: "Stopped (signal)". *BSD: "Suspended (signal)". */
95 return "Stopped (signal)";
96 #endif
97 #if defined SIGTSTP
98 case SIGTSTP:
99 /* glibc: "Stopped". *BSD: "Suspended". Solaris: "Stopped (user)". */
100 return "Stopped";
101 #endif
102 #if defined SIGTTIN
103 case SIGTTIN:
104 return "Stopped (tty input)";
105 #endif
106 #if defined SIGTTOU
107 case SIGTTOU:
108 return "Stopped (tty output)";
109 #endif
110 #if defined SIGUSR1
111 case SIGUSR1:
112 /* glibc, *BSD: "User defined signal 1". Solaris: "User signal 1". */
113 return "User defined signal 1";
114 #endif
115 #if defined SIGUSR2
116 case SIGUSR2:
117 /* glibc, *BSD: "User defined signal 2". Solaris: "User signal 2". */
118 return "User defined signal 2";
119 #endif
120 #if defined SIGPOLL
121 case SIGPOLL:
122 /* glibc: "I/O possible". Solaris: "Pollable event". */
123 return "I/O possible";
124 #endif
125 #if defined SIGPROF
126 case SIGPROF:
127 return "Profiling timer expired";
128 #endif
129 #if defined SIGSYS
130 case SIGSYS:
131 return "Bad system call";
132 #endif
133 #if defined SIGTRAP
134 case SIGTRAP:
135 /* glibc, Solaris: "Trace/breakpoint trap". *BSD: "Trace/BPT trap". */
136 return "Trace/breakpoint trap";
137 #endif
138 #if defined SIGURG
139 case SIGURG:
140 /* glibc, *BSD: "Urgent I/O condition". Solaris: "Urgent socket condition". */
141 return "Urgent I/O condition";
142 #endif
143 #if defined SIGVTALRM
144 case SIGVTALRM:
145 return "Virtual timer expired";
146 #endif
147 #if defined SIGXCPU
148 case SIGXCPU:
149 /* glibc, *BSD: "CPU time limit exceeded". Solaris: "Cpu limit exceeded". */
150 return "CPU time limit exceeded";
151 #endif
152 #if defined SIGXFSZ
153 case SIGXFSZ:
154 return "File size limit exceeded";
155 #endif
156
157 /* Other signals on other systems. */
158 /* native Windows */
159 #if defined SIGBREAK
160 case SIGBREAK:
161 return "Ctrl-Break";
162 #endif
163 /* IRIX */
164 #if defined SIGCKPT
165 case SIGCKPT:
166 return "Checkpoint"; /* See man 1 cpr, man 3C atcheckpoint */
167 #endif
168 /* Linux, IRIX, Cygwin */
169 #if defined SIGCLD && SIGCLD != SIGCHLD
170 case SIGCLD:
171 return "Child stopped or exited";
172 #endif
173 /* AIX */
174 #if defined SIGCPUFAIL
175 case SIGCPUFAIL:
176 /* AIX: "CPU failure predicted". */
177 return "CPU going down"; /* See man bindprocessor */
178 #endif
179 /* AIX */
180 #if defined SIGDANGER
181 case SIGDANGER:
182 /* AIX: "Paging space low". */
183 return "Swap space nearly exhausted";
184 #endif
185 /* Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Cygwin, mingw */
186 #if defined SIGEMT
187 case SIGEMT:
188 /* glibc/Hurd, *BSD: "EMT trap". Solaris: "Emulation trap". */
189 return "Instruction emulation needed";
190 #endif
191 /* Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix */
192 #if defined SIGINFO
193 case SIGINFO:
194 return "Information request";
195 #endif
196 /* Linux, Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Cygwin */
197 #if defined SIGIO && SIGIO != SIGPOLL
198 case SIGIO:
199 return "I/O possible";
200 #endif
201 /* Linux, IRIX, Cygwin, mingw */
202 #if defined SIGIOT && SIGIOT != SIGABRT
203 case SIGIOT:
204 return "IOT instruction"; /* a PDP-11 instruction */
205 #endif
206 /* AIX */
207 #if defined SIGKAP
208 case SIGKAP:
209 /* Process must issue a KSKAPACK ioctl, or will be killed in 30 seconds. */
210 /* AIX: "Monitor mode granted". */
211 return "Keep Alive Poll";
212 #endif
213 /* Haiku */
214 #if defined SIGKILLTHR
215 case SIGKILLTHR:
216 return "Kill thread";
217 #endif
218 /* Minix */
219 #if defined SIGKMEM
220 case SIGKMEM:
221 return "Kernel memory request";
222 #endif
223 /* Minix */
224 #if defined SIGKMESS
225 case SIGKMESS:
226 return "Kernel message";
227 #endif
228 /* Minix */
229 #if defined SIGKSIG
230 case SIGKSIG:
231 return "Kernel signal";
232 #endif
233 /* Minix */
234 #if defined SIGKSIGSM
235 case SIGKSIGSM:
236 return "Kernel signal for signal manager";
237 #endif
238 /* FreeBSD */
239 #if defined SIGLIBRT
240 case SIGLIBRT:
241 return "Real-time library interrupt";
242 #endif
243 /* Cygwin */
244 #if defined SIGLOST && SIGLOST != SIGABRT && SIGLOST != SIGPWR
245 case SIGLOST:
246 /* Solaris: "Resource lost". */
247 return "File lock lost";
248 #endif
249 /* AIX */
250 #if defined SIGMIGRATE
251 case SIGMIGRATE:
252 return "Process migration";
253 #endif
254 /* AIX */
255 #if defined SIGMSG
256 case SIGMSG:
257 /* AIX: "Input device data". */
258 return "Message in the ring";
259 #endif
260 /* ACM */
261 #if defined SIGPLAN
262 case SIGPLAN:
263 return "Programming language anomaly";
264 #endif
265 /* AIX */
266 #if defined SIGPRE
267 case SIGPRE:
268 return "Programmed exception";
269 #endif
270 /* IRIX */
271 #if defined SIGPTINTR
272 case SIGPTINTR:
273 return "Pthread interrupt";
274 #endif
275 /* IRIX */
276 #if defined SIGPTRESCHED
277 case SIGPTRESCHED:
278 return "Pthread rescheduling";
279 #endif
280 /* Linux, NetBSD, Minix, AIX, IRIX, Cygwin */
281 #if defined SIGPWR
282 case SIGPWR:
283 /* glibc: "Power failure". NetBSD: "Power fail/restart". */
284 return "Power failure";
285 #endif
286 /* AIX */
287 #if defined SIGRECONFIG
288 case SIGRECONFIG:
289 return "Dynamic logical partitioning changed";
290 #endif
291 /* AIX */
292 #if defined SIGRECOVERY
293 case SIGRECOVERY:
294 return "Kernel recovery";
295 #endif
296 /* IRIX */
297 #if defined SIGRESTART
298 case SIGRESTART:
299 return "Checkpoint restart"; /* See man 1 cpr, man 3C atrestart */
300 #endif
301 /* AIX */
302 #if defined SIGRETRACT
303 case SIGRETRACT:
304 /* AIX: "Monitor mode retracted". */
305 return "Retracting Keep Alive Poll";
306 #endif
307 /* AIX */
308 #if defined SIGSAK
309 case SIGSAK:
310 /* AIX: "Secure attention". */
311 return "Secure Attention Key";
312 #endif
313 /* ACM */
314 #if defined SIGSAM
315 case SIGSAM:
316 return "Symbolic computation failed";
317 #endif
318 /* Minix */
319 #if defined SIGSNDELAY
320 case SIGSNDELAY:
321 return "Done sending message";
322 #endif
323 /* AIX */
324 #if defined SIGSOUND
325 case SIGSOUND:
326 /* AIX: "Sound completed". */
327 return "Sound configuration changed";
328 #endif
329 /* Linux */
330 #if defined SIGSTKFLT
331 case SIGSTKFLT:
332 return "Stack fault";
333 #endif
334 /* AIX */
335 #if defined SIGSYSERROR
336 case SIGSYSERROR:
337 return "Kernel error";
338 #endif
339 /* AIX */
340 #if defined SIGTALRM
341 case SIGTALRM:
342 return "Thread alarm clock";
343 #endif
344 /* FreeBSD, OpenBSD */
345 #if defined SIGTHR
346 case SIGTHR:
347 /* OpenBSD: "Thread AST". */
348 return "Thread library interrupt";
349 #endif
350 /* IRIX */
351 #if defined SIGUME
352 case SIGUME:
353 return "Uncorrectable memory error";
354 #endif
355 /* AIX */
356 #if defined SIGVIRT
357 case SIGVIRT:
358 return "Virtual time alarm clock";
359 #endif
360 /* AIX */
361 #if defined SIGWAITING
362 case SIGWAITING:
363 /* AIX: "No runnable lwp". */
364 return "Thread waiting";
365 #endif
366 /* Linux, Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Cygwin, Haiku */
367 #if defined SIGWINCH
368 case SIGWINCH:
369 /* glibc: "Window changed". *BSD: "Window size changed" or "Window size changes". */
370 return "Window size changed";
371 #endif
372
373 default:
374 return NULL;
375 }
376}
diff --git a/lib/string.in.h b/lib/string.in.h
index 5134e11289d..776133c5eba 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -1060,6 +1060,21 @@ _GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - "
1060# endif 1060# endif
1061#endif 1061#endif
1062 1062
1063/* Return an English description string for the signal number SIG. */
1064#if @GNULIB_SIGDESCR_NP@
1065# if ! @HAVE_SIGDESCR_NP@
1066_GL_FUNCDECL_SYS (sigdescr_np, const char *, (int sig));
1067# endif
1068_GL_CXXALIAS_SYS (sigdescr_np, const char *, (int sig));
1069_GL_CXXALIASWARN (sigdescr_np);
1070#elif defined GNULIB_POSIXCHECK
1071# undef sigdescr_np
1072# if HAVE_RAW_DECL_SIGDESCR_NP
1073_GL_WARN_ON_USE (sigdescr_np, "sigdescr_np is unportable - "
1074 "use gnulib module sigdescr_np for portability");
1075# endif
1076#endif
1077
1063#if @GNULIB_STRSIGNAL@ 1078#if @GNULIB_STRSIGNAL@
1064# if @REPLACE_STRSIGNAL@ 1079# if @REPLACE_STRSIGNAL@
1065# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1080# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
diff --git a/lib/verify.h b/lib/verify.h
index d485a0283a9..ca2a1540736 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -246,6 +246,13 @@ template <int w>
246 246
247/* @assert.h omit start@ */ 247/* @assert.h omit start@ */
248 248
249#if defined __has_builtin
250/* <https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions> */
251# define _GL_HAS_BUILTIN_ASSUME __has_builtin (__builtin_assume)
252#else
253# define _GL_HAS_BUILTIN_ASSUME 0
254#endif
255
249#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)) 256#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
250# define _GL_HAS_BUILTIN_TRAP 1 257# define _GL_HAS_BUILTIN_TRAP 1
251#elif defined __has_builtin 258#elif defined __has_builtin
@@ -305,14 +312,36 @@ template <int w>
305 312
306 Although assuming R can help a compiler generate better code or 313 Although assuming R can help a compiler generate better code or
307 diagnostics, performance can suffer if R uses hard-to-optimize 314 diagnostics, performance can suffer if R uses hard-to-optimize
308 features such as function calls not inlined by the compiler. 315 features such as function calls not inlined by the compiler. */
309 316
310 Avoid Clang’s __builtin_assume, as clang 9.0.1 -Wassume can 317/* Use __builtin_assume in preference to __builtin_unreachable, because
311 generate a bogus diagnostic "the argument to '__builtin_assume' has 318 in clang versions 8.0.x and older, the definition based on
312 side effects that will be discarded" even when the argument has no 319 __builtin_assume has an effect on optimizations, whereas the definition
313 side effects. */ 320 based on __builtin_unreachable does not. (GCC so far has only
314 321 __builtin_unreachable.) */
315#if _GL_HAS_BUILTIN_UNREACHABLE 322#if _GL_HAS_BUILTIN_ASSUME
323/* Use __builtin_constant_p to help clang's data-flow analysis for the case
324 assume (0).
325 Use a temporary variable, to avoid a clang warning
326 "the argument to '__builtin_assume' has side effects that will be discarded"
327 if R contains invocations of functions not marked as 'const'.
328 The type of the temporary variable can't be __typeof__ (R), because that
329 does not work on bit field expressions. Use '_Bool' or 'bool' as type
330 instead. */
331# if defined __cplusplus
332# define assume(R) \
333 (__builtin_constant_p (R) && !(R) \
334 ? (void) __builtin_unreachable () \
335 : (void) ({ bool _gl_verify_temp = (R); \
336 __builtin_assume (_gl_verify_temp); }))
337# else
338# define assume(R) \
339 (__builtin_constant_p (R) && !(R) \
340 ? (void) __builtin_unreachable () \
341 : (void) ({ _Bool _gl_verify_temp = (R); \
342 __builtin_assume (_gl_verify_temp); }))
343# endif
344#elif _GL_HAS_BUILTIN_UNREACHABLE
316# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) 345# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
317#elif 1200 <= _MSC_VER 346#elif 1200 <= _MSC_VER
318# define assume(R) __assume (R) 347# define assume(R) __assume (R)