glib/gnulib: Update sources from gnu git

Use the new!!! python importer tool as:

    ./gnulib-tool.py --import --lgpl=2 vasnprintf

  And added the glib diff, required to get it working
This commit is contained in:
Marco Trevisan (Treviño)
2024-05-11 01:53:50 +02:00
parent 86dd02f487
commit cdaf83766f
15 changed files with 3243 additions and 899 deletions

View File

@@ -1,9 +1,9 @@
/* A C macro for declaring that specific arguments must not be NULL.
Copyright (C) 2009-2018 Free Software Foundation, Inc.
Copyright (C) 2009-2024 Free Software Foundation, Inc.
This program 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
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -18,7 +18,7 @@
that the values passed as arguments n, ..., m must be non-NULL pointers.
n = 1 stands for the first argument, n = 2 for the second argument etc. */
#ifndef _GL_ARG_NONNULL
# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
# else
# define _GL_ARG_NONNULL(params)

View File

@@ -1,18 +1,18 @@
/* Formatted output to strings.
Copyright (C) 1999, 2002, 2006, 2009-2019 Free Software Foundation, Inc.
Copyright (C) 1999, 2002, 2006, 2009-2024 Free Software Foundation, Inc.
This program 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, or (at your option)
any later version.
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 program is distributed in the hope that it will be useful,
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/>. */
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>
@@ -21,6 +21,7 @@
/* Specification. */
#include "vasnprintf.h"
#include <stdarg.h>
char *

243
glib/gnulib/attribute.h Normal file
View File

@@ -0,0 +1,243 @@
/* ATTRIBUTE_* macros for using attributes in GCC and similar compilers
Copyright 2020-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/>. */
/* Written by Paul Eggert. */
/* Provide public ATTRIBUTE_* names for the private _GL_ATTRIBUTE_*
macros used within Gnulib. */
/* These attributes can be placed in two ways:
- At the start of a declaration (i.e. even before storage-class
specifiers!); then they apply to all entities that are declared
by the declaration.
- Immediately after the name of an entity being declared by the
declaration; then they apply to that entity only. */
#ifndef _GL_ATTRIBUTE_H
#define _GL_ATTRIBUTE_H
/* This file defines two types of attributes:
* C23 standard attributes. These have macro names that do not begin with
'ATTRIBUTE_'.
* Selected GCC attributes; see:
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html
These names begin with 'ATTRIBUTE_' to avoid name clashes. */
/* This file uses _GL_ATTRIBUTE_ALLOC_SIZE, _GL_ATTRIBUTE_ALWAYS_INLINE,
_GL_ATTRIBUTE_ARTIFICIAL, _GL_ATTRIBUTE_COLD, _GL_ATTRIBUTE_CONST,
_GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_DEPRECATED, _GL_ATTRIBUTE_ERROR,
_GL_ATTRIBUTE_WARNING, _GL_ATTRIBUTE_EXTERNALLY_VISIBLE,
_GL_ATTRIBUTE_FALLTHROUGH, _GL_ATTRIBUTE_FORMAT, _GL_ATTRIBUTE_LEAF,
_GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_MAY_ALIAS, _GL_ATTRIBUTE_MAYBE_UNUSED,
_GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOINLINE, _GL_ATTRIBUTE_NONNULL,
_GL_ATTRIBUTE_NONSTRING, _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PACKED,
_GL_ATTRIBUTE_PURE, _GL_ATTRIBUTE_RETURNS_NONNULL,
_GL_ATTRIBUTE_SENTINEL. */
#if !_GL_CONFIG_H_INCLUDED
#error "Please include config.h first."
#endif
/* =============== Attributes for specific kinds of functions =============== */
/* Attributes for functions that should not be used. */
/* Warn if the entity is used. */
/* Applies to:
- function, variable,
- struct, union, struct/union member,
- enumeration, enumeration item,
- typedef,
in C++ also: namespace, class, template specialization. */
#define DEPRECATED _GL_ATTRIBUTE_DEPRECATED
/* If a function call is not optimized way, warn with MSG. */
/* Applies to: functions. */
#define ATTRIBUTE_WARNING(msg) _GL_ATTRIBUTE_WARNING (msg)
/* If a function call is not optimized way, report an error with MSG. */
/* Applies to: functions. */
#define ATTRIBUTE_ERROR(msg) _GL_ATTRIBUTE_ERROR (msg)
/* Attributes for memory-allocating functions. */
/* The function returns a pointer to freshly allocated memory. */
/* Applies to: functions. */
#define ATTRIBUTE_MALLOC _GL_ATTRIBUTE_MALLOC
/* ATTRIBUTE_ALLOC_SIZE ((N)) - The Nth argument of the function
is the size of the returned memory block.
ATTRIBUTE_ALLOC_SIZE ((M, N)) - Multiply the Mth and Nth arguments
to determine the size of the returned memory block. */
/* Applies to: function, pointer to function, function types. */
#define ATTRIBUTE_ALLOC_SIZE(args) _GL_ATTRIBUTE_ALLOC_SIZE (args)
/* ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
that can be freed by passing them as the Ith argument to the
function F.
ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
can be freed via 'free'; it can be used only after declaring 'free'. */
/* Applies to: functions. Cannot be used on inline functions. */
#define ATTRIBUTE_DEALLOC(f, i) _GL_ATTRIBUTE_DEALLOC(f, i)
#define ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC_FREE
/* Attributes for variadic functions. */
/* The variadic function expects a trailing NULL argument.
ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
/* Applies to: functions. */
#define ATTRIBUTE_SENTINEL(pos) _GL_ATTRIBUTE_SENTINEL (pos)
/* ================== Attributes for compiler diagnostics ================== */
/* Attributes that help the compiler diagnose programmer mistakes.
Some of them may also help for some compiler optimizations. */
/* ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)) -
The STRING-INDEXth function argument is a format string of style
ARCHETYPE, which is one of:
printf, gnu_printf
scanf, gnu_scanf,
strftime, gnu_strftime,
strfmon,
or the same thing prefixed and suffixed with '__'.
If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
are suitable for the format string. */
/* Applies to: functions. */
#define ATTRIBUTE_FORMAT(spec) _GL_ATTRIBUTE_FORMAT (spec)
/* ATTRIBUTE_NONNULL ((N1, N2,...)) - Arguments N1, N2,... must not be NULL.
ATTRIBUTE_NONNULL () - All pointer arguments must not be null. */
/* Applies to: functions. */
#define ATTRIBUTE_NONNULL(args) _GL_ATTRIBUTE_NONNULL (args)
/* The function's return value is a non-NULL pointer. */
/* Applies to: functions. */
#define ATTRIBUTE_RETURNS_NONNULL _GL_ATTRIBUTE_RETURNS_NONNULL
/* Warn if the caller does not use the return value,
unless the caller uses something like ignore_value. */
/* Applies to: function, enumeration, class. */
#define NODISCARD _GL_ATTRIBUTE_NODISCARD
/* Attributes that disable false alarms when the compiler diagnoses
programmer "mistakes". */
/* Do not warn if the entity is not used. */
/* Applies to:
- function, variable,
- struct, union, struct/union member,
- enumeration, enumeration item,
- typedef,
in C++ also: class. */
#define MAYBE_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
/* The contents of a character array is not meant to be NUL-terminated. */
/* Applies to: struct/union members and variables that are arrays of element
type '[[un]signed] char'. */
#define ATTRIBUTE_NONSTRING _GL_ATTRIBUTE_NONSTRING
/* Do not warn if control flow falls through to the immediately
following 'case' or 'default' label. */
/* Applies to: Empty statement (;), inside a 'switch' statement. */
#define FALLTHROUGH _GL_ATTRIBUTE_FALLTHROUGH
/* ================== Attributes for debugging information ================== */
/* Attributes regarding debugging information emitted by the compiler. */
/* Omit the function from stack traces when debugging. */
/* Applies to: function. */
#define ATTRIBUTE_ARTIFICIAL _GL_ATTRIBUTE_ARTIFICIAL
/* Make the entity visible to debuggers etc., even with '-fwhole-program'. */
/* Applies to: functions, variables. */
#define ATTRIBUTE_EXTERNALLY_VISIBLE _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
/* ========== Attributes that mainly direct compiler optimizations ========== */
/* The function does not throw exceptions. */
/* Applies to: functions. */
/* After a function's parameter list, this attribute must come first, before
other attributes. */
#define ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_NOTHROW
/* Do not inline the function. */
/* Applies to: functions. */
#define ATTRIBUTE_NOINLINE _GL_ATTRIBUTE_NOINLINE
/* Always inline the function, and report an error if the compiler
cannot inline. */
/* Applies to: function. */
#define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE
/* It is OK for a compiler to omit duplicate calls with the same arguments.
This attribute is safe for a function that neither depends on
nor affects observable state, and always returns exactly once -
e.g., does not loop forever, and does not call longjmp.
(This attribute is stricter than ATTRIBUTE_PURE.) */
/* Applies to: functions. */
#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
/* It is OK for a compiler to omit duplicate calls with the same
arguments if observable state is not changed between calls.
This attribute is safe for a function that does not affect
observable state, and always returns exactly once.
(This attribute is looser than ATTRIBUTE_CONST.) */
/* Applies to: functions. */
#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE
/* The function is rarely executed. */
/* Applies to: functions. */
#define ATTRIBUTE_COLD _GL_ATTRIBUTE_COLD
/* If called from some other compilation unit, the function executes
code from that unit only by return or by exception handling,
letting the compiler optimize that unit more aggressively. */
/* Applies to: functions. */
#define ATTRIBUTE_LEAF _GL_ATTRIBUTE_LEAF
/* For struct members: The member has the smallest possible alignment.
For struct, union, class: All members have the smallest possible alignment,
minimizing the memory required. */
/* Applies to: struct members, struct, union,
in C++ also: class. */
#define ATTRIBUTE_PACKED _GL_ATTRIBUTE_PACKED
/* ================ Attributes that make invalid code valid ================ */
/* Attributes that prevent fatal compiler optimizations for code that is not
fully ISO C compliant. */
/* Pointers to the type may point to the same storage as pointers to
other types, thus disabling strict aliasing optimization. */
/* Applies to: types. */
#define ATTRIBUTE_MAY_ALIAS _GL_ATTRIBUTE_MAY_ALIAS
#endif /* _GL_ATTRIBUTE_H */

