Update from gnulib.

This commit is contained in:
Bruno Haible 2011-06-03 11:08:14 +02:00
parent ff246ee72a
commit ae65ae49cc
11 changed files with 119 additions and 48 deletions

View File

@ -1,3 +1,21 @@
2011-06-03 Bruno Haible <bruno@clisp.org>
* wprintf-parse.h: Apply same changes as to printf-parse.h.
2011-02-04 Bruno Haible <bruno@clisp.org>
vasnprintf: Reduce use of malloc for small format strings.
* printf-args.h (N_DIRECT_ALLOC_ARGUMENTS): New macro.
(arguments): Add room for the first 7 arguments.
* printf-parse.h (N_DIRECT_ALLOC_DIRECTIVES): New macro.
(char_directives, u8_directives, u16_directives, u32_directives): Add
room for the first 7 directives.
* printf-parse.c: Include <string.h>.
(PRINTF_PARSE): Change memory handling code so that it uses the first
7 preallocated elements in an 'arguments' or 'DIRECTIVES' struct.
* vasnprintf.c (VASNPRINTF): Update memory handling code.
Reported by Pádraig Brady <P@draigbrady.com>.
2010-11-20 Bruno Haible <bruno@clisp.org>
Port to uClibc.

View File

@ -1,5 +1,5 @@
/* Decomposed printf argument list.
Copyright (C) 1999, 2002-2003, 2006-2007 Free Software Foundation, Inc.
Copyright (C) 1999, 2002-2003, 2006-2007, 2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@ -136,10 +136,14 @@ typedef struct
}
argument;
/* Number of directly allocated arguments (no malloc() needed). */
#define N_DIRECT_ALLOC_ARGUMENTS 7
typedef struct
{
size_t count;
argument *arg;
argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
}
arguments;

View File

@ -1,5 +1,5 @@
/* Formatted output to strings.
Copyright (C) 1999-2000, 2002-2003, 2006-2008 Free Software Foundation, Inc.
Copyright (C) 1999-2000, 2002-2003, 2006-2008, 2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@ -64,6 +64,9 @@
/* malloc(), realloc(), free(). */
#include <stdlib.h>
/* memcpy(). */
#include <string.h>
/* errno. */
#include <errno.h>
@ -81,23 +84,20 @@ STATIC
int
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
{
const CHAR_T *cp = format; /* pointer into format */
const CHAR_T *cp = format; /* pointer into format */
size_t arg_posn = 0; /* number of regular arguments consumed */
size_t d_allocated; /* allocated elements of d->dir */
size_t a_allocated; /* allocated elements of a->arg */
size_t d_allocated; /* allocated elements of d->dir */
size_t a_allocated; /* allocated elements of a->arg */
size_t max_width_length = 0;
size_t max_precision_length = 0;
d->count = 0;
d_allocated = 1;
d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE));
if (d->dir == NULL)
/* Out of memory. */
goto out_of_memory_1;
d_allocated = N_DIRECT_ALLOC_DIRECTIVES;
d->dir = d->direct_alloc_dir;
a->count = 0;
a_allocated = 0;
a->arg = NULL;
a_allocated = N_DIRECT_ALLOC_ARGUMENTS;
a->arg = a->direct_alloc_arg;
#define REGISTER_ARG(_index_,_type_) \
{ \
@ -114,12 +114,14 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
if (size_overflow_p (memory_size)) \
/* Overflow, would lead to out of memory. */ \
goto out_of_memory; \
memory = (argument *) (a->arg \
memory = (argument *) (a->arg != a->direct_alloc_arg \
? realloc (a->arg, memory_size) \
: malloc (memory_size)); \
if (memory == NULL) \
/* Out of memory. */ \
goto out_of_memory; \
if (a->arg == a->direct_alloc_arg) \
memcpy (memory, a->arg, a->count * sizeof (argument)); \
a->arg = memory; \
} \
while (a->count <= n) \
@ -589,10 +591,14 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
if (size_overflow_p (memory_size))
/* Overflow, would lead to out of memory. */
goto out_of_memory;
memory = (DIRECTIVE *) realloc (d->dir, memory_size);
memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir
? realloc (d->dir, memory_size)
: malloc (memory_size));
if (memory == NULL)
/* Out of memory. */
goto out_of_memory;
if (d->dir == d->direct_alloc_dir)
memcpy (memory, d->dir, d->count * sizeof (DIRECTIVE));
d->dir = memory;
}
}
@ -611,19 +617,18 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
return 0;
error:
if (a->arg)
if (a->arg != a->direct_alloc_arg)
free (a->arg);
if (d->dir)
if (d->dir != d->direct_alloc_dir)
free (d->dir);
errno = EINVAL;
return -1;
out_of_memory:
if (a->arg)
if (a->arg != a->direct_alloc_arg)
free (a->arg);
if (d->dir)
if (d->dir != d->direct_alloc_dir)
free (d->dir);
out_of_memory_1:
errno = ENOMEM;
return -1;
}

