summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2024-05-18 09:33:03 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2024-05-18 10:23:50 -0700
commit08550d058f028e0819ba6a72e9a53c0bc789257e (patch)
treeb8968c3ec0179e4ce1d57a55f90bf2dfc08bb121 /lib
parentc9af2fab9221d3793e0b9cd4dd376f9f16099a26 (diff)
downloademacs-08550d058f028e0819ba6a72e9a53c0bc789257e.tar.gz
emacs-08550d058f028e0819ba6a72e9a53c0bc789257e.tar.bz2
emacs-08550d058f028e0819ba6a72e9a53c0bc789257e.zip
Update from Gnulib by running admin/merge-gnulib
Diffstat (limited to 'lib')
-rw-r--r--lib/byteswap.c21
-rw-r--r--lib/byteswap.in.h101
-rw-r--r--lib/count-leading-zeros.h2
-rw-r--r--lib/count-one-bits.h3
-rw-r--r--lib/count-trailing-zeros.h2
-rw-r--r--lib/gnulib.mk.in5
-rw-r--r--lib/stdlib.in.h17
-rw-r--r--lib/strftime.c10
-rw-r--r--lib/sys_select.in.h2
-rw-r--r--lib/unistd.in.h12
10 files changed, 145 insertions, 30 deletions
diff --git a/lib/byteswap.c b/lib/byteswap.c
new file mode 100644
index 00000000000..6e3dad74eaa
--- /dev/null
+++ b/lib/byteswap.c
@@ -0,0 +1,21 @@
+/* Inline functions for <byteswap.h>.
+
+ Copyright 2024 Free Software Foundation, Inc.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ This file is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#define _GL_BYTESWAP_INLINE _GL_EXTERN_INLINE
+#include <byteswap.h>
diff --git a/lib/byteswap.in.h b/lib/byteswap.in.h
index 8e49efad05a..4be335d9158 100644
--- a/lib/byteswap.in.h
+++ b/lib/byteswap.in.h
@@ -16,29 +16,100 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#ifndef _GL_BYTESWAP_H
-#define _GL_BYTESWAP_H
+#define _GL_BYTESWAP_H 1
+
+/* This file uses _GL_INLINE. */
+#if !_GL_CONFIG_H_INCLUDED
+ #error "Please include config.h first."
+#endif
+
+#include <stdint.h>
+
+_GL_INLINE_HEADER_BEGIN
+#ifndef _GL_BYTESWAP_INLINE
+# define _GL_BYTESWAP_INLINE _GL_INLINE
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
+# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP16 true
+#elif defined __has_builtin
+# if __has_builtin (__builtin_bswap16)
+# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP16 true
+# endif
+#endif
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP32 true
+# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP64 true
+#elif defined __has_builtin
+# if __has_builtin (__builtin_bswap32)
+# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP32 true
+# endif
+# if __has_builtin (__builtin_bswap64)
+# define _GL_BYTESWAP_HAS_BUILTIN_BSWAP64 true
+# endif
+#endif
/* Given an unsigned 16-bit argument X, return the value corresponding to
X with reversed byte order. */
-#define bswap_16(x) ((((x) & 0x00FF) << 8) | \
- (((x) & 0xFF00) >> 8))
+_GL_BYTESWAP_INLINE uint_least16_t
+bswap_16 (uint_least16_t x)
+{
+#ifdef _GL_BYTESWAP_HAS_BUILTIN_BSWAP16
+ return __builtin_bswap16 (x);
+#else
+ uint_fast16_t mask = 0xff;
+ return ( (x & mask << 8 * 1) >> 8 * 1
+ | (x & mask << 8 * 0) << 8 * 1);
+#endif
+}
/* Given an unsigned 32-bit argument X, return the value corresponding to
X with reversed byte order. */
-#define bswap_32(x) ((((x) & 0x000000FF) << 24) | \
- (((x) & 0x0000FF00) << 8) | \
- (((x) & 0x00FF0000) >> 8) | \
- (((x) & 0xFF000000) >> 24))
+_GL_BYTESWAP_INLINE uint_least32_t
+bswap_32 (uint_least32_t x)
+{
+#ifdef _GL_BYTESWAP_HAS_BUILTIN_BSWAP32
+ return __builtin_bswap32 (x);
+#else
+ uint_fast32_t mask = 0xff;
+ return ( (x & mask << 8 * 3) >> 8 * 3
+ | (x & mask << 8 * 2) >> 8 * 1
+ | (x & mask << 8 * 1) << 8 * 1
+ | (x & mask << 8 * 0) << 8 * 3);
+#endif
+}
+#ifdef UINT_LEAST64_MAX
/* Given an unsigned 64-bit argument X, return the value corresponding to
X with reversed byte order. */
-#define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \
- (((x) & 0x000000000000FF00ULL) << 40) | \
- (((x) & 0x0000000000FF0000ULL) << 24) | \
- (((x) & 0x00000000FF000000ULL) << 8) | \
- (((x) & 0x000000FF00000000ULL) >> 8) | \
- (((x) & 0x0000FF0000000000ULL) >> 24) | \
- (((x) & 0x00FF000000000000ULL) >> 40) | \
- (((x) & 0xFF00000000000000ULL) >> 56))
+_GL_BYTESWAP_INLINE uint_least64_t
+bswap_64 (uint_least64_t x)
+{
+# ifdef _GL_BYTESWAP_HAS_BUILTIN_BSWAP64
+ return __builtin_bswap64 (x);
+# else
+ uint_fast64_t mask = 0xff;
+ return ( (x & mask << 8 * 7) >> 8 * 7
+ | (x & mask << 8 * 6) >> 8 * 5
+ | (x & mask << 8 * 5) >> 8 * 3
+ | (x & mask << 8 * 4) >> 8 * 1
+ | (x & mask << 8 * 3) << 8 * 1
+ | (x & mask << 8 * 2) << 8 * 3
+ | (x & mask << 8 * 1) << 8 * 5
+ | (x & mask << 8 * 0) << 8 * 7);
+# endif
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+_GL_INLINE_HEADER_END
#endif /* _GL_BYTESWAP_H */
diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h
index 545749d6d27..a4b68c21064 100644
--- a/lib/count-leading-zeros.h
+++ b/lib/count-leading-zeros.h
@@ -45,8 +45,10 @@ extern "C" {
# define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
return x ? BUILTIN (x) : CHAR_BIT * sizeof x;
#elif _MSC_VER
+extern unsigned char _BitScanReverse (unsigned long *, unsigned long);
# pragma intrinsic (_BitScanReverse)
# if defined _M_X64
+extern unsigned char _BitScanReverse64 (unsigned long *, unsigned long long);
# pragma intrinsic (_BitScanReverse64)
# endif
# define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h
index 8d67f8718a4..24bf8cc2327 100644
--- a/lib/count-one-bits.h
+++ b/lib/count-one-bits.h
@@ -85,9 +85,12 @@ count_one_bits_32 (unsigned int x)
# include <intrin.h>
# else
/* Don't pollute the namespace with too many MSVC intrinsics. */
+extern void __cpuid (int[4], int);
# pragma intrinsic (__cpuid)
+extern unsigned int __popcnt (unsigned int);
# pragma intrinsic (__popcnt)
# if defined _M_X64
+extern unsigned long long __popcnt64 (unsigned long long);
# pragma intrinsic (__popcnt64)
# endif
# endif
diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h
index ed1e0131147..82de8731ec1 100644
--- a/lib/count-trailing-zeros.h
+++ b/lib/count-trailing-zeros.h
@@ -45,8 +45,10 @@ extern "C" {
# define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
return x ? BUILTIN (x) : CHAR_BIT * sizeof x;
#elif _MSC_VER
+extern unsigned char _BitScanForward (unsigned long *, unsigned long);
# pragma intrinsic (_BitScanForward)
# if defined _M_X64
+extern unsigned char _BitScanForward64 (unsigned long *, unsigned long long);
# pragma intrinsic (_BitScanForward64)
# endif
# define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index a5c009cfb85..d03e193b63c 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -361,6 +361,7 @@ GL_GENERATE_MINI_GMP_H_CONDITION = @GL_GENERATE_MINI_GMP_H_CONDITION@
GL_GENERATE_STDCKDINT_H_CONDITION = @GL_GENERATE_STDCKDINT_H_CONDITION@
GL_GENERATE_STDDEF_H_CONDITION = @GL_GENERATE_STDDEF_H_CONDITION@
GL_GENERATE_STDINT_H_CONDITION = @GL_GENERATE_STDINT_H_CONDITION@
+GL_GNULIB_ABORT_DEBUG = @GL_GNULIB_ABORT_DEBUG@
GL_GNULIB_ACCESS = @GL_GNULIB_ACCESS@
GL_GNULIB_ALIGNED_ALLOC = @GL_GNULIB_ALIGNED_ALLOC@
GL_GNULIB_ALPHASORT = @GL_GNULIB_ALPHASORT@
@@ -1107,6 +1108,7 @@ QCOPY_ACL_LIB = @QCOPY_ACL_LIB@
RALLOC_OBJ = @RALLOC_OBJ@
RANLIB = @RANLIB@
READELF = @READELF@
+REPLACE_ABORT = @REPLACE_ABORT@
REPLACE_ACCESS = @REPLACE_ACCESS@
REPLACE_ALIGNED_ALLOC = @REPLACE_ALIGNED_ALLOC@
REPLACE_CALLOC_FOR_CALLOC_GNU = @REPLACE_CALLOC_FOR_CALLOC_GNU@
@@ -1639,6 +1641,7 @@ ifneq (,$(GL_GENERATE_BYTESWAP_H_CONDITION))
byteswap.h: byteswap.in.h $(top_builddir)/config.status
$(gl_V_at)$(SED_HEADER_TO_AT_t) $(srcdir)/byteswap.in.h
$(AM_V_at)mv $@-t $@
+libgnu_a_SOURCES += byteswap.c
else
byteswap.h: $(top_builddir)/config.status
rm -f $@
@@ -3322,6 +3325,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
-e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
-e 's/@''GNULIB__EXIT''@/$(GL_GNULIB__EXIT)/g' \
+ -e 's/@''GNULIB_ABORT_DEBUG''@/$(GL_GNULIB_ABORT_DEBUG)/g' \
-e 's/@''GNULIB_ALIGNED_ALLOC''@/$(GL_GNULIB_ALIGNED_ALLOC)/g' \
-e 's/@''GNULIB_ATOLL''@/$(GL_GNULIB_ATOLL)/g' \
-e 's/@''GNULIB_CALLOC_GNU''@/$(GL_GNULIB_CALLOC_GNU)/g' \
@@ -3424,6 +3428,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
< $@-t1 > $@-t2
$(AM_V_at)sed \
-e 's|@''REPLACE__EXIT''@|$(REPLACE__EXIT)|g' \
+ -e 's|@''REPLACE_ABORT''@|$(REPLACE_ABORT)|g' \
-e 's|@''REPLACE_ALIGNED_ALLOC''@|$(REPLACE_ALIGNED_ALLOC)|g' \
-e 's|@''REPLACE_CALLOC_FOR_CALLOC_GNU''@|$(REPLACE_CALLOC_FOR_CALLOC_GNU)|g' \
-e 's|@''REPLACE_CALLOC_FOR_CALLOC_POSIX''@|$(REPLACE_CALLOC_FOR_CALLOC_POSIX)|g' \
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index e74e7c18d19..1888d3ee314 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -216,6 +216,23 @@ _GL_WARN_ON_USE (_Exit, "_Exit is unportable - "
#endif
+#if @GNULIB_ABORT_DEBUG@
+# if @REPLACE_ABORT@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef abort
+# define abort rpl_abort
+# endif
+_GL_FUNCDECL_RPL (abort, _Noreturn void, (void));
+_GL_CXXALIAS_RPL (abort, void, (void));
+# else
+_GL_CXXALIAS_SYS (abort, void, (void));
+# endif
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (abort);
+# endif
+#endif
+
+
#if @GNULIB_FREE_POSIX@
# if @REPLACE_FREE@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
diff --git a/lib/strftime.c b/lib/strftime.c
index 9b205e48023..834f3a79f46 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -143,11 +143,11 @@ extern char *tzname[];
enum pad_style
{
- ZERO_PAD, /* (default) Pad with 0 unless format says otherwise. */
- ALWAYS_ZERO_PAD, /* '0' Always pad with 0. */
- SIGN_PAD, /* '+' Always output a sign. */
- SPACE_PAD, /* '_' Pad with space. */
- NO_PAD /* '-' Do not pad. */
+ ZERO_PAD, /* (default) Pad with 0 unless format says otherwise. */
+ ALWAYS_ZERO_PAD, /* '0' Always pad with 0. */
+ SIGN_PAD, /* '+' Always output a sign. */
+ SPACE_PAD, /* '_' Pad with space. */
+ NO_PAD /* '-' Do not pad. */
};
#define TM_YEAR_BASE 1900
diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h
index de29c77949a..ddf25d1de4c 100644
--- a/lib/sys_select.in.h
+++ b/lib/sys_select.in.h
@@ -328,7 +328,9 @@ _GL_CXXALIAS_SYS (select, int,
(int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
timeval *restrict));
# endif
+# if __GLIBC__ >= 2
_GL_CXXALIASWARN (select);
+# endif
#elif @HAVE_WINSOCK2_H@
# undef select
# define select select_used_without_requesting_gnulib_module_select
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index fa99d7472f4..7dbed38969b 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -1934,11 +1934,7 @@ _GL_CXXALIASWARN (read);
# undef read
# define read _read
# endif
-# ifdef __MINGW32__
-_GL_CXXALIAS_MDA (read, int, (int fd, void *buf, unsigned int count));
-# else
-_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, unsigned int count));
-# endif
+_GL_CXXALIAS_MDA_CAST (read, ssize_t, (int fd, void *buf, unsigned int count));
# else
_GL_CXXALIAS_SYS (read, ssize_t, (int fd, void *buf, size_t count));
# endif
@@ -2402,11 +2398,7 @@ _GL_CXXALIASWARN (write);
# undef write
# define write _write
# endif
-# ifdef __MINGW32__
-_GL_CXXALIAS_MDA (write, int, (int fd, const void *buf, unsigned int count));
-# else
-_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, unsigned int count));
-# endif
+_GL_CXXALIAS_MDA_CAST (write, ssize_t, (int fd, const void *buf, unsigned int count));
# else
_GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
# endif