View File

@@ -1,9 +1,9 @@
/* C++ compatible function declaration macros.
Copyright (C) 2010-2019 Free Software Foundation, Inc.
Copyright (C) 2010-2024 Free Software Foundation, Inc.
This program 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
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -99,6 +99,12 @@
Example:
_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
_GL_ARG_NONNULL ((1)));
Note: Attributes, such as _GL_ATTRIBUTE_DEPRECATED, are supported in front
of a _GL_FUNCDECL_RPL invocation only in C mode, not in C++ mode. (That's
because
[[...]] extern "C" <declaration>;
is invalid syntax in C++.)
*/
#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
_GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
@@ -146,6 +152,16 @@
_GL_EXTERN_C int _gl_cxxalias_dummy
#endif
/* _GL_CXXALIAS_MDA (func, rettype, parameters);
is to be used when func is a Microsoft deprecated alias, on native Windows.
It declares a C++ alias called GNULIB_NAMESPACE::func
that redirects to _func, if GNULIB_NAMESPACE is defined.
Example:
_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
*/
#define _GL_CXXALIAS_MDA(func,rettype,parameters) \
_GL_CXXALIAS_RPL_1 (func, _##func, rettype, parameters)
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
except that the C function rpl_func may have a slightly different
@@ -171,6 +187,14 @@
_GL_EXTERN_C int _gl_cxxalias_dummy
#endif
/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters);
is like _GL_CXXALIAS_MDA (func, rettype, parameters);
except that the C function func may have a slightly different declaration.
A cast is used to silence the "invalid conversion" error that would
otherwise occur. */
#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \
_GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters)
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
declares a C++ alias called GNULIB_NAMESPACE::func
that redirects to the system provided function func, if GNULIB_NAMESPACE
@@ -268,7 +292,7 @@
_GL_CXXALIASWARN_2 (func, namespace)
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
we enable the warning only when not optimizing. */
# if !__OPTIMIZE__
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
# define _GL_CXXALIASWARN_2(func,namespace) \
_GL_WARN_ON_USE (func, \
"The symbol ::" #func " refers to the system function. " \
@@ -296,14 +320,11 @@
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
we enable the warning only when not optimizing. */
# if !__OPTIMIZE__
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
_GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
_GL_WARN_ON_USE_CXX (func, rettype, rettype, parameters_and_attributes, \
"The symbol ::" #func " refers to the system function. " \
"Use " #namespace "::" #func " instead.")
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
extern __typeof__ (func) func
# else
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
_GL_EXTERN_C int _gl_cxxalias_dummy

View File

@@ -1,19 +1,19 @@
/* Supplemental information about the floating-point formats.
Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc.
Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2007.
This program 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, or (at your option)
any later version.
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 program is distributed in the hope that it will be useful,
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/>. */
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#ifndef _FLOATPLUS_H
#define _FLOATPLUS_H

View File

@@ -14,10 +14,12 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __G_GNULIB_H__
#include "config.h"
#include <stdlib.h>
#include <stdint.h>
#include "glib/glib.h"
/* Private namespace for gnulib functions */
@@ -42,5 +44,375 @@
#define HAVE_SNPRINTF 0
#endif
#define _GL_CONFIG_H_INCLUDED 1
/* Add declarations that are normally generated by autoconf */
/* Define _GL_HAS_ATTRIBUTE only once, because on FreeBSD, with gcc < 5, if
<config.h> gets included once again after <sys/cdefs.h>, __has_attribute(x)
expands to 0 always, and redefining _GL_HAS_ATTRIBUTE would turn off all
attributes. */
#ifndef _GL_HAS_ATTRIBUTE
# if (defined __has_attribute \
&& (!defined __clang_minor__ \
|| (defined __apple_build_version__ \
? 7000000 <= __apple_build_version__ \
: 5 <= __clang_major__)))
# define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
# else
# define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
# define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
# define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
# define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
# define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
# define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
# define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
# define _GL_ATTR_diagnose_if 0
# define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
# define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
# define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
# define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
# define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
# define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
# ifdef _ICC
# define _GL_ATTR_may_alias 0
# else
# define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
# endif
# define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
# define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
# define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
# define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
# define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
# define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
# define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
# define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
# define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
# define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
# endif
#endif
/* _GL_ATTRIBUTE_FALLTHROUGH declares that it is not a programming mistake if
the control flow falls through to the immediately following 'case' or
'default' label. The compiler should not warn in this case. */
/* Applies to: Empty statement (;), inside a 'switch' statement. */
/* Always expands to something. */
#ifndef _GL_ATTRIBUTE_FALLTHROUGH
# if _GL_HAVE___HAS_C_ATTRIBUTE
# if __has_c_attribute (__fallthrough__)
# define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
# endif
# endif
# if !defined _GL_ATTRIBUTE_FALLTHROUGH && _GL_HAS_ATTRIBUTE (fallthrough)
# define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
# endif
# ifndef _GL_ATTRIBUTE_FALLTHROUGH
# define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
# endif
#endif
#ifndef _GL_ATTRIBUTE_FORMAT
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) || defined __clang__
# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
# else
# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
# endif
#endif
/* An __attribute__ __format__ specifier for a function that takes a format
string and arguments, where the format string directives are the ones
standardized by ISO C99 and POSIX.
_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD */
/* __gnu_printf__ is supported in GCC >= 4.4. */
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __gnu_printf__
#else
# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __printf__
#endif
/* The __attribute__ feature is available in gcc versions 2.5 and later.
The attribute __pure__ was added in gcc 2.96. */
#ifndef _GL_ATTRIBUTE_PURE
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
# else
# define _GL_ATTRIBUTE_PURE /* empty */
# endif
#endif
/* In GCC 4.6 (inclusive) to 5.1 (exclusive),
suppress bogus "no previous prototype for 'FOO'"
and "no previous declaration for 'FOO'" diagnostics,
when FOO is an inline function in the header; see
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113> and
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63877>. */
#if __GNUC__ == 4 && 6 <= __GNUC_MINOR__
# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
# define _GL_INLINE_HEADER_CONST_PRAGMA
# else
# define _GL_INLINE_HEADER_CONST_PRAGMA \
_Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
# endif
# define _GL_INLINE_HEADER_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
_Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \
_GL_INLINE_HEADER_CONST_PRAGMA
# define _GL_INLINE_HEADER_END \
_Pragma ("GCC diagnostic pop")
#else
# define _GL_INLINE_HEADER_BEGIN
# define _GL_INLINE_HEADER_END
#endif
#if ((__GNUC__ \
? (defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
&& !defined __PCC__) \
: (199901L <= __STDC_VERSION__ \
&& !defined __HP_cc \
&& !defined __PGI \
&& !(defined __SUNPRO_C && __STDC__))) \
&& !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
# define _GL_INLINE inline
# define _GL_EXTERN_INLINE extern inline
# define _GL_EXTERN_INLINE_IN_USE
#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
&& !defined __PCC__ \
&& !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
# if defined __GNUC_GNU_INLINE__ && __GNUC_GNU_INLINE__
/* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */
# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
# else
# define _GL_INLINE extern inline
# endif
# define _GL_EXTERN_INLINE extern
# define _GL_EXTERN_INLINE_IN_USE
#else
# define _GL_INLINE _GL_UNUSED static
# define _GL_EXTERN_INLINE _GL_UNUSED static
#endif
#include "arg-nonnull.h"
#include "wchar.h"
/* Override mbstate_t if it is too small.
On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
implementing mbrtowc for encodings like UTF-8.
On AIX and MSVC, mbrtowc needs to be overridden, but mbstate_t exists and is
large enough and overriding it would cause problems in C++ mode. */
#if !(defined _WIN32 && !defined __CYGWIN__) && \
(!defined ____mbstate_t_defined || ____mbstate_t_defined)
# if !GNULIB_defined_mbstate_t
# if !(defined _AIX || defined _MSC_VER)
typedef int rpl_mbstate_t;
# undef mbstate_t
# define mbstate_t rpl_mbstate_t
# endif
# define GNULIB_defined_mbstate_t 1
# endif
#endif
/* ISO C 23 § 7.31.6.(3) says that zeroing an mbstate_t is a way to put the
mbstate_t into an initial state. However, on many platforms an mbstate_t
is large, and it is possible - as an optimization - to get away with zeroing
only part of it. So, instead of
mbstate_t state = { 0 };
or
mbstate_t state;
memset (&state, 0, sizeof (mbstate_t));
we can write this faster code:
mbstate_t state;
mbszero (&state);
*/
/* _GL_MBSTATE_INIT_SIZE describes how mbsinit() behaves: It is the number of
bytes at the beginning of an mbstate_t that need to be zero, for mbsinit()
to return true.
_GL_MBSTATE_ZERO_SIZE is the number of bytes at the beginning of an mbstate_t
that need to be zero,
- for mbsinit() to return true, and
- for all other multibyte-aware functions to operate properly.
0 < _GL_MBSTATE_INIT_SIZE <= _GL_MBSTATE_ZERO_SIZE <= sizeof (mbstate_t).
These values are determined by source code inspection, where possible, and
by running the gnulib unit tests.
We need _GL_MBSTATE_INIT_SIZE because if we define _GL_MBSTATE_ZERO_SIZE
without considering what mbsinit() does, we get test failures such as
assertion "mbsinit (&iter->state)" failed
*/
# if GNULIB_defined_mbstate_t /* AIX, IRIX */
/* mbstate_t has at least 4 bytes. They are used as coded in
gnulib/lib/mbrtowc.c. */
# define _GL_MBSTATE_INIT_SIZE 1
/* define _GL_MBSTATE_ZERO_SIZE 4
does not work: it causes test failures.
So, use the safe fallback value, below. */
# elif __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 /* glibc */
/* mbstate_t is defined in <bits/types/__mbstate_t.h>.
For more details, see glibc/iconv/skeleton.c. */
# define _GL_MBSTATE_INIT_SIZE 4 /* sizeof (((mbstate_t) {0}).__count) */
# define _GL_MBSTATE_ZERO_SIZE /* 8 */ sizeof (mbstate_t)
# elif defined MUSL_LIBC /* musl libc */
/* mbstate_t is defined in <bits/alltypes.h>.
It is an opaque aligned 8-byte struct, of which at most the first
4 bytes are used.
For more details, see src/multibyte/mbrtowc.c. */
# define _GL_MBSTATE_INIT_SIZE 4 /* sizeof (unsigned) */
# define _GL_MBSTATE_ZERO_SIZE 4
# elif defined __APPLE__ && defined __MACH__ /* macOS */
/* On macOS, mbstate_t is defined in <machine/_types.h>.
It is an opaque aligned 128-byte struct, of which at most the first
12 bytes are used.
For more details, see the __mbsinit implementations in
Libc-<version>/locale/FreeBSD/
{ascii,none,euc,mskanji,big5,gb2312,gbk,gb18030,utf8,utf2}.c. */
/* File INIT_SIZE ZERO_SIZE
ascii.c 0 0
none.c 0 0
euc.c 12 12
mskanji.c 4 4
big5.c 4 4
gb2312.c 4 6
gbk.c 4 4
gb18030.c 4 8
utf8.c 8 10
utf2.c 8 12 */
# define _GL_MBSTATE_INIT_SIZE 12
# define _GL_MBSTATE_ZERO_SIZE 12
# elif defined __FreeBSD__ /* FreeBSD */
/* On FreeBSD, mbstate_t is defined in src/sys/sys/_types.h.
It is an opaque aligned 128-byte struct, of which at most the first
12 bytes are used.
For more details, see the __mbsinit implementations in
src/lib/libc/locale/
{ascii,none,euc,mskanji,big5,gb2312,gbk,gb18030,utf8}.c. */
/* File INIT_SIZE ZERO_SIZE
ascii.c 0 0
none.c 0 0
euc.c 12 12
mskanji.c 4 4
big5.c 4 4
gb2312.c 4 6
gbk.c 4 4
gb18030.c 4 8
utf8.c 8 12 */
# define _GL_MBSTATE_INIT_SIZE 12
# define _GL_MBSTATE_ZERO_SIZE 12
# elif defined __NetBSD__ /* NetBSD */
/* On NetBSD, mbstate_t is defined in src/sys/sys/ansi.h.
It is an opaque aligned 128-byte struct, of which at most the first
28 bytes are used.
For more details, see the *State types in
src/lib/libc/citrus/modules/citrus_*.c
(ignoring citrus_{hz,iso2022,utf7,viqr,zw}.c, since these implement
stateful encodings, not usable as locale encodings). */
/* File ZERO_SIZE
citrus/citrus_none.c 0
citrus/modules/citrus_euc.c 8
citrus/modules/citrus_euctw.c 8
citrus/modules/citrus_mskanji.c 8
citrus/modules/citrus_big5.c 8
citrus/modules/citrus_gbk2k.c 8
citrus/modules/citrus_dechanyu.c 8
citrus/modules/citrus_johab.c 6
citrus/modules/citrus_utf8.c 12 */
/* But 12 is not the correct value for _GL_MBSTATE_ZERO_SIZE: we get test
failures for values < 28. */
# define _GL_MBSTATE_ZERO_SIZE 28
# elif defined __OpenBSD__ /* OpenBSD */
/* On OpenBSD, mbstate_t is defined in src/sys/sys/_types.h.
It is an opaque aligned 128-byte struct, of which at most the first
12 bytes are used.
For more details, see src/lib/libc/citrus/citrus_*.c. */
/* File INIT_SIZE ZERO_SIZE
citrus_none.c 0 0
citrus_utf8.c 12 12 */
# define _GL_MBSTATE_INIT_SIZE 12
# define _GL_MBSTATE_ZERO_SIZE 12
# elif defined __minix /* Minix */
/* On Minix, mbstate_t is defined in sys/sys/ansi.h.
It is an opaque aligned 128-byte struct.
For more details, see the *State types in
lib/libc/citrus/citrus_*.c. */
/* File INIT_SIZE ZERO_SIZE
citrus_none.c 0 0 */
/* But 1 is not the correct value for _GL_MBSTATE_ZERO_SIZE: we get test
failures for values < 4. */
# define _GL_MBSTATE_ZERO_SIZE 4
# elif defined __sun /* Solaris */
/* On Solaris, mbstate_t is defined in <wchar_impl.h>.
It is an opaque aligned 24-byte or 32-byte struct, of which at most the first
20 or 28 bytes are used.
For more details on OpenSolaris derivatives, see the *State types in
illumos-gate/usr/src/lib/libc/port/locale/
{none,euc,mskanji,big5,gb2312,gbk,gb18030,utf8}.c. */
/* File INIT_SIZE ZERO_SIZE
none.c 0 0
euc.c 12 12
mskanji.c 4 4
big5.c 4 4
gb2312.c 4 6
gbk.c 4 4
gb18030.c 4 8
utf8.c 12 12 */
/* But 12 is not the correct value for _GL_MBSTATE_ZERO_SIZE: we get test
failures
- in OpenIndiana and OmniOS: for values < 16,
- in Solaris 10 and 11: for values < 20 (in 32-bit mode)
or < 28 (in 64-bit mode).
Since we don't have a good way to distinguish the OpenSolaris derivatives
from the proprietary Solaris versions, and can't inspect the Solaris source
code, use the safe fallback values, below. */
# elif defined __CYGWIN__ /* Cygwin */
/* On Cygwin, mbstate_t is defined in <sys/_types.h>.
For more details, see newlib/libc/stdlib/mbtowc_r.c and
winsup/cygwin/strfuncs.cc. */
# define _GL_MBSTATE_INIT_SIZE 4 /* sizeof (int) */
# define _GL_MBSTATE_ZERO_SIZE 8
# elif defined _WIN32 && !defined __CYGWIN__ /* Native Windows. */
/* MSVC defines 'mbstate_t' as an aligned 8-byte struct.
On mingw, 'mbstate_t' is sometimes defined as 'int', sometimes defined
as an aligned 8-byte struct, of which the first 4 bytes matter.
Use the safe values, below. */
# elif defined __ANDROID__ /* Android */
/* Android defines 'mbstate_t' in <bits/mbstate_t.h>.
It is an opaque 4-byte or 8-byte struct.
For more details, see
bionic/libc/private/bionic_mbstate.h
bionic/libc/bionic/mbrtoc32.cpp
bionic/libc/bionic/mbrtoc16.cpp
*/
# define _GL_MBSTATE_INIT_SIZE 4
# define _GL_MBSTATE_ZERO_SIZE 4
# endif
/* Use safe values as defaults. */
# ifndef _GL_MBSTATE_INIT_SIZE
# define _GL_MBSTATE_INIT_SIZE sizeof (mbstate_t)
# endif
# ifndef _GL_MBSTATE_ZERO_SIZE
# define _GL_MBSTATE_ZERO_SIZE sizeof (mbstate_t)
# endif
#ifdef __cplusplus
extern "C" {
#endif
# if defined IN_MBSZERO
_GL_EXTERN_INLINE
# else
_GL_INLINE
# endif
_GL_ARG_NONNULL ((1)) void
mbszero (mbstate_t *ps)
{
memset (ps, 0, _GL_MBSTATE_ZERO_SIZE);
}
#ifdef __cplusplus
}
#endif
#endif /* __G_GNULIB_H__ */

