diff options
| author | Paul Eggert | 2013-10-03 00:06:52 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-10-03 00:06:52 -0700 |
| commit | 0a858ebfc57a072ae8ab65f509d8a4901a2ec073 (patch) | |
| tree | dd81bcdf11f3d3efa32ffe00f7cdc90d3c1144d9 /lib | |
| parent | b52f569dcfc5c2e1b764c89d27ea8699a44228e6 (diff) | |
| download | emacs-0a858ebfc57a072ae8ab65f509d8a4901a2ec073.tar.gz emacs-0a858ebfc57a072ae8ab65f509d8a4901a2ec073.zip | |
Merge from gnulib.
* src/conf_post.h (__has_builtin, assume): Remove; gnulib now does these.
* src/lisp.h: Include <verify.h>, for 'assume'.
This also incorpoprates:
2013-10-02 verify: new macro 'assume'
2013-09-26 dup2, dup3: work around another cygwin crasher
2013-09-26 getdtablesize: work around cygwin issue
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dup2.c | 4 | ||||
| -rw-r--r-- | lib/getdtablesize.c | 33 | ||||
| -rw-r--r-- | lib/gnulib.mk | 1 | ||||
| -rw-r--r-- | lib/unistd.in.h | 13 | ||||
| -rw-r--r-- | lib/verify.h | 24 |
5 files changed, 67 insertions, 8 deletions
diff --git a/lib/dup2.c b/lib/dup2.c index 9219eb38238..f128e7a63cd 100644 --- a/lib/dup2.c +++ b/lib/dup2.c | |||
| @@ -96,7 +96,11 @@ rpl_dup2 (int fd, int desired_fd) | |||
| 96 | /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF. | 96 | /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF. |
| 97 | On Cygwin 1.5.x, dup2 (1, 1) returns 0. | 97 | On Cygwin 1.5.x, dup2 (1, 1) returns 0. |
| 98 | On Cygwin 1.7.17, dup2 (1, -1) dumps core. | 98 | On Cygwin 1.7.17, dup2 (1, -1) dumps core. |
| 99 | On Cygwin 1.7.25, dup2 (1, 256) can dump core. | ||
| 99 | On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */ | 100 | On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */ |
| 101 | # if HAVE_SETDTABLESIZE | ||
| 102 | setdtablesize (desired_fd + 1); | ||
| 103 | # endif | ||
| 100 | if (desired_fd < 0) | 104 | if (desired_fd < 0) |
| 101 | fd = desired_fd; | 105 | fd = desired_fd; |
| 102 | if (fd == desired_fd) | 106 | if (fd == desired_fd) |
diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c index 9947405af61..355c17e3b9e 100644 --- a/lib/getdtablesize.c +++ b/lib/getdtablesize.c | |||
| @@ -22,11 +22,11 @@ | |||
| 22 | 22 | ||
| 23 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | 23 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
| 24 | 24 | ||
| 25 | #include <stdio.h> | 25 | # include <stdio.h> |
| 26 | 26 | ||
| 27 | #include "msvc-inval.h" | 27 | # include "msvc-inval.h" |
| 28 | 28 | ||
| 29 | #if HAVE_MSVC_INVALID_PARAMETER_HANDLER | 29 | # if HAVE_MSVC_INVALID_PARAMETER_HANDLER |
| 30 | static int | 30 | static int |
| 31 | _setmaxstdio_nothrow (int newmax) | 31 | _setmaxstdio_nothrow (int newmax) |
| 32 | { | 32 | { |
| @@ -44,10 +44,11 @@ _setmaxstdio_nothrow (int newmax) | |||
| 44 | 44 | ||
| 45 | return result; | 45 | return result; |
| 46 | } | 46 | } |
| 47 | # define _setmaxstdio _setmaxstdio_nothrow | 47 | # define _setmaxstdio _setmaxstdio_nothrow |
| 48 | #endif | 48 | # endif |
| 49 | 49 | ||
| 50 | /* Cache for the previous getdtablesize () result. */ | 50 | /* Cache for the previous getdtablesize () result. Safe to cache because |
| 51 | Windows also lacks setrlimit. */ | ||
| 51 | static int dtablesize; | 52 | static int dtablesize; |
| 52 | 53 | ||
| 53 | int | 54 | int |
| @@ -83,4 +84,24 @@ getdtablesize (void) | |||
| 83 | return dtablesize; | 84 | return dtablesize; |
| 84 | } | 85 | } |
| 85 | 86 | ||
| 87 | #elif HAVE_GETDTABLESIZE | ||
| 88 | |||
| 89 | # include <sys/resource.h> | ||
| 90 | # undef getdtablesize | ||
| 91 | |||
| 92 | int | ||
| 93 | rpl_getdtablesize(void) | ||
| 94 | { | ||
| 95 | /* To date, this replacement is only compiled for Cygwin 1.7.25, | ||
| 96 | which auto-increased the RLIMIT_NOFILE soft limit until it | ||
| 97 | hits the compile-time constant hard limit of 3200. Although | ||
| 98 | that version of cygwin supported a child process inheriting | ||
| 99 | a smaller soft limit, the smaller limit is not enforced, so | ||
| 100 | we might as well just report the hard limit. */ | ||
| 101 | struct rlimit lim; | ||
| 102 | if (!getrlimit (RLIMIT_NOFILE, &lim) && lim.rlim_max != RLIM_INFINITY) | ||
| 103 | return lim.rlim_max; | ||
| 104 | return getdtablesize (); | ||
| 105 | } | ||
| 106 | |||
| 86 | #endif | 107 | #endif |
diff --git a/lib/gnulib.mk b/lib/gnulib.mk index 32255181fb4..14d45e798e5 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk | |||
| @@ -1707,6 +1707,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H | |||
| 1707 | -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \ | 1707 | -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \ |
| 1708 | -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ | 1708 | -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ |
| 1709 | -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \ | 1709 | -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \ |
| 1710 | -e 's|@''REPLACE_GETDTABLESIZE''@|$(REPLACE_GETDTABLESIZE)|g' \ | ||
| 1710 | -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \ | 1711 | -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \ |
| 1711 | -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ | 1712 | -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ |
| 1712 | -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ | 1713 | -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ |
diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 874c628a63b..0e510d679c6 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h | |||
| @@ -654,10 +654,19 @@ _GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - " | |||
| 654 | #if @GNULIB_GETDTABLESIZE@ | 654 | #if @GNULIB_GETDTABLESIZE@ |
| 655 | /* Return the maximum number of file descriptors in the current process. | 655 | /* Return the maximum number of file descriptors in the current process. |
| 656 | In POSIX, this is same as sysconf (_SC_OPEN_MAX). */ | 656 | In POSIX, this is same as sysconf (_SC_OPEN_MAX). */ |
| 657 | # if !@HAVE_GETDTABLESIZE@ | 657 | # if @REPLACE_GETDTABLESIZE@ |
| 658 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 659 | # undef getdtablesize | ||
| 660 | # define getdtablesize rpl_getdtablesize | ||
| 661 | # endif | ||
| 662 | _GL_FUNCDECL_RPL (getdtablesize, int, (void)); | ||
| 663 | _GL_CXXALIAS_RPL (getdtablesize, int, (void)); | ||
| 664 | # else | ||
| 665 | # if !@HAVE_GETDTABLESIZE@ | ||
| 658 | _GL_FUNCDECL_SYS (getdtablesize, int, (void)); | 666 | _GL_FUNCDECL_SYS (getdtablesize, int, (void)); |
| 659 | # endif | 667 | # endif |
| 660 | _GL_CXXALIAS_SYS (getdtablesize, int, (void)); | 668 | _GL_CXXALIAS_SYS (getdtablesize, int, (void)); |
| 669 | # endif | ||
| 661 | _GL_CXXALIASWARN (getdtablesize); | 670 | _GL_CXXALIASWARN (getdtablesize); |
| 662 | #elif defined GNULIB_POSIXCHECK | 671 | #elif defined GNULIB_POSIXCHECK |
| 663 | # undef getdtablesize | 672 | # undef getdtablesize |
diff --git a/lib/verify.h b/lib/verify.h index d42d0750ee1..bf40b028c92 100644 --- a/lib/verify.h +++ b/lib/verify.h | |||
| @@ -250,6 +250,30 @@ template <int w> | |||
| 250 | 250 | ||
| 251 | #define verify(R) _GL_VERIFY (R, "verify (" #R ")") | 251 | #define verify(R) _GL_VERIFY (R, "verify (" #R ")") |
| 252 | 252 | ||
| 253 | #ifndef __has_builtin | ||
| 254 | # define __has_builtin(x) 0 | ||
| 255 | #endif | ||
| 256 | |||
| 257 | /* Assume that R always holds. This lets the compiler optimize | ||
| 258 | accordingly. R should not have side-effects; it may or may not be | ||
| 259 | evaluated. Behavior is undefined if R is false. */ | ||
| 260 | |||
| 261 | #if (__has_builtin (__builtin_unreachable) \ | ||
| 262 | || 4 < __GNUC__ + (5 <= __GNUC_MINOR__)) | ||
| 263 | # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) | ||
| 264 | #elif 1200 <= _MSC_VER | ||
| 265 | # define assume(R) __assume (R) | ||
| 266 | #elif (defined lint \ | ||
| 267 | && (__has_builtin (__builtin_trap) \ | ||
| 268 | || 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)))) | ||
| 269 | /* Doing it this way helps various packages when configured with | ||
| 270 | --enable-gcc-warnings, which compiles with -Dlint. It's nicer | ||
| 271 | when 'assume' silences warnings even with older GCCs. */ | ||
| 272 | # define assume(R) ((R) ? (void) 0 : __builtin_trap ()) | ||
| 273 | #else | ||
| 274 | # define assume(R) ((void) (0 && (R))) | ||
| 275 | #endif | ||
| 276 | |||
| 253 | /* @assert.h omit end@ */ | 277 | /* @assert.h omit end@ */ |
| 254 | 278 | ||
| 255 | #endif | 279 | #endif |