This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
intl patches (11)
- To: libc-alpha at sources dot redhat dot com
- Subject: intl patches (11)
- From: Bruno Haible <haible at ilog dot fr>
- Date: Mon, 19 Mar 2001 20:35:51 +0100 (CET)
This patch deals with alloca handling on platforms that don't have it.
- Simplifies localealias.c, it has a single alloca() call.
- Avoid memory leak by freeing the 'charset' allocated for iconv_open.
This patch has no effect inside glibc.
2001-01-05 Bruno Haible <haible@clisp.cons.org>
* intl/loadmsgcat.c: Include headers needed for alloca().
(freea): New macro.
(_nl_load_domain): Add fallback code for platforms lacking alloca.
* intl/localealias.c: (ADD_BLOCK, FREE_BLOCK): Remove macros.
(freea): New macro.
(read_alias_file): Simplify fallback code for platforms lacking
alloca.
diff -r -c3 intl/loadmsgcat.c intl-98/loadmsgcat.c
*** intl/loadmsgcat.c Sat Mar 17 18:53:53 2001
--- intl/loadmsgcat.c Sat Mar 17 14:52:33 2001
***************
*** 33,38 ****
--- 33,55 ----
#include <sys/types.h>
#include <sys/stat.h>
+ #ifdef __GNUC__
+ # define alloca __builtin_alloca
+ # define HAVE_ALLOCA 1
+ #else
+ # if defined HAVE_ALLOCA_H || defined _LIBC
+ # include <alloca.h>
+ # else
+ # ifdef _AIX
+ #pragma alloca
+ # else
+ # ifndef alloca
+ char *alloca ();
+ # endif
+ # endif
+ # endif
+ #endif
+
#if defined STDC_HEADERS || defined _LIBC
# include <stdlib.h>
#endif
***************
*** 91,96 ****
--- 108,122 ----
# define PLURAL_PARSE gettextparse__
#endif
+ /* For those losing systems which don't have `alloca' we have to add
+ some additional code emulating it. */
+ #ifdef HAVE_ALLOCA
+ # define freea(p) /* nothing */
+ #else
+ # define alloca(n) malloc (n)
+ # define freea(p) free (p)
+ #endif
+
/* We need a sign, whether a new catalog was loaded, which can be associated
with all translations. This is important if the translations are
cached by one of GCC's features. */
***************
*** 373,378 ****
--- 423,430 ----
domain->conv = iconv_open (outcharset, charset);
# endif
# endif
+
+ freea (charset);
}
#endif /* _LIBC || HAVE_ICONV */
}
diff -r -c3 intl/localealias.c intl-98/localealias.c
*** intl/localealias.c Sat Mar 17 17:06:11 2001
--- intl/localealias.c Sat Mar 17 14:52:01 2001
***************
*** 98,137 ****
# define internal_function
#endif
! /* For those loosing systems which don't have `alloca' we have to add
some additional code emulating it. */
#ifdef HAVE_ALLOCA
! /* Nothing has to be done. */
! # define ADD_BLOCK(list, address) /* nothing */
! # define FREE_BLOCKS(list) /* nothing */
#else
! struct block_list
! {
! void *address;
! struct block_list *next;
! };
! # define ADD_BLOCK(list, addr) \
! do { \
! struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \
! /* If we cannot get a free block we cannot add the new element to \
! the list. */ \
! if (newp != NULL) { \
! newp->address = (addr); \
! newp->next = (list); \
! (list) = newp; \
! } \
! } while (0)
! # define FREE_BLOCKS(list) \
! do { \
! while (list != NULL) { \
! struct block_list *old = list; \
! list = list->next; \
! free (old); \
! } \
! } while (0)
! # undef alloca
! # define alloca(size) (malloc (size))
! #endif /* have alloca */
#if defined _LIBC_REENTRANT || defined HAVE_FGETS_UNLOCKED
# undef fgets
--- 98,111 ----
# define internal_function
#endif
! /* For those losing systems which don't have `alloca' we have to add
some additional code emulating it. */
#ifdef HAVE_ALLOCA
! # define freea(p) /* nothing */
#else
! # define alloca(n) malloc (n)
! # define freea(p) free (p)
! #endif
#if defined _LIBC_REENTRANT || defined HAVE_FGETS_UNLOCKED
# undef fgets
***************
*** 234,249 ****
const char *fname;
int fname_len;
{
- #ifndef HAVE_ALLOCA
- struct block_list *block_list = NULL;
- #endif
FILE *fp;
char *full_fname;
size_t added;
static const char aliasfile[] = "/locale.alias";
full_fname = (char *) alloca (fname_len + sizeof aliasfile);
- ADD_BLOCK (block_list, full_fname);
#ifdef HAVE_MEMPCPY
mempcpy (mempcpy (full_fname, fname, fname_len),
aliasfile, sizeof aliasfile);
--- 209,220 ----
***************
*** 253,263 ****
#endif
fp = fopen (full_fname, "r");
if (fp == NULL)
! {
! FREE_BLOCKS (block_list);
! return 0;
! }
added = 0;
while (!feof (fp))
--- 224,232 ----
#endif
fp = fopen (full_fname, "r");
+ freea (full_fname);
if (fp == NULL)
! return 0;
added = 0;
while (!feof (fp))
***************
*** 330,339 ****
if (nmap >= maxmap)
if (__builtin_expect (extend_alias_table (), 0))
! {
! FREE_BLOCKS (block_list);
! return added;
! }
alias_len = strlen (alias) + 1;
value_len = strlen (value) + 1;
--- 299,305 ----
if (nmap >= maxmap)
if (__builtin_expect (extend_alias_table (), 0))
! return added;
alias_len = strlen (alias) + 1;
value_len = strlen (value) + 1;
***************
*** 346,355 ****
? alias_len + value_len : 1024));
char *new_pool = (char *) realloc (string_space, new_size);
if (new_pool == NULL)
! {
! FREE_BLOCKS (block_list);
! return added;
! }
if (__builtin_expect (string_space != new_pool, 0))
{
--- 312,318 ----
? alias_len + value_len : 1024));
char *new_pool = (char *) realloc (string_space, new_size);
if (new_pool == NULL)
! return added;
if (__builtin_expect (string_space != new_pool, 0))
{
***************
*** 388,394 ****
qsort (map, nmap, sizeof (struct alias_map),
(int (*) PARAMS ((const void *, const void *))) alias_compare);
- FREE_BLOCKS (block_list);
return added;
}
--- 351,356 ----