View File

@@ -1,19 +1,19 @@
/* Decomposed printf argument list.
Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2019 Free Software
Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2024 Free Software
Foundation, Inc.
This program 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, or (at your option)
any later version.
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 program is distributed in the hope that it will be useful,
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/>. */
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/>. */
/* This file can be parametrized with the following macros:
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
@@ -31,6 +31,9 @@
# include "printf-args.h"
#endif
/* Get INT_WIDTH. */
#include <limits.h>
#ifdef STATIC
STATIC
#endif
@@ -67,14 +70,108 @@ PRINTF_FETCHARGS (va_list args, arguments *a)
case TYPE_ULONGINT:
ap->a.a_ulongint = va_arg (args, unsigned long int);
break;
#if HAVE_LONG_LONG
case TYPE_LONGLONGINT:
ap->a.a_longlongint = va_arg (args, long long int);
break;
case TYPE_ULONGLONGINT:
ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
break;
#endif
case TYPE_INT8_T:
#if INT8_WIDTH < INT_WIDTH
ap->a.a_int8_t = va_arg (args, /* int8_t */ int);
#else
ap->a.a_int8_t = va_arg (args, int8_t);
#endif
break;
case TYPE_UINT8_T:
#if UINT8_WIDTH < INT_WIDTH
ap->a.a_uint8_t = va_arg (args, /* uint8_t */ int);
#else
ap->a.a_uint8_t = va_arg (args, uint8_t);
#endif
break;
case TYPE_INT16_T:
#if INT16_WIDTH < INT_WIDTH
ap->a.a_int16_t = va_arg (args, /* int16_t */ int);
#else
ap->a.a_int16_t = va_arg (args, int16_t);
#endif
break;
case TYPE_UINT16_T:
#if UINT16_WIDTH < INT_WIDTH
ap->a.a_uint16_t = va_arg (args, /* uint16_t */ int);
#else
ap->a.a_uint16_t = va_arg (args, uint16_t);
#endif
break;
case TYPE_INT32_T:
#if INT32_WIDTH < INT_WIDTH
ap->a.a_int32_t = va_arg (args, /* int32_t */ int);
#else
ap->a.a_int32_t = va_arg (args, int32_t);
#endif
break;
case TYPE_UINT32_T:
#if UINT32_WIDTH < INT_WIDTH
ap->a.a_uint32_t = va_arg (args, /* uint32_t */ int);
#else
ap->a.a_uint32_t = va_arg (args, uint32_t);
#endif
break;
case TYPE_INT64_T:
ap->a.a_int64_t = va_arg (args, int64_t);
break;
case TYPE_UINT64_T:
ap->a.a_uint64_t = va_arg (args, uint64_t);
break;
case TYPE_INT_FAST8_T:
#if INT_FAST8_WIDTH < INT_WIDTH
ap->a.a_int_fast8_t = va_arg (args, /* int_fast8_t */ int);
#else
ap->a.a_int_fast8_t = va_arg (args, int_fast8_t);
#endif
break;
case TYPE_UINT_FAST8_T:
#if UINT_FAST8_WIDTH < INT_WIDTH
ap->a.a_uint_fast8_t = va_arg (args, /* uint_fast8_t */ int);
#else
ap->a.a_uint_fast8_t = va_arg (args, uint_fast8_t);
#endif
break;
case TYPE_INT_FAST16_T:
#if INT_FAST16_WIDTH < INT_WIDTH
ap->a.a_int_fast16_t = va_arg (args, /* int_fast16_t */ int);
#else
ap->a.a_int_fast16_t = va_arg (args, int_fast16_t);
#endif
break;
case TYPE_UINT_FAST16_T:
#if UINT_FAST16_WIDTH < INT_WIDTH
ap->a.a_uint_fast16_t = va_arg (args, /* uint_fast16_t */ int);
#else
ap->a.a_uint_fast16_t = va_arg (args, uint_fast16_t);
#endif
break;
case TYPE_INT_FAST32_T:
#if INT_FAST32_WIDTH < INT_WIDTH
ap->a.a_int_fast32_t = va_arg (args, /* int_fast32_t */ int);
#else
ap->a.a_int_fast32_t = va_arg (args, int_fast32_t);
#endif
break;
case TYPE_UINT_FAST32_T:
#if UINT_FAST32_WIDTH < INT_WIDTH
ap->a.a_uint_fast32_t = va_arg (args, /* uint_fast32_t */ int);
#else
ap->a.a_uint_fast32_t = va_arg (args, uint_fast32_t);
#endif
break;
case TYPE_INT_FAST64_T:
ap->a.a_int_fast64_t = va_arg (args, int_fast64_t);
break;
case TYPE_UINT_FAST64_T:
ap->a.a_uint_fast64_t = va_arg (args, uint_fast64_t);
break;
case TYPE_DOUBLE:
ap->a.a_double = va_arg (args, double);
break;
@@ -137,11 +234,33 @@ PRINTF_FETCHARGS (va_list args, arguments *a)
case TYPE_COUNT_LONGINT_POINTER:
ap->a.a_count_longint_pointer = va_arg (args, long int *);
break;
#if HAVE_LONG_LONG
case TYPE_COUNT_LONGLONGINT_POINTER:
ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
break;
#endif
case TYPE_COUNT_INT8_T_POINTER:
ap->a.a_count_int8_t_pointer = va_arg (args, int8_t *);
break;
case TYPE_COUNT_INT16_T_POINTER:
ap->a.a_count_int16_t_pointer = va_arg (args, int16_t *);
break;
case TYPE_COUNT_INT32_T_POINTER:
ap->a.a_count_int32_t_pointer = va_arg (args, int32_t *);
break;
case TYPE_COUNT_INT64_T_POINTER:
ap->a.a_count_int64_t_pointer = va_arg (args, int64_t *);
break;
case TYPE_COUNT_INT_FAST8_T_POINTER:
ap->a.a_count_int_fast8_t_pointer = va_arg (args, int_fast8_t *);
break;
case TYPE_COUNT_INT_FAST16_T_POINTER:
ap->a.a_count_int_fast16_t_pointer = va_arg (args, int_fast16_t *);
break;
case TYPE_COUNT_INT_FAST32_T_POINTER:
ap->a.a_count_int_fast32_t_pointer = va_arg (args, int_fast32_t *);
break;
case TYPE_COUNT_INT_FAST64_T_POINTER:
ap->a.a_count_int_fast64_t_pointer = va_arg (args, int_fast64_t *);
break;
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
case TYPE_U8_STRING:

