1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

Update from Gnulib by running admin/merge-gnulib

This commit is contained in:
Paul Eggert 2024-05-18 09:33:03 -07:00
parent c9af2fab92
commit 08550d058f
14 changed files with 173 additions and 36 deletions

21
lib/byteswap.c Normal file
View File

@ -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>

View File

@ -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 */

View File

@ -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) \

View File

@ -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

View File

@ -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) \

View File

@ -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' \

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,5 @@
# byteswap.m4
# serial 5
# serial 6
dnl Copyright (C) 2005, 2007, 2009-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@ -10,9 +10,28 @@ dnl Written by Oskar Liljeblad.
AC_DEFUN([gl_BYTESWAP],
[
dnl Prerequisites of lib/byteswap.in.h.
AC_CHECK_HEADERS([byteswap.h], [
AC_CHECK_HEADERS_ONCE([byteswap.h])
if test $ac_cv_header_byteswap_h = yes; then
AC_CACHE_CHECK([for working bswap_16, bswap_32, bswap_64],
[gl_cv_header_working_byteswap_h],
[gl_cv_header_working_byteswap_h=no
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <byteswap.h>
]],
[[int value_16 = bswap_16 (0.0);
int value_32 = bswap_32 (0.0);
int value_64 = bswap_64 (0.0);
return !(value_16 + value_32 + value_64);
]])
],
[gl_cv_header_working_byteswap_h=yes],
[gl_cv_header_working_byteswap_h=no])
])
fi
if test $gl_cv_header_working_byteswap_h = yes; then
GL_GENERATE_BYTESWAP_H=false
], [
else
GL_GENERATE_BYTESWAP_H=true
])
fi
])

View File

@ -1259,6 +1259,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/boot-time-aux.h
lib/boot-time.c
lib/boot-time.h
lib/byteswap.c
lib/byteswap.in.h
lib/c++defs.h
lib/c-ctype.c

View File

@ -81,7 +81,7 @@ AC_DEFUN([gl_ALIGNASOF],
References:
ISO C23 (latest free draft
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n3047.pdf>)
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf>)
sections 6.5.3.4, 6.7.5, 7.15.
C++11 (latest free draft
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf>)

View File

@ -1,5 +1,5 @@
# stdlib_h.m4
# serial 77
# serial 78
dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@ -110,6 +110,7 @@ AC_DEFUN([gl_STDLIB_H_REQUIRE_DEFAULTS],
[
m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDLIB_H_MODULE_INDICATOR_DEFAULTS], [
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB__EXIT])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ABORT_DEBUG])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ALIGNED_ALLOC])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ATOLL])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CALLOC_GNU])
@ -218,6 +219,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT])
HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV])
REPLACE__EXIT=0; AC_SUBST([REPLACE__EXIT])
REPLACE_ABORT=0; AC_SUBST([REPLACE_ABORT])
REPLACE_ALIGNED_ALLOC=0; AC_SUBST([REPLACE_ALIGNED_ALLOC])
REPLACE_CALLOC_FOR_CALLOC_GNU=0; AC_SUBST([REPLACE_CALLOC_FOR_CALLOC_GNU])
REPLACE_CALLOC_FOR_CALLOC_POSIX=0; AC_SUBST([REPLACE_CALLOC_FOR_CALLOC_POSIX])