From: Bruno Haible Date: Fri, 3 Jun 2011 09:08:14 +0000 (+0200) Subject: Update from gnulib. X-Git-Tag: v0.18.2~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae65ae49cce2ea129aaef75e8a3d28f8bfd01187;p=thirdparty%2Fgettext.git Update from gnulib. --- diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index dcc87a64b..7f4721093 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,21 @@ +2011-06-03 Bruno Haible + + * wprintf-parse.h: Apply same changes as to printf-parse.h. + +2011-02-04 Bruno Haible + + 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 . + (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 . + 2010-11-20 Bruno Haible Port to uClibc. diff --git a/gettext-runtime/intl/printf-args.h b/gettext-runtime/intl/printf-args.h index f95e6bd9c..39383a685 100644 --- a/gettext-runtime/intl/printf-args.h +++ b/gettext-runtime/intl/printf-args.h @@ -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; diff --git a/gettext-runtime/intl/printf-parse.c b/gettext-runtime/intl/printf-parse.c index 7ae6d8998..7327b26a4 100644 --- a/gettext-runtime/intl/printf-parse.c +++ b/gettext-runtime/intl/printf-parse.c @@ -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 +/* memcpy(). */ +#include + /* errno. */ #include @@ -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; } diff --git a/gettext-runtime/intl/printf-parse.h b/gettext-runtime/intl/printf-parse.h index 12da5577e..0069957a2 100644 --- a/gettext-runtime/intl/printf-parse.h +++ b/gettext-runtime/intl/printf-parse.h @@ -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; diff --git a/gettext-runtime/intl/vasnprintf.c b/gettext-runtime/intl/vasnprintf.c index 1e521c8c5..dcdbec3cb 100644 --- a/gettext-runtime/intl/vasnprintf.c +++ b/gettext-runtime/intl/vasnprintf.c @@ -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) diff --git a/gettext-runtime/intl/wprintf-parse.h b/gettext-runtime/intl/wprintf-parse.h index a08356ed6..4b5f6c00f 100644 --- a/gettext-runtime/intl/wprintf-parse.h +++ b/gettext-runtime/intl/wprintf-parse.h @@ -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 /* 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; diff --git a/gettext-runtime/libasprintf/ChangeLog b/gettext-runtime/libasprintf/ChangeLog index 109fbc7cb..c76f1a24b 100644 --- a/gettext-runtime/libasprintf/ChangeLog +++ b/gettext-runtime/libasprintf/ChangeLog @@ -1,3 +1,17 @@ +2011-02-04 Bruno Haible + + 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 . + (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 . + 2010-11-20 Bruno Haible Ensure that is included before __GLIBC__ is tested. diff --git a/gettext-runtime/libasprintf/printf-args.h b/gettext-runtime/libasprintf/printf-args.h index f95e6bd9c..39383a685 100644 --- a/gettext-runtime/libasprintf/printf-args.h +++ b/gettext-runtime/libasprintf/printf-args.h @@ -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; diff --git a/gettext-runtime/libasprintf/printf-parse.c b/gettext-runtime/libasprintf/printf-parse.c index 7ae6d8998..7327b26a4 100644 --- a/gettext-runtime/libasprintf/printf-parse.c +++ b/gettext-runtime/libasprintf/printf-parse.c @@ -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 +/* memcpy(). */ +#include + /* errno. */ #include @@ -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; } diff --git a/gettext-runtime/libasprintf/printf-parse.h b/gettext-runtime/libasprintf/printf-parse.h index 12da5577e..0069957a2 100644 --- a/gettext-runtime/libasprintf/printf-parse.h +++ b/gettext-runtime/libasprintf/printf-parse.h @@ -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; diff --git a/gettext-runtime/libasprintf/vasnprintf.c b/gettext-runtime/libasprintf/vasnprintf.c index 1e521c8c5..dcdbec3cb 100644 --- a/gettext-runtime/libasprintf/vasnprintf.c +++ b/gettext-runtime/libasprintf/vasnprintf.c @@ -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)