View File

@@ -1,19 +1,19 @@
/* Decomposed printf argument list.
Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2019 Free Software
Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2024 Free Software
Foundation, Inc.
This program 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, or (at your option)
any later version.
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 program is distributed in the hope that it will be useful,
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/>. */
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/>. */
#ifndef _PRINTF_ARGS_H
#define _PRINTF_ARGS_H
@@ -41,6 +41,9 @@
# include <wchar.h>
#endif
/* Get intN_t, uintN_t, intN_fast_t, uintN_fast_t. */
#include <stdint.h>
/* Get va_list. */
#include <stdarg.h>
@@ -57,10 +60,28 @@ typedef enum
TYPE_UINT,
TYPE_LONGINT,
TYPE_ULONGINT,
#if HAVE_LONG_LONG
TYPE_LONGLONGINT,
TYPE_ULONGLONGINT,
#endif
/* According to ISO C 23 § 7.23.6.1, "all exact-width integer types",
"all minimum-width integer types", and "all fastest minimum-width integer
types" defined in <stdint.h> should be supported. But for portability
between platforms, we support only those with N = 8, 16, 32, 64. */
TYPE_INT8_T,
TYPE_UINT8_T,
TYPE_INT16_T,
TYPE_UINT16_T,
TYPE_INT32_T,
TYPE_UINT32_T,
TYPE_INT64_T,
TYPE_UINT64_T,
TYPE_INT_FAST8_T,
TYPE_UINT_FAST8_T,
TYPE_INT_FAST16_T,
TYPE_UINT_FAST16_T,
TYPE_INT_FAST32_T,
TYPE_UINT_FAST32_T,
TYPE_INT_FAST64_T,
TYPE_UINT_FAST64_T,
TYPE_DOUBLE,
TYPE_LONGDOUBLE,
TYPE_CHAR,
@@ -75,10 +96,16 @@ typedef enum
TYPE_COUNT_SCHAR_POINTER,
TYPE_COUNT_SHORT_POINTER,
TYPE_COUNT_INT_POINTER,
TYPE_COUNT_LONGINT_POINTER
#if HAVE_LONG_LONG
, TYPE_COUNT_LONGLONGINT_POINTER
#endif
TYPE_COUNT_LONGINT_POINTER,
TYPE_COUNT_LONGLONGINT_POINTER,
TYPE_COUNT_INT8_T_POINTER,
TYPE_COUNT_INT16_T_POINTER,
TYPE_COUNT_INT32_T_POINTER,
TYPE_COUNT_INT64_T_POINTER,
TYPE_COUNT_INT_FAST8_T_POINTER,
TYPE_COUNT_INT_FAST16_T_POINTER,
TYPE_COUNT_INT_FAST32_T_POINTER,
TYPE_COUNT_INT_FAST64_T_POINTER
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
, TYPE_U8_STRING
@@ -101,11 +128,25 @@ typedef struct
unsigned int a_uint;
long int a_longint;
unsigned long int a_ulongint;
#if HAVE_LONG_LONG
long long int a_longlongint;
unsigned long long int a_ulonglongint;
#endif
float a_float;
int8_t a_int8_t;
uint8_t a_uint8_t;
int16_t a_int16_t;
uint16_t a_uint16_t;
int32_t a_int32_t;
uint32_t a_uint32_t;
int64_t a_int64_t;
uint64_t a_uint64_t;
int_fast8_t a_int_fast8_t;
uint_fast8_t a_uint_fast8_t;
int_fast16_t a_int_fast16_t;
uint_fast16_t a_uint_fast16_t;
int_fast32_t a_int_fast32_t;
uint_fast32_t a_uint_fast32_t;
int_fast64_t a_int_fast64_t;
uint_fast64_t a_uint_fast64_t;
float a_float; /* unused */
double a_double;
long double a_longdouble;
int a_char;
@@ -121,9 +162,15 @@ typedef struct
short * a_count_short_pointer;
int * a_count_int_pointer;
long int * a_count_longint_pointer;
#if HAVE_LONG_LONG
long long int * a_count_longlongint_pointer;
#endif
int8_t * a_count_int8_t_pointer;
int16_t * a_count_int16_t_pointer;
int32_t * a_count_int32_t_pointer;
int64_t * a_count_int64_t_pointer;
int_fast8_t * a_count_int_fast8_t_pointer;
int_fast16_t * a_count_int_fast16_t_pointer;
int_fast32_t * a_count_int_fast32_t_pointer;
int_fast64_t * a_count_int_fast64_t_pointer;
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
const uint8_t * a_u8_string;