View File

@ -1,5 +1,5 @@
/* Parse printf format string.
Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@ -40,6 +40,9 @@
/* arg_index value indicating that no argument is consumed. */
#define ARG_NONE (~(size_t)0)
/* Number of directly allocated directives (no malloc() needed). */
#define N_DIRECT_ALLOC_DIRECTIVES 7
/* A parsed directive. */
typedef struct
{
@ -64,6 +67,7 @@ typedef struct
char_directive *dir;
size_t max_width_length;
size_t max_precision_length;
char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
}
char_directives;

View File

@ -1,5 +1,5 @@
/* vsprintf with automatic memory allocation.
Copyright (C) 1999, 2002-2010 Free Software Foundation, Inc.
Copyright (C) 1999, 2002-2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@ -1752,8 +1752,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
return NULL;
#define CLEANUP() \
free (d.dir); \
if (a.arg) \
if (d.dir != d.direct_alloc_dir) \
free (d.dir); \
if (a.arg != a.direct_alloc_arg) \
free (a.arg);
if (PRINTF_FETCHARGS (args, &a) < 0)

View File

@ -1,5 +1,5 @@
/* Parse printf format string.
Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@ -19,6 +19,10 @@
#ifndef _WPRINTF_PARSE_H
#define _WPRINTF_PARSE_H
#if HAVE_FEATURES_H
# include <features.h> /* for __GLIBC__, __UCLIBC__ */
#endif
#include "printf-args.h"
@ -29,10 +33,16 @@
#define FLAG_SPACE 8 /* space flag */
#define FLAG_ALT 16 /* # flag */
#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)
/* Number of directly allocated directives (no malloc() needed). */
#define N_DIRECT_ALLOC_DIRECTIVES 7
/* A parsed directive. */
typedef struct
{
@ -45,7 +55,7 @@ typedef struct
const wchar_t* precision_start;
const wchar_t* precision_end;
size_t precision_arg_index;
wchar_t conversion; /* d i o u x X f e E g G c s p n U % but not C S */
wchar_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;
}
wchar_t_directive;
@ -57,6 +67,7 @@ typedef struct
wchar_t_directive *dir;
size_t max_width_length;
size_t max_precision_length;
wchar_t_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
}
wchar_t_directives;

View File

@ -1,3 +1,17 @@
2011-02-04 Bruno Haible <bruno@clisp.org>
vasnprintf: Reduce use of malloc for small format strings.
* printf-args.h (N_DIRECT_ALLOC_ARGUMENTS): New macro.
(arguments): Add room for the first 7 arguments.
* printf-parse.h (N_DIRECT_ALLOC_DIRECTIVES): New macro.
(char_directives, u8_directives, u16_directives, u32_directives): Add
room for the first 7 directives.
* printf-parse.c: Include <string.h>.
(PRINTF_PARSE): Change memory handling code so that it uses the first
7 preallocated elements in an 'arguments' or 'DIRECTIVES' struct.
* vasnprintf.c (VASNPRINTF): Update memory handling code.
Reported by Pádraig Brady <P@draigbrady.com>.
2010-11-20 Bruno Haible <bruno@clisp.org>
Ensure that <features.h> is included before __GLIBC__ is tested.

View File

@ -1,5 +1,5 @@
/* Decomposed printf argument list.
Copyright (C) 1999, 2002-2003, 2006-2007 Free Software Foundation, Inc.
Copyright (C) 1999, 2002-2003, 2006-2007, 2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@ -136,10 +136,14 @@ typedef struct
}
argument;
/* Number of directly allocated arguments (no malloc() needed). */
#define N_DIRECT_ALLOC_ARGUMENTS 7
typedef struct
{
size_t count;
argument *arg;
argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
}
arguments;

