mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-01 05:13:06 +02:00
Update gnulib
It updates it to the version c5d07ce91a8ad51591154450442fa4376441fdfa As a difference with upstream we need to ensure: * Include "g-gnulib.h" so the methods get the gnulib namespace. * xsize.h uses G_MAXSIZE instead of SIZE_MAX and the methods are marked as static inline. * Some defines are named different from the ones in glib i.e HAVE_LONG_LONG_INT is HAVE_LONG_LONG All the unit tests pass properly with and without --enable-included-printf. It has also been tested on Windows. https://bugzilla.gnome.org/show_bug.cgi?id=756382
This commit is contained in:
parent
8ece2de964
commit
212e4232e7
@ -21,6 +21,8 @@ libgnulib_la_SOURCES = \
|
|||||||
vasnprintf.h \
|
vasnprintf.h \
|
||||||
printf.c \
|
printf.c \
|
||||||
printf.h \
|
printf.h \
|
||||||
|
verify.h \
|
||||||
|
xsize.h \
|
||||||
g-gnulib.h
|
g-gnulib.h
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,131 +1,189 @@
|
|||||||
/* Decomposed printf argument list.
|
/* Decomposed printf argument list.
|
||||||
Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
|
Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2015 Free Software
|
||||||
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify
|
||||||
under the terms of the GNU Library General Public License as published
|
it under the terms of the GNU General Public License as published by
|
||||||
by the Free Software Foundation; either version 2, or (at your option)
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
any later version.
|
any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
Library General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
You should have received a copy of the GNU General Public License along
|
||||||
License along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
/* This file can be parametrized with the following macros:
|
||||||
|
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
|
||||||
|
PRINTF_FETCHARGS Name of the function to be defined.
|
||||||
|
STATIC Set to 'static' to declare the function static. */
|
||||||
|
|
||||||
|
#ifndef PRINTF_FETCHARGS
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "g-gnulib.h"
|
#include "g-gnulib.h"
|
||||||
|
|
||||||
/* Specification. */
|
/* Specification. */
|
||||||
#include "printf-args.h"
|
#ifndef PRINTF_FETCHARGS
|
||||||
|
# include "printf-args.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef STATIC
|
#ifdef STATIC
|
||||||
STATIC
|
STATIC
|
||||||
#endif
|
#endif
|
||||||
int
|
int
|
||||||
printf_fetchargs (va_list args, arguments *a)
|
PRINTF_FETCHARGS (va_list args, arguments *a)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
size_t i;
|
||||||
argument *ap;
|
argument *ap;
|
||||||
|
|
||||||
for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
|
for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
|
||||||
switch (ap->type)
|
switch (ap->type)
|
||||||
{
|
{
|
||||||
case TYPE_SCHAR:
|
case TYPE_SCHAR:
|
||||||
ap->a.a_schar = va_arg (args, /*signed char*/ int);
|
ap->a.a_schar = va_arg (args, /*signed char*/ int);
|
||||||
break;
|
break;
|
||||||
case TYPE_UCHAR:
|
case TYPE_UCHAR:
|
||||||
ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
|
ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
|
||||||
break;
|
break;
|
||||||
case TYPE_SHORT:
|
case TYPE_SHORT:
|
||||||
ap->a.a_short = va_arg (args, /*short*/ int);
|
ap->a.a_short = va_arg (args, /*short*/ int);
|
||||||
break;
|
break;
|
||||||
case TYPE_USHORT:
|
case TYPE_USHORT:
|
||||||
ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
|
ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
|
||||||
break;
|
break;
|
||||||
case TYPE_INT:
|
case TYPE_INT:
|
||||||
ap->a.a_int = va_arg (args, int);
|
ap->a.a_int = va_arg (args, int);
|
||||||
break;
|
break;
|
||||||
case TYPE_UINT:
|
case TYPE_UINT:
|
||||||
ap->a.a_uint = va_arg (args, unsigned int);
|
ap->a.a_uint = va_arg (args, unsigned int);
|
||||||
break;
|
break;
|
||||||
case TYPE_LONGINT:
|
case TYPE_LONGINT:
|
||||||
ap->a.a_longint = va_arg (args, long int);
|
ap->a.a_longint = va_arg (args, long int);
|
||||||
break;
|
break;
|
||||||
case TYPE_ULONGINT:
|
case TYPE_ULONGINT:
|
||||||
ap->a.a_ulongint = va_arg (args, unsigned long int);
|
ap->a.a_ulongint = va_arg (args, unsigned long int);
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
case TYPE_LONGLONGINT:
|
case TYPE_LONGLONGINT:
|
||||||
ap->a.a_longlongint = va_arg (args, long long int);
|
ap->a.a_longlongint = va_arg (args, long long int);
|
||||||
break;
|
break;
|
||||||
case TYPE_ULONGLONGINT:
|
case TYPE_ULONGLONGINT:
|
||||||
ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
|
ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifdef HAVE_INT64_AND_I64
|
|
||||||
case TYPE_INT64:
|
|
||||||
ap->a.a_int64 = va_arg (args, __int64);
|
|
||||||
break;
|
|
||||||
case TYPE_UINT64:
|
|
||||||
ap->a.a_uint64 = va_arg (args, unsigned __int64);
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
case TYPE_DOUBLE:
|
case TYPE_DOUBLE:
|
||||||
ap->a.a_double = va_arg (args, double);
|
ap->a.a_double = va_arg (args, double);
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_LONG_DOUBLE
|
|
||||||
case TYPE_LONGDOUBLE:
|
case TYPE_LONGDOUBLE:
|
||||||
ap->a.a_longdouble = va_arg (args, long double);
|
ap->a.a_longdouble = va_arg (args, long double);
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case TYPE_CHAR:
|
case TYPE_CHAR:
|
||||||
ap->a.a_char = va_arg (args, int);
|
ap->a.a_char = va_arg (args, int);
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_WINT_T
|
#if HAVE_WINT_T
|
||||||
case TYPE_WIDE_CHAR:
|
case TYPE_WIDE_CHAR:
|
||||||
#ifdef _WIN32
|
/* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
|
||||||
ap->a.a_wide_char = va_arg (args, int);
|
default argument promotions", this is not the case in mingw32,
|
||||||
#else
|
where wint_t is 'unsigned short'. */
|
||||||
ap->a.a_wide_char = va_arg (args, wint_t);
|
ap->a.a_wide_char =
|
||||||
#endif
|
(sizeof (wint_t) < sizeof (int)
|
||||||
break;
|
? (wint_t) va_arg (args, int)
|
||||||
|
: va_arg (args, wint_t));
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
ap->a.a_string = va_arg (args, const char *);
|
ap->a.a_string = va_arg (args, const char *);
|
||||||
break;
|
/* A null pointer is an invalid argument for "%s", but in practice
|
||||||
#ifdef HAVE_WCHAR_T
|
it occurs quite frequently in printf statements that produce
|
||||||
|
debug output. Use a fallback in this case. */
|
||||||
|
if (ap->a.a_string == NULL)
|
||||||
|
ap->a.a_string = "(NULL)";
|
||||||
|
break;
|
||||||
|
#if HAVE_WCHAR_T
|
||||||
case TYPE_WIDE_STRING:
|
case TYPE_WIDE_STRING:
|
||||||
ap->a.a_wide_string = va_arg (args, const wchar_t *);
|
ap->a.a_wide_string = va_arg (args, const wchar_t *);
|
||||||
break;
|
/* A null pointer is an invalid argument for "%ls", but in practice
|
||||||
|
it occurs quite frequently in printf statements that produce
|
||||||
|
debug output. Use a fallback in this case. */
|
||||||
|
if (ap->a.a_wide_string == NULL)
|
||||||
|
{
|
||||||
|
static const wchar_t wide_null_string[] =
|
||||||
|
{
|
||||||
|
(wchar_t)'(',
|
||||||
|
(wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
|
||||||
|
(wchar_t)')',
|
||||||
|
(wchar_t)0
|
||||||
|
};
|
||||||
|
ap->a.a_wide_string = wide_null_string;
|
||||||
|
}
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
case TYPE_POINTER:
|
case TYPE_POINTER:
|
||||||
ap->a.a_pointer = va_arg (args, void *);
|
ap->a.a_pointer = va_arg (args, void *);
|
||||||
break;
|
break;
|
||||||
case TYPE_COUNT_SCHAR_POINTER:
|
case TYPE_COUNT_SCHAR_POINTER:
|
||||||
ap->a.a_count_schar_pointer = va_arg (args, signed char *);
|
ap->a.a_count_schar_pointer = va_arg (args, signed char *);
|
||||||
break;
|
break;
|
||||||
case TYPE_COUNT_SHORT_POINTER:
|
case TYPE_COUNT_SHORT_POINTER:
|
||||||
ap->a.a_count_short_pointer = va_arg (args, short *);
|
ap->a.a_count_short_pointer = va_arg (args, short *);
|
||||||
break;
|
break;
|
||||||
case TYPE_COUNT_INT_POINTER:
|
case TYPE_COUNT_INT_POINTER:
|
||||||
ap->a.a_count_int_pointer = va_arg (args, int *);
|
ap->a.a_count_int_pointer = va_arg (args, int *);
|
||||||
break;
|
break;
|
||||||
case TYPE_COUNT_LONGINT_POINTER:
|
case TYPE_COUNT_LONGINT_POINTER:
|
||||||
ap->a.a_count_longint_pointer = va_arg (args, long int *);
|
ap->a.a_count_longint_pointer = va_arg (args, long int *);
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
case TYPE_COUNT_LONGLONGINT_POINTER:
|
case TYPE_COUNT_LONGLONGINT_POINTER:
|
||||||
ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
|
ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if ENABLE_UNISTDIO
|
||||||
|
/* The unistdio extensions. */
|
||||||
|
case TYPE_U8_STRING:
|
||||||
|
ap->a.a_u8_string = va_arg (args, const uint8_t *);
|
||||||
|
/* A null pointer is an invalid argument for "%U", but in practice
|
||||||
|
it occurs quite frequently in printf statements that produce
|
||||||
|
debug output. Use a fallback in this case. */
|
||||||
|
if (ap->a.a_u8_string == NULL)
|
||||||
|
{
|
||||||
|
static const uint8_t u8_null_string[] =
|
||||||
|
{ '(', 'N', 'U', 'L', 'L', ')', 0 };
|
||||||
|
ap->a.a_u8_string = u8_null_string;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TYPE_U16_STRING:
|
||||||
|
ap->a.a_u16_string = va_arg (args, const uint16_t *);
|
||||||
|
/* A null pointer is an invalid argument for "%lU", but in practice
|
||||||
|
it occurs quite frequently in printf statements that produce
|
||||||
|
debug output. Use a fallback in this case. */
|
||||||
|
if (ap->a.a_u16_string == NULL)
|
||||||
|
{
|
||||||
|
static const uint16_t u16_null_string[] =
|
||||||
|
{ '(', 'N', 'U', 'L', 'L', ')', 0 };
|
||||||
|
ap->a.a_u16_string = u16_null_string;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TYPE_U32_STRING:
|
||||||
|
ap->a.a_u32_string = va_arg (args, const uint32_t *);
|
||||||
|
/* A null pointer is an invalid argument for "%llU", but in practice
|
||||||
|
it occurs quite frequently in printf statements that produce
|
||||||
|
debug output. Use a fallback in this case. */
|
||||||
|
if (ap->a.a_u32_string == NULL)
|
||||||
|
{
|
||||||
|
static const uint32_t u32_null_string[] =
|
||||||
|
{ '(', 'N', 'U', 'L', 'L', ')', 0 };
|
||||||
|
ap->a.a_u32_string = u32_null_string;
|
||||||
|
}
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
/* Unknown type. */
|
/* Unknown type. */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,43 @@
|
|||||||
/* Decomposed printf argument list.
|
/* Decomposed printf argument list.
|
||||||
Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
|
Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2015 Free Software
|
||||||
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify
|
||||||
under the terms of the GNU Library General Public License as published
|
it under the terms of the GNU General Public License as published by
|
||||||
by the Free Software Foundation; either version 2, or (at your option)
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
any later version.
|
any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
Library General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
You should have received a copy of the GNU General Public License along
|
||||||
License along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _PRINTF_ARGS_H
|
#ifndef _PRINTF_ARGS_H
|
||||||
#define _PRINTF_ARGS_H
|
#define _PRINTF_ARGS_H
|
||||||
|
|
||||||
|
/* This file can be parametrized with the following macros:
|
||||||
|
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
|
||||||
|
PRINTF_FETCHARGS Name of the function to be declared.
|
||||||
|
STATIC Set to 'static' to declare the function static. */
|
||||||
|
|
||||||
|
/* Default parameters. */
|
||||||
|
#ifndef PRINTF_FETCHARGS
|
||||||
|
# define PRINTF_FETCHARGS printf_fetchargs
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Get size_t. */
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
/* Get wchar_t. */
|
/* Get wchar_t. */
|
||||||
#ifdef HAVE_WCHAR_T
|
#if HAVE_WCHAR_T
|
||||||
# include <stddef.h>
|
# include <stddef.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Get wint_t. */
|
/* Get wint_t. */
|
||||||
#ifdef HAVE_WINT_T
|
#if HAVE_WINT_T
|
||||||
# include <wchar.h>
|
# include <wchar.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -43,24 +57,18 @@ typedef enum
|
|||||||
TYPE_UINT,
|
TYPE_UINT,
|
||||||
TYPE_LONGINT,
|
TYPE_LONGINT,
|
||||||
TYPE_ULONGINT,
|
TYPE_ULONGINT,
|
||||||
#ifdef HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
TYPE_LONGLONGINT,
|
TYPE_LONGLONGINT,
|
||||||
TYPE_ULONGLONGINT,
|
TYPE_ULONGLONGINT,
|
||||||
#endif
|
|
||||||
#ifdef HAVE_INT64_AND_I64
|
|
||||||
TYPE_INT64,
|
|
||||||
TYPE_UINT64,
|
|
||||||
#endif
|
#endif
|
||||||
TYPE_DOUBLE,
|
TYPE_DOUBLE,
|
||||||
#ifdef HAVE_LONG_DOUBLE
|
|
||||||
TYPE_LONGDOUBLE,
|
TYPE_LONGDOUBLE,
|
||||||
#endif
|
|
||||||
TYPE_CHAR,
|
TYPE_CHAR,
|
||||||
#ifdef HAVE_WINT_T
|
#if HAVE_WINT_T
|
||||||
TYPE_WIDE_CHAR,
|
TYPE_WIDE_CHAR,
|
||||||
#endif
|
#endif
|
||||||
TYPE_STRING,
|
TYPE_STRING,
|
||||||
#ifdef HAVE_WCHAR_T
|
#if HAVE_WCHAR_T
|
||||||
TYPE_WIDE_STRING,
|
TYPE_WIDE_STRING,
|
||||||
#endif
|
#endif
|
||||||
TYPE_POINTER,
|
TYPE_POINTER,
|
||||||
@ -68,9 +76,15 @@ typedef enum
|
|||||||
TYPE_COUNT_SHORT_POINTER,
|
TYPE_COUNT_SHORT_POINTER,
|
||||||
TYPE_COUNT_INT_POINTER,
|
TYPE_COUNT_INT_POINTER,
|
||||||
TYPE_COUNT_LONGINT_POINTER
|
TYPE_COUNT_LONGINT_POINTER
|
||||||
#ifdef HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
, TYPE_COUNT_LONGLONGINT_POINTER
|
, TYPE_COUNT_LONGLONGINT_POINTER
|
||||||
#endif
|
#endif
|
||||||
|
#if ENABLE_UNISTDIO
|
||||||
|
/* The unistdio extensions. */
|
||||||
|
, TYPE_U8_STRING
|
||||||
|
, TYPE_U16_STRING
|
||||||
|
, TYPE_U32_STRING
|
||||||
|
#endif
|
||||||
} arg_type;
|
} arg_type;
|
||||||
|
|
||||||
/* Polymorphic argument */
|
/* Polymorphic argument */
|
||||||
@ -79,52 +93,56 @@ typedef struct
|
|||||||
arg_type type;
|
arg_type type;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
signed char a_schar;
|
signed char a_schar;
|
||||||
unsigned char a_uchar;
|
unsigned char a_uchar;
|
||||||
short a_short;
|
short a_short;
|
||||||
unsigned short a_ushort;
|
unsigned short a_ushort;
|
||||||
int a_int;
|
int a_int;
|
||||||
unsigned int a_uint;
|
unsigned int a_uint;
|
||||||
long int a_longint;
|
long int a_longint;
|
||||||
unsigned long int a_ulongint;
|
unsigned long int a_ulongint;
|
||||||
#ifdef HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
long long int a_longlongint;
|
long long int a_longlongint;
|
||||||
unsigned long long int a_ulonglongint;
|
unsigned long long int a_ulonglongint;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_INT64_AND_I64
|
float a_float;
|
||||||
__int64 a_int64;
|
double a_double;
|
||||||
unsigned __int64 a_uint64;
|
long double a_longdouble;
|
||||||
|
int a_char;
|
||||||
|
#if HAVE_WINT_T
|
||||||
|
wint_t a_wide_char;
|
||||||
#endif
|
#endif
|
||||||
float a_float;
|
const char* a_string;
|
||||||
double a_double;
|
#if HAVE_WCHAR_T
|
||||||
#ifdef HAVE_LONG_DOUBLE
|
const wchar_t* a_wide_string;
|
||||||
long double a_longdouble;
|
|
||||||
#endif
|
#endif
|
||||||
int a_char;
|
void* a_pointer;
|
||||||
#ifdef HAVE_WINT_T
|
signed char * a_count_schar_pointer;
|
||||||
wint_t a_wide_char;
|
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
|
#endif
|
||||||
const char* a_string;
|
#if ENABLE_UNISTDIO
|
||||||
#ifdef HAVE_WCHAR_T
|
/* The unistdio extensions. */
|
||||||
const wchar_t* a_wide_string;
|
const uint8_t * a_u8_string;
|
||||||
#endif
|
const uint16_t * a_u16_string;
|
||||||
void* a_pointer;
|
const uint32_t * a_u32_string;
|
||||||
signed char * a_count_schar_pointer;
|
|
||||||
short * a_count_short_pointer;
|
|
||||||
int * a_count_int_pointer;
|
|
||||||
long int * a_count_longint_pointer;
|
|
||||||
#ifdef HAVE_LONG_LONG
|
|
||||||
long long int * a_count_longlongint_pointer;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
a;
|
a;
|
||||||
}
|
}
|
||||||
argument;
|
argument;
|
||||||
|
|
||||||
|
/* Number of directly allocated arguments (no malloc() needed). */
|
||||||
|
#define N_DIRECT_ALLOC_ARGUMENTS 7
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned int count;
|
size_t count;
|
||||||
argument *arg;
|
argument *arg;
|
||||||
|
argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
|
||||||
}
|
}
|
||||||
arguments;
|
arguments;
|
||||||
|
|
||||||
@ -135,6 +153,6 @@ STATIC
|
|||||||
#else
|
#else
|
||||||
extern
|
extern
|
||||||
#endif
|
#endif
|
||||||
int printf_fetchargs (va_list args, arguments *a);
|
int PRINTF_FETCHARGS (va_list args, arguments *a);
|
||||||
|
|
||||||
#endif /* _PRINTF_ARGS_H */
|
#endif /* _PRINTF_ARGS_H */
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,34 +1,53 @@
|
|||||||
/* Parse printf format string.
|
/* Parse printf format string.
|
||||||
Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2015 Free Software
|
||||||
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify
|
||||||
under the terms of the GNU Library General Public License as published
|
it under the terms of the GNU General Public License as published by
|
||||||
by the Free Software Foundation; either version 2, or (at your option)
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
any later version.
|
any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
Library General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
You should have received a copy of the GNU General Public License along
|
||||||
License along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _PRINTF_PARSE_H
|
#ifndef _PRINTF_PARSE_H
|
||||||
#define _PRINTF_PARSE_H
|
#define _PRINTF_PARSE_H
|
||||||
|
|
||||||
|
/* This file can be parametrized with the following macros:
|
||||||
|
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
|
||||||
|
STATIC Set to 'static' to declare the function static. */
|
||||||
|
|
||||||
|
#if HAVE_FEATURES_H
|
||||||
|
# include <features.h> /* for __GLIBC__, __UCLIBC__ */
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "printf-args.h"
|
#include "printf-args.h"
|
||||||
|
|
||||||
/* Private namespace for gnulib functions */
|
|
||||||
#define printf_parse _g_gnulib_printf_parse
|
|
||||||
|
|
||||||
/* Flags */
|
/* Flags */
|
||||||
#define FLAG_GROUP 1 /* ' flag */
|
#define FLAG_GROUP 1 /* ' flag */
|
||||||
#define FLAG_LEFT 2 /* - flag */
|
#define FLAG_LEFT 2 /* - flag */
|
||||||
#define FLAG_SHOWSIGN 4 /* + flag */
|
#define FLAG_SHOWSIGN 4 /* + flag */
|
||||||
#define FLAG_SPACE 8 /* space flag */
|
#define FLAG_SPACE 8 /* space flag */
|
||||||
#define FLAG_ALT 16 /* # flag */
|
#define FLAG_ALT 16 /* # flag */
|
||||||
#define FLAG_ZERO 32
|
#define FLAG_ZERO 32
|
||||||
|
#if __GLIBC__ >= 2 && !defined __UCLIBC__
|
||||||
|
# define FLAG_LOCALIZED 64 /* I flag, uses localized digits */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* arg_index value indicating that no argument is consumed. */
|
||||||
|
#define ARG_NONE (~(size_t)0)
|
||||||
|
|
||||||
|
/* xxx_directive: A parsed directive.
|
||||||
|
xxx_directives: A parsed format string. */
|
||||||
|
|
||||||
|
/* Number of directly allocated directives (no malloc() needed). */
|
||||||
|
#define N_DIRECT_ALLOC_DIRECTIVES 7
|
||||||
|
|
||||||
/* A parsed directive. */
|
/* A parsed directive. */
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -38,35 +57,137 @@ typedef struct
|
|||||||
int flags;
|
int flags;
|
||||||
const char* width_start;
|
const char* width_start;
|
||||||
const char* width_end;
|
const char* width_end;
|
||||||
int width_arg_index;
|
size_t width_arg_index;
|
||||||
const char* precision_start;
|
const char* precision_start;
|
||||||
const char* precision_end;
|
const char* precision_end;
|
||||||
int precision_arg_index;
|
size_t precision_arg_index;
|
||||||
char conversion; /* d i o u x X f e E g G c s p n U % but not C S */
|
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 */
|
||||||
int arg_index;
|
size_t arg_index;
|
||||||
}
|
}
|
||||||
char_directive;
|
char_directive;
|
||||||
|
|
||||||
/* A parsed format string. */
|
/* A parsed format string. */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned int count;
|
size_t count;
|
||||||
char_directive *dir;
|
char_directive *dir;
|
||||||
unsigned int max_width_length;
|
size_t max_width_length;
|
||||||
unsigned int max_precision_length;
|
size_t max_precision_length;
|
||||||
|
char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
|
||||||
}
|
}
|
||||||
char_directives;
|
char_directives;
|
||||||
|
|
||||||
|
#if ENABLE_UNISTDIO
|
||||||
|
|
||||||
|
/* A parsed directive. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
const uint8_t* dir_start;
|
||||||
|
const uint8_t* dir_end;
|
||||||
|
int flags;
|
||||||
|
const uint8_t* width_start;
|
||||||
|
const uint8_t* width_end;
|
||||||
|
size_t width_arg_index;
|
||||||
|
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 */
|
||||||
|
size_t arg_index;
|
||||||
|
}
|
||||||
|
u8_directive;
|
||||||
|
|
||||||
|
/* A parsed format string. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
size_t count;
|
||||||
|
u8_directive *dir;
|
||||||
|
size_t max_width_length;
|
||||||
|
size_t max_precision_length;
|
||||||
|
u8_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
|
||||||
|
}
|
||||||
|
u8_directives;
|
||||||
|
|
||||||
|
/* A parsed directive. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
const uint16_t* dir_start;
|
||||||
|
const uint16_t* dir_end;
|
||||||
|
int flags;
|
||||||
|
const uint16_t* width_start;
|
||||||
|
const uint16_t* width_end;
|
||||||
|
size_t width_arg_index;
|
||||||
|
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 */
|
||||||
|
size_t arg_index;
|
||||||
|
}
|
||||||
|
u16_directive;
|
||||||
|
|
||||||
|
/* A parsed format string. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
size_t count;
|
||||||
|
u16_directive *dir;
|
||||||
|
size_t max_width_length;
|
||||||
|
size_t max_precision_length;
|
||||||
|
u16_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
|
||||||
|
}
|
||||||
|
u16_directives;
|
||||||
|
|
||||||
|
/* A parsed directive. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
const uint32_t* dir_start;
|
||||||
|
const uint32_t* dir_end;
|
||||||
|
int flags;
|
||||||
|
const uint32_t* width_start;
|
||||||
|
const uint32_t* width_end;
|
||||||
|
size_t width_arg_index;
|
||||||
|
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 */
|
||||||
|
size_t arg_index;
|
||||||
|
}
|
||||||
|
u32_directive;
|
||||||
|
|
||||||
|
/* A parsed format string. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
size_t count;
|
||||||
|
u32_directive *dir;
|
||||||
|
size_t max_width_length;
|
||||||
|
size_t max_precision_length;
|
||||||
|
u32_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
|
||||||
|
}
|
||||||
|
u32_directives;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Parses the format string. Fills in the number N of directives, and fills
|
/* Parses the format string. Fills in the number N of directives, and fills
|
||||||
in directives[0], ..., directives[N-1], and sets directives[N].dir_start
|
in directives[0], ..., directives[N-1], and sets directives[N].dir_start
|
||||||
to the end of the format string. Also fills in the arg_type fields of the
|
to the end of the format string. Also fills in the arg_type fields of the
|
||||||
arguments and the needed count of arguments. */
|
arguments and the needed count of arguments. */
|
||||||
#ifdef STATIC
|
#if ENABLE_UNISTDIO
|
||||||
STATIC
|
extern int
|
||||||
|
ulc_printf_parse (const char *format, char_directives *d, arguments *a);
|
||||||
|
extern int
|
||||||
|
u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
|
||||||
|
extern int
|
||||||
|
u16_printf_parse (const uint16_t *format, u16_directives *d,
|
||||||
|
arguments *a);
|
||||||
|
extern int
|
||||||
|
u32_printf_parse (const uint32_t *format, u32_directives *d,
|
||||||
|
arguments *a);
|
||||||
#else
|
#else
|
||||||
|
# ifdef STATIC
|
||||||
|
STATIC
|
||||||
|
# else
|
||||||
extern
|
extern
|
||||||
#endif
|
# endif
|
||||||
int printf_parse (const char *format, char_directives *d, arguments *a);
|
int printf_parse (const char *format, char_directives *d, arguments *a);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _PRINTF_PARSE_H */
|
#endif /* _PRINTF_PARSE_H */
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,18 +1,18 @@
|
|||||||
/* vsprintf with automatic memory allocation.
|
/* vsprintf with automatic memory allocation.
|
||||||
Copyright (C) 2002-2003 Free Software Foundation, Inc.
|
Copyright (C) 2002-2004, 2007-2015 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify
|
||||||
under the terms of the GNU Library General Public License as published
|
it under the terms of the GNU General Public License as published by
|
||||||
by the Free Software Foundation; either version 2, or (at your option)
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
any later version.
|
any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
Library General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
You should have received a copy of the GNU General Public License along
|
||||||
License along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _VASNPRINTF_H
|
#ifndef _VASNPRINTF_H
|
||||||
#define _VASNPRINTF_H
|
#define _VASNPRINTF_H
|
||||||
@ -23,20 +23,19 @@
|
|||||||
/* Get size_t. */
|
/* Get size_t. */
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifndef __attribute__
|
/* The __attribute__ feature is available in gcc versions 2.5 and later.
|
||||||
/* This feature is available in gcc versions 2.5 and later. */
|
The __-protected variants of the attributes 'format' and 'printf' are
|
||||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
|
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
|
||||||
# define __attribute__(Spec) /* empty */
|
We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
|
||||||
# endif
|
gnulib and libintl do '#define printf __printf__' when they override
|
||||||
/* The __-protected variants of `format' and `printf' attributes
|
the 'printf' function. */
|
||||||
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
|
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
|
||||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
|
||||||
# define __format__ format
|
#else
|
||||||
# define __printf__ printf
|
# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -46,13 +45,34 @@ extern "C" {
|
|||||||
If successful, return the address of the string (this may be = RESULTBUF
|
If successful, return the address of the string (this may be = RESULTBUF
|
||||||
if no dynamic memory allocation was necessary) and set *LENGTHP to the
|
if no dynamic memory allocation was necessary) and set *LENGTHP to the
|
||||||
number of resulting bytes, excluding the trailing NUL. Upon error, set
|
number of resulting bytes, excluding the trailing NUL. Upon error, set
|
||||||
errno and return NULL. */
|
errno and return NULL.
|
||||||
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
|
|
||||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
|
||||||
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
|
|
||||||
__attribute__ ((__format__ (__printf__, 3, 0)));
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
When dynamic memory allocation occurs, the preallocated buffer is left
|
||||||
|
alone (with possibly modified contents). This makes it possible to use
|
||||||
|
a statically allocated or stack-allocated buffer, like this:
|
||||||
|
|
||||||
|
char buf[100];
|
||||||
|
size_t len = sizeof (buf);
|
||||||
|
char *output = vasnprintf (buf, &len, format, args);
|
||||||
|
if (output == NULL)
|
||||||
|
... error handling ...;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
... use the output string ...;
|
||||||
|
if (output != buf)
|
||||||
|
free (output);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#if REPLACE_VASNPRINTF
|
||||||
|
# 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));
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
279
glib/gnulib/verify.h
Normal file
279
glib/gnulib/verify.h
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
/* Compile-time assert-like macros.
|
||||||
|
|
||||||
|
Copyright (C) 2005-2006, 2009-2015 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
|
||||||
|
|
||||||
|
#ifndef _GL_VERIFY_H
|
||||||
|
#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 works as per C++11.
|
||||||
|
This will likely be supported by future GCC versions, in C++ mode.
|
||||||
|
|
||||||
|
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
|
||||||
|
/* The condition (99 < __GNUC__) is temporary, until we know about the
|
||||||
|
first G++ release that supports static_assert. */
|
||||||
|
#if (99 < __GNUC__) && defined __cplusplus
|
||||||
|
# define _GL_HAVE_STATIC_ASSERT 1
|
||||||
|
#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
|
||||||
|
# include <stddef.h>
|
||||||
|
# undef _Static_assert
|
||||||
|
#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.
|
||||||
|
|
||||||
|
If _Static_assert works, verify (R) uses it directly. Similarly,
|
||||||
|
_GL_VERIFY_TRUE works by packaging a _Static_assert inside a struct
|
||||||
|
that is an operand of sizeof.
|
||||||
|
|
||||||
|
The code below uses several ideas for C++ compilers, and for C
|
||||||
|
compilers that do not support _Static_assert:
|
||||||
|
|
||||||
|
* The first step is ((R) ? 1 : -1). Given an expression R, of
|
||||||
|
integral or boolean or floating-point type, this yields an
|
||||||
|
expression of integral type, whose value is later verified to be
|
||||||
|
constant and nonnegative.
|
||||||
|
|
||||||
|
* Next this expression W is wrapped in a type
|
||||||
|
struct _gl_verify_type {
|
||||||
|
unsigned int _gl_verify_error_if_negative: W;
|
||||||
|
}.
|
||||||
|
If W is negative, this yields a compile-time error. No compiler can
|
||||||
|
deal with a bit-field of negative size.
|
||||||
|
|
||||||
|
One might think that an array size check would have the same
|
||||||
|
effect, that is, that the type struct { unsigned int dummy[W]; }
|
||||||
|
would work as well. However, inside a function, some compilers
|
||||||
|
(such as C++ compilers and GNU C) allow local parameters and
|
||||||
|
variables inside array size expressions. With these compilers,
|
||||||
|
an array size check would not properly diagnose this misuse of
|
||||||
|
the verify macro:
|
||||||
|
|
||||||
|
void function (int n) { verify (n < 0); }
|
||||||
|
|
||||||
|
* For the verify macro, the struct _gl_verify_type will need to
|
||||||
|
somehow be embedded into a declaration. To be portable, this
|
||||||
|
declaration must declare an object, a constant, a function, or a
|
||||||
|
typedef name. If the declared entity uses the type directly,
|
||||||
|
such as in
|
||||||
|
|
||||||
|
struct dummy {...};
|
||||||
|
typedef struct {...} dummy;
|
||||||
|
extern struct {...} *dummy;
|
||||||
|
extern void dummy (struct {...} *);
|
||||||
|
extern struct {...} *dummy (void);
|
||||||
|
|
||||||
|
two uses of the verify macro would yield colliding declarations
|
||||||
|
if the entity names are not disambiguated. A workaround is to
|
||||||
|
attach the current line number to the entity name:
|
||||||
|
|
||||||
|
#define _GL_CONCAT0(x, y) x##y
|
||||||
|
#define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
|
||||||
|
extern struct {...} * _GL_CONCAT (dummy, __LINE__);
|
||||||
|
|
||||||
|
But this has the problem that two invocations of verify from
|
||||||
|
within the same macro would collide, since the __LINE__ value
|
||||||
|
would be the same for both invocations. (The GCC __COUNTER__
|
||||||
|
macro solves this problem, but is not portable.)
|
||||||
|
|
||||||
|
A solution is to use the sizeof operator. It yields a number,
|
||||||
|
getting rid of the identity of the type. Declarations like
|
||||||
|
|
||||||
|
extern int dummy [sizeof (struct {...})];
|
||||||
|
extern void dummy (int [sizeof (struct {...})]);
|
||||||
|
extern int (*dummy (void)) [sizeof (struct {...})];
|
||||||
|
|
||||||
|
can be repeated.
|
||||||
|
|
||||||
|
* Should the implementation use a named struct or an unnamed struct?
|
||||||
|
Which of the following alternatives can be used?
|
||||||
|
|
||||||
|
extern int dummy [sizeof (struct {...})];
|
||||||
|
extern int dummy [sizeof (struct _gl_verify_type {...})];
|
||||||
|
extern void dummy (int [sizeof (struct {...})]);
|
||||||
|
extern void dummy (int [sizeof (struct _gl_verify_type {...})]);
|
||||||
|
extern int (*dummy (void)) [sizeof (struct {...})];
|
||||||
|
extern int (*dummy (void)) [sizeof (struct _gl_verify_type {...})];
|
||||||
|
|
||||||
|
In the second and sixth case, the struct type is exported to the
|
||||||
|
outer scope; two such declarations therefore collide. GCC warns
|
||||||
|
about the first, third, and fourth cases. So the only remaining
|
||||||
|
possibility is the fifth case:
|
||||||
|
|
||||||
|
extern int (*dummy (void)) [sizeof (struct {...})];
|
||||||
|
|
||||||
|
* GCC warns about duplicate declarations of the dummy function if
|
||||||
|
-Wredundant-decls is used. GCC 4.3 and later have a builtin
|
||||||
|
__COUNTER__ macro that can let us generate unique identifiers for
|
||||||
|
each dummy function, to suppress this warning.
|
||||||
|
|
||||||
|
* This implementation exploits the fact that older versions of GCC,
|
||||||
|
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
|
||||||
|
within a function body; but inside a function, you can always
|
||||||
|
arrange to use verify_expr() instead.
|
||||||
|
|
||||||
|
* In C++, any struct definition inside sizeof is invalid.
|
||||||
|
Use a template type to work around the problem. */
|
||||||
|
|
||||||
|
/* Concatenate two preprocessor tokens. */
|
||||||
|
#define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
|
||||||
|
#define _GL_CONCAT0(x, y) x##y
|
||||||
|
|
||||||
|
/* _GL_COUNTER is an integer, preferably one that changes each time we
|
||||||
|
use it. Use __COUNTER__ if it works, falling back on __LINE__
|
||||||
|
otherwise. __LINE__ isn't perfect, but it's better than a
|
||||||
|
constant. */
|
||||||
|
#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
|
||||||
|
# define _GL_COUNTER __COUNTER__
|
||||||
|
#else
|
||||||
|
# define _GL_COUNTER __LINE__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Generate a symbol with the given prefix, making it unique if
|
||||||
|
possible. */
|
||||||
|
#define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
|
||||||
|
|
||||||
|
/* Verify requirement R at compile-time, as an integer constant expression
|
||||||
|
that returns 1. If R is false, fail at compile-time, preferably
|
||||||
|
with a diagnostic that includes the string-literal DIAGNOSTIC. */
|
||||||
|
|
||||||
|
#define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
|
||||||
|
(!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC)))
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
# if !GNULIB_defined_struct__gl_verify_type
|
||||||
|
template <int w>
|
||||||
|
struct _gl_verify_type {
|
||||||
|
unsigned int _gl_verify_error_if_negative: w;
|
||||||
|
};
|
||||||
|
# define GNULIB_defined_struct__gl_verify_type 1
|
||||||
|
# endif
|
||||||
|
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
|
||||||
|
_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; \
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
|
||||||
|
struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; }
|
||||||
|
#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.
|
||||||
|
|
||||||
|
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
|
||||||
|
#else
|
||||||
|
# define _GL_VERIFY(R, DIAGNOSTIC) \
|
||||||
|
extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
|
||||||
|
[_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
|
||||||
|
#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)
|
||||||
|
# endif
|
||||||
|
# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert
|
||||||
|
# define static_assert _Static_assert /* C11 requires this #define. */
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* @assert.h omit start@ */
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
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. */
|
||||||
|
|
||||||
|
#define verify_expr(R, E) \
|
||||||
|
(_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
|
||||||
|
|
||||||
|
/* Verify requirement R at compile-time, as a declaration without a
|
||||||
|
trailing ';'. */
|
||||||
|
|
||||||
|
#define verify(R) _GL_VERIFY (R, "verify (" #R ")")
|
||||||
|
|
||||||
|
#ifndef __has_builtin
|
||||||
|
# define __has_builtin(x) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* 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. */
|
||||||
|
|
||||||
|
#if (__has_builtin (__builtin_unreachable) \
|
||||||
|
|| 4 < __GNUC__ + (5 <= __GNUC_MINOR__))
|
||||||
|
# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
|
||||||
|
#elif 1200 <= _MSC_VER
|
||||||
|
# define assume(R) __assume (R)
|
||||||
|
#elif (defined lint \
|
||||||
|
&& (__has_builtin (__builtin_trap) \
|
||||||
|
|| 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))))
|
||||||
|
/* 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. */
|
||||||
|
# define assume(R) ((R) ? (void) 0 : __builtin_trap ())
|
||||||
|
#else
|
||||||
|
# define assume(R) ((void) (0 && (R)))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* @assert.h omit end@ */
|
||||||
|
|
||||||
|
#endif
|
101
glib/gnulib/xsize.h
Normal file
101
glib/gnulib/xsize.h
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/* xsize.h -- Checked size_t computations.
|
||||||
|
|
||||||
|
Copyright (C) 2003, 2008-2015 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifndef _XSIZE_H
|
||||||
|
#define _XSIZE_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
/* Get size_t. */
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/* Get G_MAXSIZE. */
|
||||||
|
#include <limits.h>
|
||||||
|
#if HAVE_STDINT_H
|
||||||
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef XSIZE_INLINE
|
||||||
|
# define XSIZE_INLINE _GL_INLINE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The size of memory objects is often computed through expressions of
|
||||||
|
type size_t. Example:
|
||||||
|
void* p = malloc (header_size + n * element_size).
|
||||||
|
These computations can lead to overflow. When this happens, malloc()
|
||||||
|
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
|
||||||
|
implementation that uses mmap --, it's recommended to use size_overflow_p()
|
||||||
|
or size_in_bounds_p() before invoking malloc().
|
||||||
|
The example thus becomes:
|
||||||
|
size_t size = xsum (header_size, xtimes (n, element_size));
|
||||||
|
void *p = (size_in_bounds_p (size) ? malloc (size) : NULL);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Convert an arbitrary value >= 0 to type size_t. */
|
||||||
|
#define xcast_size_t(N) \
|
||||||
|
((N) <= G_MAXSIZE ? (size_t) (N) : G_MAXSIZE)
|
||||||
|
|
||||||
|
/* Sum of two sizes, with overflow check. */
|
||||||
|
static inline size_t
|
||||||
|
xsum (size_t size1, size_t size2)
|
||||||
|
{
|
||||||
|
size_t sum = size1 + size2;
|
||||||
|
return (sum >= size1 ? sum : G_MAXSIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sum of three sizes, with overflow check. */
|
||||||
|
static inline size_t
|
||||||
|
xsum3 (size_t size1, size_t size2, size_t size3)
|
||||||
|
{
|
||||||
|
return xsum (xsum (size1, size2), size3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sum of four sizes, with overflow check. */
|
||||||
|
static inline size_t
|
||||||
|
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. */
|
||||||
|
static inline size_t
|
||||||
|
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. */
|
||||||
|
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. */
|
||||||
|
#define xtimes(N, ELSIZE) \
|
||||||
|
((N) <= G_MAXSIZE / (ELSIZE) ? (size_t) (N) * (ELSIZE) : G_MAXSIZE)
|
||||||
|
|
||||||
|
/* Check for overflow. */
|
||||||
|
#define size_overflow_p(SIZE) \
|
||||||
|
((SIZE) == G_MAXSIZE)
|
||||||
|
/* Check against overflow. */
|
||||||
|
#define size_in_bounds_p(SIZE) \
|
||||||
|
((SIZE) != G_MAXSIZE)
|
||||||
|
|
||||||
|
#endif /* _XSIZE_H */
|
Loading…
x
Reference in New Issue
Block a user