View File

@@ -1,18 +1,18 @@
/* Formatted output to strings.
Copyright (C) 1999-2000, 2002-2003, 2006-2019 Free Software Foundation, Inc.
Copyright (C) 1999-2000, 2002-2003, 2006-2024 Free Software Foundation, Inc.
This program 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, or (at your option)
any later version.
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 program is distributed in the hope that it will be useful,
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/>. */
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/>. */
/* This file can be parametrized with the following macros:
CHAR_T The element type of the format string.
@@ -50,16 +50,7 @@
#include <stddef.h>
/* Get intmax_t. */
#if defined IN_LIBINTL || defined IN_LIBASPRINTF
# if HAVE_STDINT_H_WITH_UINTMAX
# include <stdint.h>
# endif
# if HAVE_INTTYPES_H_WITH_UINTMAX
# include <inttypes.h>
# endif
#else
# include <stdint.h>
#endif
#include <stdint.h>
/* malloc(), realloc(), free(). */
#include <stdlib.h>
@@ -337,232 +328,320 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
arg_type type;
/* Parse argument type/size specifiers. */
{
int flags = 0;
/* Relevant for the conversion characters d, i. */
arg_type signed_type = TYPE_INT;
/* Relevant for the conversion characters b, o, u, x, X. */
arg_type unsigned_type = TYPE_UINT;
/* Relevant for the conversion characters n. */
arg_type pointer_type = TYPE_COUNT_INT_POINTER;
/* Relevant for the conversion characters a, A, e, E, f, F, g, G. */
arg_type floatingpoint_type = TYPE_DOUBLE;
for (;;)
{
if (*cp == 'h')
{
flags |= (1 << (flags & 1));
cp++;
}
else if (*cp == 'L')
{
flags |= 4;
cp++;
}
else if (*cp == 'l')
{
flags += 8;
cp++;
}
else if (*cp == 'j')
{
if (sizeof (intmax_t) > sizeof (long))
{
/* intmax_t = long long */
flags += 16;
}
else if (sizeof (intmax_t) > sizeof (int))
{
/* intmax_t = long */
flags += 8;
}
cp++;
}
else if (*cp == 'z' || *cp == 'Z')
{
/* 'z' is standardized in ISO C 99, but glibc uses 'Z'
because the warning facility in gcc-2.95.2 understands
only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */
if (sizeof (size_t) > sizeof (long))
{
/* size_t = long long */
flags += 16;
}
else if (sizeof (size_t) > sizeof (int))
{
/* size_t = long */
flags += 8;
}
cp++;
}
else if (*cp == 't')
{
if (sizeof (ptrdiff_t) > sizeof (long))
{
/* ptrdiff_t = long long */
flags += 16;
}
else if (sizeof (ptrdiff_t) > sizeof (int))
{
/* ptrdiff_t = long */
flags += 8;
}
cp++;
}
if (*cp == 'h')
{
if (cp[1] == 'h')
{
signed_type = TYPE_SCHAR;
unsigned_type = TYPE_UCHAR;
pointer_type = TYPE_COUNT_SCHAR_POINTER;
cp += 2;
}
else
{
signed_type = TYPE_SHORT;
unsigned_type = TYPE_USHORT;
pointer_type = TYPE_COUNT_SHORT_POINTER;
cp++;
}
}
else if (*cp == 'l')
{
if (cp[1] == 'l')
{
signed_type = TYPE_LONGLONGINT;
unsigned_type = TYPE_ULONGLONGINT;
pointer_type = TYPE_COUNT_LONGLONGINT_POINTER;
/* For backward compatibility only. */
floatingpoint_type = TYPE_LONGDOUBLE;
cp += 2;
}
else
{
signed_type = TYPE_LONGINT;
unsigned_type = TYPE_ULONGINT;
pointer_type = TYPE_COUNT_LONGINT_POINTER;
cp++;
}
}
else if (*cp == 'j')
{
if (sizeof (intmax_t) > sizeof (long))
{
/* intmax_t = long long */
signed_type = TYPE_LONGLONGINT;
unsigned_type = TYPE_ULONGLONGINT;
pointer_type = TYPE_COUNT_LONGLONGINT_POINTER;
/* For backward compatibility only. */
floatingpoint_type = TYPE_LONGDOUBLE;
}
else if (sizeof (intmax_t) > sizeof (int))
{
/* intmax_t = long */
signed_type = TYPE_LONGINT;
unsigned_type = TYPE_ULONGINT;
pointer_type = TYPE_COUNT_LONGINT_POINTER;
}
cp++;
}
else if (*cp == 'z' || *cp == 'Z')
{
/* 'z' is standardized in ISO C 99, but glibc uses 'Z'
because the warning facility in gcc-2.95.2 understands
only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */
if (sizeof (size_t) > sizeof (long))
{
/* size_t = unsigned long long */
signed_type = TYPE_LONGLONGINT;
unsigned_type = TYPE_ULONGLONGINT;
pointer_type = TYPE_COUNT_LONGLONGINT_POINTER;
/* For backward compatibility only. */
floatingpoint_type = TYPE_LONGDOUBLE;
}
else if (sizeof (size_t) > sizeof (int))
{
/* size_t = unsigned long */
signed_type = TYPE_LONGINT;
unsigned_type = TYPE_ULONGINT;
pointer_type = TYPE_COUNT_LONGINT_POINTER;
}
cp++;
}
else if (*cp == 't')
{
if (sizeof (ptrdiff_t) > sizeof (long))
{
/* ptrdiff_t = long long */
signed_type = TYPE_LONGLONGINT;
unsigned_type = TYPE_ULONGLONGINT;
pointer_type = TYPE_COUNT_LONGLONGINT_POINTER;
/* For backward compatibility only. */
floatingpoint_type = TYPE_LONGDOUBLE;
}
else if (sizeof (ptrdiff_t) > sizeof (int))
{
/* ptrdiff_t = long */
signed_type = TYPE_LONGINT;
unsigned_type = TYPE_ULONGINT;
pointer_type = TYPE_COUNT_LONGINT_POINTER;
}
cp++;
}
else if (*cp == 'w')
{
/* wN and wfN are standardized in ISO C 23. */
if (cp[1] == 'f')
{
if (cp[2] == '8')
{
signed_type = TYPE_INT_FAST8_T;
unsigned_type = TYPE_UINT_FAST8_T;
pointer_type = TYPE_COUNT_INT_FAST8_T_POINTER;
cp += 3;
}
else if (cp[2] == '1' && cp[3] == '6')
{
signed_type = TYPE_INT_FAST16_T;
unsigned_type = TYPE_UINT_FAST16_T;
pointer_type = TYPE_COUNT_INT_FAST16_T_POINTER;
cp += 4;
}
else if (cp[2] == '3' && cp[3] == '2')
{
signed_type = TYPE_INT_FAST32_T;
unsigned_type = TYPE_UINT_FAST32_T;
pointer_type = TYPE_COUNT_INT_FAST32_T_POINTER;
cp += 4;
}
else if (cp[2] == '6' && cp[3] == '4')
{
signed_type = TYPE_INT_FAST64_T;
unsigned_type = TYPE_UINT_FAST64_T;
pointer_type = TYPE_COUNT_INT_FAST64_T_POINTER;
cp += 4;
}
}
else
{
if (cp[1] == '8')
{
signed_type = TYPE_INT8_T;
unsigned_type = TYPE_UINT8_T;
pointer_type = TYPE_COUNT_INT8_T_POINTER;
cp += 2;
}
else if (cp[1] == '1' && cp[2] == '6')
{
signed_type = TYPE_INT16_T;
unsigned_type = TYPE_UINT16_T;
pointer_type = TYPE_COUNT_INT16_T_POINTER;
cp += 3;
}
else if (cp[1] == '3' && cp[2] == '2')
{
signed_type = TYPE_INT32_T;
unsigned_type = TYPE_UINT32_T;
pointer_type = TYPE_COUNT_INT32_T_POINTER;
cp += 3;
}
else if (cp[1] == '6' && cp[2] == '4')
{
signed_type = TYPE_INT64_T;
unsigned_type = TYPE_UINT64_T;
pointer_type = TYPE_COUNT_INT64_T_POINTER;
cp += 3;
}
}
}
else if (*cp == 'L')
{
signed_type = TYPE_LONGLONGINT;
unsigned_type = TYPE_ULONGLONGINT;
pointer_type = TYPE_COUNT_LONGLONGINT_POINTER;
floatingpoint_type = TYPE_LONGDOUBLE;
cp++;
}
#if defined __APPLE__ && defined __MACH__
/* On Mac OS X 10.3, PRIdMAX is defined as "qd".
We cannot change it to "lld" because PRIdMAX must also
be understood by the system's printf routines. */
else if (*cp == 'q')
{
if (64 / 8 > sizeof (long))
{
/* int64_t = long long */
flags += 16;
}
else
{
/* int64_t = long */
flags += 8;
}
cp++;
}
/* On Mac OS X 10.3, PRIdMAX is defined as "qd".
We cannot change it to "lld" because PRIdMAX must also
be understood by the system's printf routines. */
else if (*cp == 'q')
{
if (64 / 8 > sizeof (long))
{
/* int64_t = long long */
signed_type = TYPE_LONGLONGINT;
unsigned_type = TYPE_ULONGLONGINT;
pointer_type = TYPE_COUNT_LONGLONGINT_POINTER;
/* For backward compatibility only. */
floatingpoint_type = TYPE_LONGDOUBLE;
}
else
{
/* int64_t = long */
signed_type = TYPE_LONGINT;
unsigned_type = TYPE_ULONGINT;
pointer_type = TYPE_COUNT_LONGINT_POINTER;
}
cp++;
}
#endif
#if defined _WIN32 && ! defined __CYGWIN__
/* On native Windows, PRIdMAX is defined as "I64d".
We cannot change it to "lld" because PRIdMAX must also
be understood by the system's printf routines. */
else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
{
if (64 / 8 > sizeof (long))
{
/* __int64 = long long */
flags += 16;
}
else
{
/* __int64 = long */
flags += 8;
}
cp += 3;
}
/* On native Windows, PRIdMAX is defined as "I64d".
We cannot change it to "lld" because PRIdMAX must also
be understood by the system's printf routines. */
else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
{
if (64 / 8 > sizeof (long))
{
/* __int64_t = long long */
signed_type = TYPE_LONGLONGINT;
unsigned_type = TYPE_ULONGLONGINT;
pointer_type = TYPE_COUNT_LONGLONGINT_POINTER;
/* For backward compatibility only. */
floatingpoint_type = TYPE_LONGDOUBLE;
}
else
{
/* __int64_t = long */
signed_type = TYPE_LONGINT;
unsigned_type = TYPE_ULONGINT;
pointer_type = TYPE_COUNT_LONGINT_POINTER;
}
cp += 3;
}
#endif
else
break;
}
(void) pointer_type;
/* Read the conversion character. */
c = *cp++;
switch (c)
{
case 'd': case 'i':
#if HAVE_LONG_LONG
/* If 'long long' exists and is larger than 'long': */
if (flags >= 16 || (flags & 4))
type = TYPE_LONGLONGINT;
else
#endif
/* If 'long long' exists and is the same as 'long', we parse
"lld" into TYPE_LONGINT. */
if (flags >= 8)
type = TYPE_LONGINT;
else if (flags & 2)
type = TYPE_SCHAR;
else if (flags & 1)
type = TYPE_SHORT;
else
type = TYPE_INT;
break;
case 'o': case 'u': case 'x': case 'X':
#if HAVE_LONG_LONG
/* If 'long long' exists and is larger than 'long': */
if (flags >= 16 || (flags & 4))
type = TYPE_ULONGLONGINT;
else
#endif
/* If 'unsigned long long' exists and is the same as
'unsigned long', we parse "llu" into TYPE_ULONGINT. */
if (flags >= 8)
type = TYPE_ULONGINT;
else if (flags & 2)
type = TYPE_UCHAR;
else if (flags & 1)
type = TYPE_USHORT;
else
type = TYPE_UINT;
break;
case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
case 'a': case 'A':
if (flags >= 16 || (flags & 4))
type = TYPE_LONGDOUBLE;
else
type = TYPE_DOUBLE;
break;
case 'c':
if (flags >= 8)
/* Read the conversion character. */
c = *cp++;
switch (c)
{
case 'd': case 'i':
type = signed_type;
break;
case 'b': case 'o': case 'u': case 'x': case 'X':
#if SUPPORT_GNU_PRINTF_DIRECTIVES \
|| (__GLIBC__ + (__GLIBC_MINOR__ >= 35) > 2)
case 'B':
#endif
type = unsigned_type;
break;
case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
case 'a': case 'A':
type = floatingpoint_type;
break;
case 'c':
if (signed_type == TYPE_LONGINT
/* For backward compatibility only. */
|| signed_type == TYPE_LONGLONGINT)
#if HAVE_WINT_T
type = TYPE_WIDE_CHAR;
#else
goto error;
#endif
else
type = TYPE_CHAR;
break;
#if HAVE_WINT_T
case 'C':
type = TYPE_WIDE_CHAR;
c = 'c';
break;
#endif
case 's':
if (flags >= 8)
#if HAVE_WCHAR_T
type = TYPE_WIDE_STRING;
#else
goto error;
#endif
else
type = TYPE_STRING;
break;
#if HAVE_WCHAR_T
case 'S':
type = TYPE_WIDE_STRING;
c = 's';
break;
#endif
case 'p':
type = TYPE_POINTER;
break;
case 'n':
#if HAVE_LONG_LONG
/* If 'long long' exists and is larger than 'long': */
if (flags >= 16 || (flags & 4))
type = TYPE_COUNT_LONGLONGINT_POINTER;
else
#endif
/* If 'long long' exists and is the same as 'long', we parse
"lln" into TYPE_COUNT_LONGINT_POINTER. */
if (flags >= 8)
type = TYPE_COUNT_LONGINT_POINTER;
else if (flags & 2)
type = TYPE_COUNT_SCHAR_POINTER;
else if (flags & 1)
type = TYPE_COUNT_SHORT_POINTER;
else
type = TYPE_COUNT_INT_POINTER;
break;
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
case 'U':
if (flags >= 16)
type = TYPE_U32_STRING;
else if (flags >= 8)
type = TYPE_U16_STRING;
else
type = TYPE_U8_STRING;
break;
#endif
case '%':
type = TYPE_NONE;
break;
default:
/* Unknown conversion character. */
goto error;
}
}
#endif
else
type = TYPE_CHAR;
break;
#if HAVE_WINT_T
case 'C':
type = TYPE_WIDE_CHAR;
c = 'c';
break;
#endif
case 's':
if (signed_type == TYPE_LONGINT
/* For backward compatibility only. */
|| signed_type == TYPE_LONGLONGINT)
#if HAVE_WCHAR_T
type = TYPE_WIDE_STRING;
#else
goto error;
#endif
else
type = TYPE_STRING;
break;
#if HAVE_WCHAR_T
case 'S':
type = TYPE_WIDE_STRING;
c = 's';
break;
#endif
case 'p':
type = TYPE_POINTER;
break;
#if NEED_PRINTF_WITH_N_DIRECTIVE
case 'n':
type = pointer_type;
break;
#endif
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
case 'U':
if (signed_type == TYPE_LONGLONGINT)
type = TYPE_U32_STRING;
else if (signed_type == TYPE_LONGINT)
type = TYPE_U16_STRING;
else
type = TYPE_U8_STRING;
break;
#endif
case '%':
type = TYPE_NONE;
break;
default:
/* Unknown conversion character. */
goto error;
}
if (type != TYPE_NONE)
{

View File

@@ -1,19 +1,19 @@
/* Parse printf format string.
Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2019 Free Software
Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2024 Free Software
Foundation, Inc.
This program 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, or (at your option)
any later version.
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 program is distributed in the hope that it will be useful,
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/>. */
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/>. */
#ifndef _PRINTF_PARSE_H
#define _PRINTF_PARSE_H
@@ -61,7 +61,7 @@ typedef struct
const char* precision_start;
const char* precision_end;
size_t precision_arg_index;
char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
char conversion; /* d i b B o u x X f F e E g G a A c s p n U % but not C S */
size_t arg_index;
}
char_directive;
@@ -91,7 +91,7 @@ typedef struct
const uint8_t* precision_start;
const uint8_t* precision_end;
size_t precision_arg_index;
uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
uint8_t conversion; /* d i b B o u x X f F e E g G a A c s p n U % but not C S */
size_t arg_index;
}
u8_directive;
@@ -119,7 +119,7 @@ typedef struct
const uint16_t* precision_start;
const uint16_t* precision_end;
size_t precision_arg_index;
uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
uint16_t conversion; /* d i b B o u x X f F e E g G a A c s p n U % but not C S */
size_t arg_index;
}
u16_directive;
@@ -147,7 +147,7 @@ typedef struct
const uint32_t* precision_start;
const uint32_t* precision_end;
size_t precision_arg_index;
uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
uint32_t conversion; /* d i b B o u x X f F e E g G a A c s p n U % but not C S */
size_t arg_index;
}
u32_directive;