View File

@ -1,5 +1,5 @@
/* Formatted output to strings.
Copyright (C) 1999-2000, 2002-2003, 2006-2008 Free Software Foundation, Inc.
Copyright (C) 1999-2000, 2002-2003, 2006-2008, 2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@ -64,6 +64,9 @@
/* malloc(), realloc(), free(). */
#include <stdlib.h>
/* memcpy(). */
#include <string.h>
/* errno. */
#include <errno.h>
@ -81,23 +84,20 @@ STATIC
int
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
{
const CHAR_T *cp = format; /* pointer into format */
const CHAR_T *cp = format; /* pointer into format */
size_t arg_posn = 0; /* number of regular arguments consumed */
size_t d_allocated; /* allocated elements of d->dir */
size_t a_allocated; /* allocated elements of a->arg */
size_t d_allocated; /* allocated elements of d->dir */
size_t a_allocated; /* allocated elements of a->arg */
size_t max_width_length = 0;
size_t max_precision_length = 0;
d->count = 0;
d_allocated = 1;
d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE));
if (d->dir == NULL)
/* Out of memory. */
goto out_of_memory_1;
d_allocated = N_DIRECT_ALLOC_DIRECTIVES;
d->dir = d->direct_alloc_dir;
a->count = 0;
a_allocated = 0;
a->arg = NULL;
a_allocated = N_DIRECT_ALLOC_ARGUMENTS;
a->arg = a->direct_alloc_arg;
#define REGISTER_ARG(_index_,_type_) \
{ \
@ -114,12 +114,14 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
if (size_overflow_p (memory_size)) \
/* Overflow, would lead to out of memory. */ \
goto out_of_memory; \
memory = (argument *) (a->arg \
memory = (argument *) (a->arg != a->direct_alloc_arg \
? realloc (a->arg, memory_size) \
: malloc (memory_size)); \
if (memory == NULL) \
/* Out of memory. */ \
goto out_of_memory; \
if (a->arg == a->direct_alloc_arg) \
memcpy (memory, a->arg, a->count * sizeof (argument)); \
a->arg = memory; \
} \
while (a->count <= n) \
@ -589,10 +591,14 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
if (size_overflow_p (memory_size))
/* Overflow, would lead to out of memory. */
goto out_of_memory;
memory = (DIRECTIVE *) realloc (d->dir, memory_size);
memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir
? realloc (d->dir, memory_size)
: malloc (memory_size));
if (memory == NULL)
/* Out of memory. */
goto out_of_memory;
if (d->dir == d->direct_alloc_dir)
memcpy (memory, d->dir, d->count * sizeof (DIRECTIVE));
d->dir = memory;
}
}
@ -611,19 +617,18 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
return 0;
error:
if (a->arg)
if (a->arg != a->direct_alloc_arg)
free (a->arg);
if (d->dir)
if (d->dir != d->direct_alloc_dir)
free (d->dir);
errno = EINVAL;
return -1;
out_of_memory:
if (a->arg)
if (a->arg != a->direct_alloc_arg)
free (a->arg);
if (d->dir)
if (d->dir != d->direct_alloc_dir)
free (d->dir);
out_of_memory_1:
errno = ENOMEM;
return -1;
}

View File

@ -1,5 +1,5 @@
/* Parse printf format string.
Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@ -40,6 +40,9 @@
/* arg_index value indicating that no argument is consumed. */
#define ARG_NONE (~(size_t)0)
/* Number of directly allocated directives (no malloc() needed). */
#define N_DIRECT_ALLOC_DIRECTIVES 7
/* A parsed directive. */
typedef struct
{
@ -64,6 +67,7 @@ typedef struct
char_directive *dir;
size_t max_width_length;
size_t max_precision_length;
char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
}
char_directives;

View File

@ -1,5 +1,5 @@
/* vsprintf with automatic memory allocation.
Copyright (C) 1999, 2002-2010 Free Software Foundation, Inc.
Copyright (C) 1999, 2002-2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
@ -1752,8 +1752,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
return NULL;
#define CLEANUP() \
free (d.dir); \
if (a.arg) \
if (d.dir != d.direct_alloc_dir) \
free (d.dir); \
if (a.arg != a.direct_alloc_arg) \
free (a.arg);
if (PRINTF_FETCHARGS (args, &a) < 0)