summaryrefslogtreecommitdiff
path: root/intl
diff options
context:
space:
mode:
Diffstat (limited to 'intl')
-rw-r--r--intl/dcgettext.c25
-rw-r--r--intl/finddomain.c20
-rw-r--r--intl/gettextP.h3
-rw-r--r--intl/loadmsgcat.c17
-rw-r--r--intl/localealias.c77
5 files changed, 108 insertions, 34 deletions
diff --git a/intl/dcgettext.c b/intl/dcgettext.c
index ecc2e1ac26..692ce45bcf 100644
--- a/intl/dcgettext.c
+++ b/intl/dcgettext.c
@@ -597,3 +597,28 @@ stpcpy (dest, src)
return dest - 1;
}
#endif
+
+
+#ifdef _LIBC
+/* If we want to free all resources we have to do some work at
+ program's end. */
+static void __attribute__ ((unused))
+free_mem (void)
+{
+ struct binding *runp;
+
+ for (runp = _nl_domain_bindings; runp != NULL; runp = runp->next)
+ {
+ free (runp->domainname);
+ if (runp->dirname != _nl_default_dirname)
+ /* Yes, this is a pointer comparison. */
+ free (runp->dirname);
+ }
+
+ if (_nl_current_default_domain != _nl_default_default_domain)
+ /* Yes, again a pointer comparison. */
+ free ((char *) _nl_current_default_domain);
+}
+
+text_set_element (__libc_subfreeres, free_mem);
+#endif
diff --git a/intl/finddomain.c b/intl/finddomain.c
index 769bd93eee..a44197c808 100644
--- a/intl/finddomain.c
+++ b/intl/finddomain.c
@@ -197,3 +197,23 @@ _nl_find_domain (dirname, locale, domainname)
return retval;
}
+
+
+#ifdef _LIBC
+static void __attribute__ ((unused))
+free_mem (void)
+{
+ struct loaded_l10nfile *runp = _nl_loaded_domains;
+
+ while (runp != NULL)
+ {
+ struct loaded_l10nfile *here = runp;
+ if (runp->data != NULL)
+ _nl_unload_domain ((struct loaded_domain *) runp->data);
+ runp = runp->next;
+ free (here);
+ }
+}
+
+text_set_element (__libc_subfreeres, free_mem);
+#endif
diff --git a/intl/gettextP.h b/intl/gettextP.h
index 8a4560dbfd..5225bcbc5e 100644
--- a/intl/gettextP.h
+++ b/intl/gettextP.h
@@ -50,6 +50,8 @@ SWAP (i)
struct loaded_domain
{
const char *data;
+ int use_mmap;
+ size_t mmap_size;
int must_swap;
nls_uint32 nstrings;
struct string_desc *orig_tab;
@@ -69,6 +71,7 @@ struct loaded_l10nfile *_nl_find_domain PARAMS ((const char *__dirname,
char *__locale,
const char *__domainname));
void _nl_load_domain PARAMS ((struct loaded_l10nfile *__domain));
+void _nl_unload_domain PARAMS ((struct loaded_domain *__domain));
/* @@ begin of epilog @@ */
diff --git a/intl/loadmsgcat.c b/intl/loadmsgcat.c
index f4352d00eb..43158c4cfa 100644
--- a/intl/loadmsgcat.c
+++ b/intl/loadmsgcat.c
@@ -168,6 +168,8 @@ _nl_load_domain (domain_file)
domain = (struct loaded_domain *) domain_file->data;
domain->data = (char *) data;
+ domain->use_mmap = use_mmap;
+ domain->mmap_size = st.st_size;
domain->must_swap = data->magic != _MAGIC;
/* Fill in the information about the available tables. */
@@ -201,3 +203,18 @@ _nl_load_domain (domain_file)
translations invalid. */
++_nl_msg_cat_cntr;
}
+
+
+#ifdef _LIBC
+void
+_nl_unload_domain (domain)
+ struct loaded_domain *domain;
+{
+ if (domain->use_mmap)
+ munmap ((caddr_t) domain->data, domain->mmap_size);
+ else
+ free ((void *) domain->data);
+
+ free (domain);
+}
+#endif
diff --git a/intl/localealias.c b/intl/localealias.c
index c77f12527e..46d570f88f 100644
--- a/intl/localealias.c
+++ b/intl/localealias.c
@@ -134,6 +134,9 @@ struct alias_map
};
+static char *string_space = NULL;
+static size_t string_space_act = 0;
+static size_t string_space_max = 0;
static struct alias_map *map;
static size_t nmap = 0;
static size_t maxmap = 0;
@@ -272,7 +275,8 @@ read_alias_file (fname, fname_len)
if (cp[0] != '\0')
{
char *tp;
- size_t len;
+ size_t alias_len;
+ size_t value_len;
value = cp++;
while (cp[0] != '\0' && !isspace (cp[0]))
@@ -292,35 +296,32 @@ read_alias_file (fname, fname_len)
if (nmap >= maxmap)
extend_alias_table ();
-#if defined _LIBC || defined HAVE_STRDUP
- map[nmap].alias = strdup (alias);
- map[nmap].value = strdup (value);
- if (map[nmap].alias == NULL || map[nmap].value == NULL)
- {
- FREE_BLOCKS (block_list);
- return added;
- }
-#else
- len = strlen (alias) + 1;
- tp = (char *) malloc (len);
- if (tp == NULL)
- {
- FREE_BLOCKS (block_list);
- return added;
- }
- memcpy (tp, alias, len);
- map[nmap].alias = tp;
+ alias_len = strlen (alias) + 1;
+ value_len = strlen (value) + 1;
- len = strlen (value) + 1;
- tp = (char *) malloc (len);
- if (tp == NULL)
+ if (string_space_act + alias_len + value_len > string_space_max)
{
- FREE_BLOCKS (block_list);
- return added;
+ /* Increase size of memory pool. */
+ size_t new_size = (string_space_max
+ + (alias_len + value_len > 1024
+ ? alias_len + value_len : 1024));
+ char *new_pool = (char *) realloc (string_space, new_size);
+ if (new_pool == NULL)
+ {
+ FREE_BLOCKS (block_list);
+ return added;
+ }
+ string_space = new_pool;
+ string_space_max = new_size;
}
- memcpy (tp, value, len);
- map[nmap].value = tp;
-#endif
+
+ map[nmap].alias = memcpy (&string_space[string_space_act],
+ alias, alias_len);
+ string_space_act += alias_len;
+
+ map[nmap].alias = memcpy (&string_space[string_space_act],
+ value, value_len);
+ string_space_act += value_len;
++nmap;
++added;
@@ -359,22 +360,30 @@ extend_alias_table ()
struct alias_map *new_map;
new_size = maxmap == 0 ? 100 : 2 * maxmap;
- new_map = (struct alias_map *) malloc (new_size
- * sizeof (struct alias_map));
+ new_map = (struct alias_map *) realloc (map, (new_size
+ * sizeof (struct alias_map)));
if (new_map == NULL)
/* Simply don't extend: we don't have any more core. */
return;
- memcpy (new_map, map, nmap * sizeof (struct alias_map));
-
- if (maxmap != 0)
- free (map);
-
map = new_map;
maxmap = new_size;
}
+#ifdef _LIBC
+static void __attribute__ ((unused))
+free_mem (void)
+{
+ if (string_space != NULL)
+ free (string_space);
+ if (map != NULL)
+ free (map);
+}
+text_set_element (__libc_subfreeres, free_mem);
+#endif
+
+
static int
alias_compare (map1, map2)
const struct alias_map *map1;