aboutsummaryrefslogtreecommitdiff
path: root/locale
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2022-05-23 10:08:18 +0200
committerFlorian Weimer <fweimer@redhat.com>2022-05-23 11:06:31 +0200
commitbbebe83a2874cd25934046d908824dfc11711a2b (patch)
tree1e4b6818e4fc8c35996da79471d55048095f7650 /locale
parent0b6342e769be6903f29da067f5cbcbfcc7c01b10 (diff)
downloadglibc-bbebe83a2874cd25934046d908824dfc11711a2b.zip
glibc-bbebe83a2874cd25934046d908824dfc11711a2b.tar.gz
glibc-bbebe83a2874cd25934046d908824dfc11711a2b.tar.bz2
locale: Remove cleanup function pointer from struct __localedata
We can call the cleanup functions directly from _nl_unload_locale if we pass the category to it. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'locale')
-rw-r--r--locale/findlocale.c2
-rw-r--r--locale/loadarchive.c2
-rw-r--r--locale/loadlocale.c17
-rw-r--r--locale/localeinfo.h23
-rw-r--r--locale/setlocale.c2
5 files changed, 25 insertions, 21 deletions
diff --git a/locale/findlocale.c b/locale/findlocale.c
index 64f687e..fc433b6 100644
--- a/locale/findlocale.c
+++ b/locale/findlocale.c
@@ -348,6 +348,6 @@ _nl_remove_locale (int locale, struct __locale_data *data)
}
/* This does the real work. */
- _nl_unload_locale (data);
+ _nl_unload_locale (locale, data);
}
}
diff --git a/locale/loadarchive.c b/locale/loadarchive.c
index 5a23567..fcc4913 100644
--- a/locale/loadarchive.c
+++ b/locale/loadarchive.c
@@ -515,7 +515,7 @@ _nl_archive_subfreeres (void)
free (dead->name);
for (category = 0; category < __LC_LAST; ++category)
if (category != LC_ALL && dead->data[category] != NULL)
- _nl_unload_locale (dead->data[category]);
+ _nl_unload_locale (category, dead->data[category]);
free (dead);
}
archloaded = NULL;
diff --git a/locale/loadlocale.c b/locale/loadlocale.c
index b8cd1aa..9069baf 100644
--- a/locale/loadlocale.c
+++ b/locale/loadlocale.c
@@ -101,8 +101,7 @@ _nl_intern_locale_data (int category, const void *data, size_t datasize)
newdata->filedata = (void *) filedata;
newdata->filesize = datasize;
- newdata->private.data = NULL;
- newdata->private.cleanup = NULL;
+ memset (&newdata->private, 0, sizeof (newdata->private));
newdata->usage_count = 0;
newdata->use_translit = 0;
newdata->nstrings = filedata->nstrings;
@@ -282,10 +281,18 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
}
void
-_nl_unload_locale (struct __locale_data *locale)
+_nl_unload_locale (int category, struct __locale_data *locale)
{
- if (locale->private.cleanup)
- (*locale->private.cleanup) (locale);
+ /* Deallocate locale->private. */
+ switch (category)
+ {
+ case LC_CTYPE:
+ _nl_cleanup_ctype (locale);
+ break;
+ case LC_TIME:
+ _nl_cleanup_time (locale);
+ break;
+ }
switch (__builtin_expect (locale->alloc, ld_mapped))
{
diff --git a/locale/localeinfo.h b/locale/localeinfo.h
index 87d3b48..8ce072b 100644
--- a/locale/localeinfo.h
+++ b/locale/localeinfo.h
@@ -58,18 +58,13 @@ struct __locale_data
ld_archive /* Both point into mmap'd archive regions. */
} alloc;
- /* This provides a slot for category-specific code to cache data computed
- about this locale. That code can set a cleanup function to deallocate
- the data. */
- struct
+ /* This provides a slot for category-specific code to cache data
+ computed about this locale. This is deallocated at the start of
+ _nl_unload_locale. */
+ union
{
- void (*cleanup) (struct __locale_data *);
- union
- {
- void *data;
- struct lc_time_data *time;
- const struct gconv_fcts *ctype;
- };
+ struct lc_time_data *time;
+ const struct gconv_fcts *ctype;
} private;
unsigned int usage_count; /* Counter for users. */
@@ -349,7 +344,8 @@ extern void _nl_load_locale (struct loaded_l10nfile *file, int category)
attribute_hidden;
/* Free all resource. */
-extern void _nl_unload_locale (struct __locale_data *locale) attribute_hidden;
+extern void _nl_unload_locale (int category, struct __locale_data *locale)
+ attribute_hidden;
/* Free the locale and give back all memory if the usage count is one. */
extern void _nl_remove_locale (int locale, struct __locale_data *data)
@@ -409,7 +405,8 @@ extern int _nl_parse_alt_digit (const char **strp,
/* Postload processing. */
extern void _nl_postload_ctype (void);
-/* Functions used for the `private.cleanup' hook. */
+/* Deallocate category-specific data. Used in _nl_unload_locale. */
+extern void _nl_cleanup_ctype (struct __locale_data *) attribute_hidden;
extern void _nl_cleanup_time (struct __locale_data *) attribute_hidden;
diff --git a/locale/setlocale.c b/locale/setlocale.c
index 38e9bec..56c14d8 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -489,7 +489,7 @@ free_category (int category,
struct __locale_data *data = (struct __locale_data *) runp->data;
if (data != NULL && data != c_data)
- _nl_unload_locale (data);
+ _nl_unload_locale (category, data);
runp = runp->next;
free ((char *) curr->filename);
free (curr);