File diff suppressed because it is too large Load Diff

View File

@@ -1,40 +1,33 @@
/* vsprintf with automatic memory allocation.
Copyright (C) 2002-2004, 2007-2019 Free Software Foundation, Inc.
Copyright (C) 2002-2004, 2007-2024 Free Software Foundation, Inc.
This program 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, or (at your option)
any later version.
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 program is distributed in the hope that it will be useful,
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/>. */
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/>. */
#ifndef _VASNPRINTF_H
#define _VASNPRINTF_H
/* This file uses _GL_ATTRIBUTE_FORMAT. */
#if !_GL_CONFIG_H_INCLUDED
#error "Please include config.h first."
#endif
/* Get va_list. */
#include <stdarg.h>
/* Get size_t. */
#include <stddef.h>
/* The __attribute__ feature is available in gcc versions 2.5 and later.
The __-protected variants of the attributes 'format' and 'printf' are
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
gnulib and libintl do '#define printf __printf__' when they override
the 'printf' function. */
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
#else
# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -67,10 +60,12 @@ extern "C" {
# define asnprintf rpl_asnprintf
# define vasnprintf rpl_vasnprintf
#endif
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
_GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
_GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0));
extern char * asnprintf (char *restrict resultbuf, size_t *lengthp,
const char *format, ...)
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4));
extern char * vasnprintf (char *restrict resultbuf, size_t *lengthp,
const char *format, va_list args)
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0));
#ifdef __cplusplus
}

View File

@@ -1,13 +1,13 @@
/* Compile-time assert-like macros.
Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc.
Copyright (C) 2005-2006, 2009-2024 Free Software Foundation, Inc.
This program 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 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 program is distributed in the hope that it will be useful,
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.
@@ -21,29 +21,32 @@
#define _GL_VERIFY_H
/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11.
This is supported by GCC 4.6.0 and later, in C mode, and its use
here generates easier-to-read diagnostics when verify (R) fails.
/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC)
works as per C11. This is supported by GCC 4.6.0+ and by clang 4+.
Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per C++11.
This is supported by GCC 6.1.0 and later, in C++ mode.
Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as
per C23. This is supported by GCC 9.1+.
Use this only with GCC. If we were willing to slow 'configure'
down we could also use it with other compilers, but since this
affects only the quality of diagnostics, why bother? */
#if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \
&& (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \
&& !defined __cplusplus)
# define _GL_HAVE__STATIC_ASSERT 1
#endif
#if (6 <= __GNUC__) && defined __cplusplus
# define _GL_HAVE_STATIC_ASSERT 1
Support compilers claiming conformance to the relevant standard,
and also support GCC when not pedantic. If we were willing to slow
'configure' down we could also use it with other compilers, but
since this affects only the quality of diagnostics, why bother? */
#ifndef __cplusplus
# if (201112 <= __STDC_VERSION__ \
|| (!defined __STRICT_ANSI__ \
&& (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 5 <= __clang_major__)))
# define _GL_HAVE__STATIC_ASSERT 1
# endif
# if (202311 <= __STDC_VERSION__ \
|| (!defined __STRICT_ANSI__ && 9 <= __GNUC__))
# define _GL_HAVE__STATIC_ASSERT1 1
# endif
#endif
/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
system headers, defines a conflicting _Static_assert that is no
better than ours; override it. */
#ifndef _GL_HAVE_STATIC_ASSERT
#ifndef _GL_HAVE__STATIC_ASSERT
# include <stddef.h>
# undef _Static_assert
#endif
@@ -141,9 +144,9 @@
which do not support _Static_assert, also do not warn about the
last declaration mentioned above.
* GCC warns if -Wnested-externs is enabled and verify() is used
* GCC warns if -Wnested-externs is enabled and 'verify' is used
within a function body; but inside a function, you can always
arrange to use verify_expr() instead.
arrange to use verify_expr instead.
* In C++, any struct definition inside sizeof is invalid.
Use a template type to work around the problem. */
@@ -185,9 +188,9 @@ template <int w>
_gl_verify_type<(R) ? 1 : -1>
#elif defined _GL_HAVE__STATIC_ASSERT
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
struct { \
_Static_assert (R, DIAGNOSTIC); \
int _gl_dummy; \
struct { \
_Static_assert (R, DIAGNOSTIC); \
int _gl_dummy; \
}
#else
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
@@ -195,48 +198,120 @@ template <int w>
#endif
/* Verify requirement R at compile-time, as a declaration without a
trailing ';'. If R is false, fail at compile-time, preferably
with a diagnostic that includes the string-literal DIAGNOSTIC.
trailing ';'. If R is false, fail at compile-time.
This macro requires three or more arguments but uses at most the first
two, so that the _Static_assert macro optionally defined below supports
both the C11 two-argument syntax and the C23 one-argument syntax.
Unfortunately, unlike C11, this implementation must appear as an
ordinary declaration, and cannot appear inside struct { ... }. */
#ifdef _GL_HAVE__STATIC_ASSERT
# define _GL_VERIFY _Static_assert
#if 202311 <= __STDC_VERSION__ || 200410 <= __cpp_static_assert
# define _GL_VERIFY(R, DIAGNOSTIC, ...) static_assert (R, DIAGNOSTIC)
#elif defined _GL_HAVE__STATIC_ASSERT
# define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC)
#else
# define _GL_VERIFY(R, DIAGNOSTIC) \
extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
# define _GL_VERIFY(R, DIAGNOSTIC, ...) \
extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
[_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
# if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
# pragma GCC diagnostic ignored "-Wnested-externs"
# endif
#endif
/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */
#ifdef _GL_STATIC_ASSERT_H
# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert
# define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC)
/* Define _Static_assert if needed. */
/* With clang ≥ 3.8.0 in C++ mode, _Static_assert already works and accepts
1 or 2 arguments. We better don't override it, because clang's standard
C++ library uses static_assert inside classes in several places, and our
replacement via _GL_VERIFY does not work in these contexts. */
# if (defined __cplusplus && defined __clang__ \
&& (4 <= __clang_major__ + (8 <= __clang_minor__)))
# if 5 <= __clang_major__
/* Avoid "warning: 'static_assert' with no message is a C++17 extension". */
# pragma clang diagnostic ignored "-Wc++17-extensions"
# else
/* Avoid "warning: static_assert with no message is a C++1z extension". */
# pragma clang diagnostic ignored "-Wc++1z-extensions"
# endif
# elif !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
# if !defined _MSC_VER || defined __clang__
# define _Static_assert(...) \
_GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
# else
# if defined __cplusplus && _MSC_VER >= 1910
/* In MSVC 14.1 or newer, static_assert accepts one or two arguments,
but _Static_assert is not defined. */
# define _Static_assert static_assert
# else
/* Work around MSVC preprocessor incompatibility with ISO C; see
<https://stackoverflow.com/questions/5134523/>. */
# define _Static_assert(R, ...) \
_GL_VERIFY ((R), "static assertion failed", -)
# endif
# endif
# endif
# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert
# define static_assert _Static_assert /* C11 requires this #define. */
/* Define static_assert if needed. */
# if (!defined static_assert \
&& __STDC_VERSION__ < 202311 \
&& (!defined __cplusplus \
|| (__cpp_static_assert < 201411 \
&& __GNUG__ < 6 && __clang_major__ < 6 && _MSC_VER < 1910)))
# if defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__
/* MSVC 14 in C++ mode supports the two-arguments static_assert but not
the one-argument static_assert, and it does not support _Static_assert.
We have to play preprocessor tricks to distinguish the two cases.
Since the MSVC preprocessor is not ISO C compliant (see above),.
the solution is specific to MSVC. */
# define _GL_EXPAND(x) x
# define _GL_SA1(a1) static_assert ((a1), "static assertion failed")
# define _GL_SA2 static_assert
# define _GL_SA3 static_assert
# define _GL_SA_PICK(x1,x2,x3,x4,...) x4
# define static_assert(...) _GL_EXPAND(_GL_SA_PICK(__VA_ARGS__,_GL_SA3,_GL_SA2,_GL_SA1)) (__VA_ARGS__)
/* Avoid "fatal error C1189: #error: The C++ Standard Library forbids macroizing keywords." */
# define _ALLOW_KEYWORD_MACROS 1
# else
# define static_assert _Static_assert /* C11 requires this #define. */
# endif
# endif
#endif
/* @assert.h omit start@ */
#if defined __clang_major__ && __clang_major__ < 5
# define _GL_HAS_BUILTIN_TRAP 0
#elif 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
# define _GL_HAS_BUILTIN_TRAP 1
#elif defined __has_builtin
# define _GL_HAS_BUILTIN_TRAP __has_builtin (__builtin_trap)
#else
# define _GL_HAS_BUILTIN_TRAP 0
#endif
#ifndef _GL_HAS_BUILTIN_UNREACHABLE
# if defined __clang_major__ && __clang_major__ < 5
# define _GL_HAS_BUILTIN_UNREACHABLE 0
# elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
# define _GL_HAS_BUILTIN_UNREACHABLE 1
# elif defined __has_builtin
# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
# else
# define _GL_HAS_BUILTIN_UNREACHABLE 0
# endif
#endif
/* Each of these macros verifies that its argument R is nonzero. To
be portable, R should be an integer constant expression. Unlike
assert (R), there is no run-time overhead.
There are two macros, since no single macro can be used in all
contexts in C. verify_true (R) is for scalar contexts, including
contexts in C. verify_expr (R, E) is for scalar contexts, including
integer constant expression contexts. verify (R) is for declaration
contexts, e.g., the top level. */
/* Verify requirement R at compile-time, as an integer constant expression.
Return 1. This is equivalent to verify_expr (R, 1).
verify_true is obsolescent; please use verify_expr instead. */
#define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")")
/* Verify requirement R at compile-time. Return the value of the
expression E. */
@@ -244,37 +319,54 @@ template <int w>
(_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
/* Verify requirement R at compile-time, as a declaration without a
trailing ';'. */
trailing ';'. verify (R) acts like static_assert (R) except that
it is portable to C11/C++14 and earlier, it can issue better
diagnostics, and its name is shorter and may be more convenient. */
#ifdef __GNUC__
# define verify(R) _GL_VERIFY (R, "verify (" #R ")")
#ifdef __PGI
/* PGI barfs if R is long. */
# define verify(R) _GL_VERIFY (R, "verify (...)", -)
#else
/* PGI barfs if R is long. Play it safe. */
# define verify(R) _GL_VERIFY (R, "verify (...)")
# define verify(R) _GL_VERIFY (R, "verify (" #R ")", -)
#endif
#ifndef __has_builtin
# define __has_builtin(x) 0
#endif
/* Assume that R always holds. Behavior is undefined if R is false,
fails to evaluate, or has side effects.
/* Assume that R always holds. This lets the compiler optimize
accordingly. R should not have side-effects; it may or may not be
evaluated. Behavior is undefined if R is false. */
'assume (R)' is a directive from the programmer telling the
compiler that R is true so the compiler needn't generate code to
test R. This is why 'assume' is in verify.h: it's related to
static checking (in this case, static checking done by the
programmer), not dynamic checking.
#if (__has_builtin (__builtin_unreachable) \
|| 4 < __GNUC__ + (5 <= __GNUC_MINOR__))
'assume (R)' can affect compilation of all the code, not just code
that happens to be executed after the assume (R) is "executed".
For example, if the code mistakenly does 'assert (R); assume (R);'
the compiler is entitled to optimize away the 'assert (R)'.
Although assuming R can help a compiler generate better code or
diagnostics, performance can suffer if R uses hard-to-optimize
features such as function calls not inlined by the compiler.
Avoid Clang's __builtin_assume, as it breaks GNU Emacs master
as of 2020-08-23T21:09:49Z!eggert@cs.ucla.edu; see
<https://bugs.gnu.org/43152#71>. It's not known whether this breakage
is a Clang bug or an Emacs bug; play it safe for now. */
#if _GL_HAS_BUILTIN_UNREACHABLE
# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
#elif 1200 <= _MSC_VER
# define assume(R) __assume (R)
#elif ((defined GCC_LINT || defined lint) \
&& (__has_builtin (__builtin_trap) \
|| 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))))
#elif 202311 <= __STDC_VERSION__
# include <stddef.h>
# define assume(R) ((R) ? (void) 0 : unreachable ())
#elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP
/* Doing it this way helps various packages when configured with
--enable-gcc-warnings, which compiles with -Dlint. It's nicer
when 'assume' silences warnings even with older GCCs. */
if 'assume' silences warnings with GCC 3.4 through GCC 4.4.7 (2012). */
# define assume(R) ((R) ? (void) 0 : __builtin_trap ())
#else
/* Some tools grok NOTREACHED, e.g., Oracle Studio 12.6. */
/* Some older tools grok NOTREACHED, e.g., Oracle Studio 12.6 (2017). */
# define assume(R) ((R) ? (void) 0 : /*NOTREACHED*/ (void) 0)
#endif

View File

@@ -1,3 +1,23 @@
/* Checked size_t computations.
Copyright (C) 2012-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>
#include "g-gnulib.h"
#define XSIZE_INLINE _GL_EXTERN_INLINE
#include "xsize.h"

View File

@@ -1,42 +1,50 @@
/* xsize.h -- Checked size_t computations.
Copyright (C) 2003, 2008-2019 Free Software Foundation, Inc.
Copyright (C) 2003, 2008-2024 Free Software Foundation, Inc.
This program 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, or (at your option)
any later version.
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 program is distributed in the hope that it will be useful,
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/>. */
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#ifndef _XSIZE_H
#define _XSIZE_H
#include <glib.h>
/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, HAVE_STDINT_H. */
#if !_GL_CONFIG_H_INCLUDED
#error "Please include config.h first."
#endif
/* Get size_t. */
#include <stddef.h>
/* Get G_MAXSIZE. */
/* Get SIZE_MAX. */
#include <limits.h>
#if HAVE_STDINT_H
# include <stdint.h>
#endif
#ifndef _GL_INLINE_HEADER_BEGIN
#error "Please include config.h first."
#endif
/* Get ATTRIBUTE_PURE. */
#include "attribute.h"
_GL_INLINE_HEADER_BEGIN
#ifndef XSIZE_INLINE
# define XSIZE_INLINE _GL_INLINE
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* The size of memory objects is often computed through expressions of
type size_t. Example:
void* p = malloc (header_size + n * element_size).
@@ -44,8 +52,8 @@ _GL_INLINE_HEADER_BEGIN
returns a piece of memory that is way too small, and the program then
crashes while attempting to fill the memory.
To avoid this, the functions and macros in this file check for overflow.
The convention is that G_MAXSIZE represents overflow.
malloc (G_MAXSIZE) is not guaranteed to fail -- think of a malloc
The convention is that SIZE_MAX represents overflow.
malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc
implementation that uses mmap --, it's recommended to use size_overflow_p()
or size_in_bounds_p() before invoking malloc().
The example thus becomes:
@@ -55,64 +63,57 @@ _GL_INLINE_HEADER_BEGIN
/* Convert an arbitrary value >= 0 to type size_t. */
#define xcast_size_t(N) \
((N) <= G_MAXSIZE ? (size_t) (N) : G_MAXSIZE)
((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX)
/* Sum of two sizes, with overflow check. */
XSIZE_INLINE size_t
#if __GNUC__ >= 3
__attribute__ ((__pure__))
#endif
XSIZE_INLINE size_t ATTRIBUTE_PURE
xsum (size_t size1, size_t size2)
{
size_t sum = size1 + size2;
return (sum >= size1 ? sum : G_MAXSIZE);
return (sum >= size1 ? sum : SIZE_MAX);
}
/* Sum of three sizes, with overflow check. */
XSIZE_INLINE size_t
#if __GNUC__ >= 3
__attribute__ ((__pure__))
#endif
XSIZE_INLINE size_t ATTRIBUTE_PURE
xsum3 (size_t size1, size_t size2, size_t size3)
{
return xsum (xsum (size1, size2), size3);
}
/* Sum of four sizes, with overflow check. */
XSIZE_INLINE size_t
#if __GNUC__ >= 3
__attribute__ ((__pure__))
#endif
XSIZE_INLINE size_t ATTRIBUTE_PURE
xsum4 (size_t size1, size_t size2, size_t size3, size_t size4)
{
return xsum (xsum (xsum (size1, size2), size3), size4);
}
/* Maximum of two sizes, with overflow check. */
XSIZE_INLINE size_t
#if __GNUC__ >= 3
__attribute__ ((__pure__))
#endif
XSIZE_INLINE size_t ATTRIBUTE_PURE
xmax (size_t size1, size_t size2)
{
/* No explicit check is needed here, because for any n:
max (G_MAXSIZE, n) == G_MAXSIZE and max (n, G_MAXSIZE) == G_MAXSIZE. */
max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */
return (size1 >= size2 ? size1 : size2);
}
/* Multiplication of a count with an element size, with overflow check.
The count must be >= 0 and the element size must be > 0.
This is a macro, not a function, so that it works correctly even
when N is of a wider type and N > G_MAXSIZE. */
when N is of a wider type and N > SIZE_MAX. */
#define xtimes(N, ELSIZE) \
((N) <= G_MAXSIZE / (ELSIZE) ? (size_t) (N) * (ELSIZE) : G_MAXSIZE)
((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX)
/* Check for overflow. */
#define size_overflow_p(SIZE) \
((SIZE) == G_MAXSIZE)
((SIZE) == SIZE_MAX)
/* Check against overflow. */
#define size_in_bounds_p(SIZE) \
((SIZE) != G_MAXSIZE)
((SIZE) != SIZE_MAX)
#ifdef __cplusplus
}
#endif
_GL_INLINE_HEADER_END