From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH 13/26] locale: Remove cleanup function pointer from struct __localedata
Date: Thu, 17 Mar 2022 20:30:30 +0100 [thread overview]
Message-ID: <88ed96b666eb032d54b5788f99ed322939f9e8f9.1647544751.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1647544751.git.fweimer@redhat.com>
We can call the cleanup functions directly from _nl_unload_locale
if we pass the category to it.
---
locale/findlocale.c | 2 +-
locale/loadarchive.c | 2 +-
locale/loadlocale.c | 17 ++++++++++++-----
locale/localeinfo.h | 23 ++++++++++-------------
locale/setlocale.c | 2 +-
time/alt_digit.c | 2 --
time/era.c | 1 -
time/lc-time-cleanup.c | 1 -
wcsmbs/wcsmbsload.c | 8 ++------
9 files changed, 27 insertions(+), 31 deletions(-)
diff --git a/locale/findlocale.c b/locale/findlocale.c
index 64f687ea9d..fc433b61d8 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 5a2356707f..fcc4913319 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 b8cd1aa441..9069bafcd8 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 87d3b48c16..8ce072b7b4 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 38e9bec6bb..56c14d8533 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);
diff --git a/time/alt_digit.c b/time/alt_digit.c
index ae22b3f927..7ed9b6b0a5 100644
--- a/time/alt_digit.c
+++ b/time/alt_digit.c
@@ -41,7 +41,6 @@ _nl_init_alt_digit (struct __locale_data *current)
if (current->private.time == NULL)
return;
memset (current->private.time, 0, sizeof *current->private.time);
- current->private.cleanup = &_nl_cleanup_time;
}
data = current->private.time;
@@ -110,7 +109,6 @@ _nl_get_walt_digit (unsigned int number, struct __locale_data *current)
if (current->private.time == NULL)
goto out;
memset (current->private.time, 0, sizeof *current->private.time);
- current->private.cleanup = &_nl_cleanup_time;
}
data = current->private.time;
diff --git a/time/era.c b/time/era.c
index 43528ad0d2..d4b538c7b0 100644
--- a/time/era.c
+++ b/time/era.c
@@ -53,7 +53,6 @@ _nl_init_era_entries (struct __locale_data *current)
if (current->private.time == NULL)
goto out;
memset (current->private.time, 0, sizeof *current->private.time);
- current->private.cleanup = &_nl_cleanup_time;
}
data = current->private.time;
diff --git a/time/lc-time-cleanup.c b/time/lc-time-cleanup.c
index 2734e25815..f844e04905 100644
--- a/time/lc-time-cleanup.c
+++ b/time/lc-time-cleanup.c
@@ -26,7 +26,6 @@ _nl_cleanup_time (struct __locale_data *locale)
if (data != NULL)
{
locale->private.time = NULL;
- locale->private.cleanup = NULL;
free (data->eras);
free (data->alt_digits);
diff --git a/wcsmbs/wcsmbsload.c b/wcsmbs/wcsmbsload.c
index ffb5cb7b87..af539a099a 100644
--- a/wcsmbs/wcsmbsload.c
+++ b/wcsmbs/wcsmbsload.c
@@ -202,10 +202,7 @@ __wcsmbs_load_conv (struct __locale_data *new_category)
new_category->private.ctype = &__wcsmbs_gconv_fcts_c;
}
else
- {
- new_category->private.ctype = new_fcts;
- new_category->private.cleanup = &_nl_cleanup_ctype;
- }
+ new_category->private.ctype = new_fcts;
}
__libc_rwlock_unlock (__libc_setlocale_lock);
@@ -267,10 +264,9 @@ void
_nl_cleanup_ctype (struct __locale_data *locale)
{
const struct gconv_fcts *const data = locale->private.ctype;
- if (data != NULL)
+ if (data != NULL && data != &__wcsmbs_gconv_fcts_c)
{
locale->private.ctype = NULL;
- locale->private.cleanup = NULL;
/* Free the old conversions. */
__gconv_close_transform (data->tomb, data->tomb_nsteps);
--
2.35.1
next prev parent reply other threads:[~2022-03-17 19:30 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-17 19:28 [PATCH 00/26] vfprintf rework to remove vtables Florian Weimer
2022-03-17 19:28 ` [PATCH 01/26] libio: Convert tst_swprintf to the test framework Florian Weimer
2022-03-18 17:40 ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 02/26] libio: Flush-only _IO_str_overflow must not return EOF (bug 28949) Florian Weimer
2022-03-18 18:11 ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 03/26] stdio-common: Add wide stream coverage to tst-vfprintf-user-type Florian Weimer
2022-03-18 18:30 ` Adhemerval Zanella
2022-03-18 19:19 ` Florian Weimer
2022-03-17 19:28 ` [PATCH 04/26] stdio-common: Add tst-printf-width-i18n to cover numeric field width Florian Weimer
2022-05-20 13:22 ` Adhemerval Zanella
2022-05-20 13:33 ` Adhemerval Zanella
2022-05-23 6:39 ` Florian Weimer
2022-03-17 19:28 ` [PATCH 05/26] vfprintf: Move argument processing into vfprintf-process-arg.c Florian Weimer
2022-05-20 13:28 ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 06/26] vfprintf: Consolidate some multibyte/wide character processing Florian Weimer
2022-05-20 14:16 ` Adhemerval Zanella
2022-03-17 19:29 ` [PATCH 07/26] __printf_fphex always uses LC_NUMERIC Florian Weimer
2022-05-20 14:21 ` Adhemerval Zanella
2022-05-23 6:55 ` Florian Weimer
2022-03-17 19:29 ` [PATCH 08/26] stdio-common: Add tst-memstream-string for open_memstream overflow Florian Weimer
2022-05-20 17:44 ` Adhemerval Zanella
2022-05-23 7:03 ` Florian Weimer
2022-03-17 19:29 ` [PATCH 09/26] stdio-common: Add printf specifier registry to <printf.h> Florian Weimer
2022-05-20 17:49 ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 10/26] stdio-common: Move union printf_arg int <printf.h> Florian Weimer
2022-05-20 17:51 ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 11/26] stdio-common: Simplify printf_unknown interface in vfprintf-internal.c Florian Weimer
2022-05-20 18:07 ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 12/26] locale: Call _nl_unload_locale from _nl_archive_subfreeres Florian Weimer
2022-05-20 18:09 ` Adhemerval Zanella
2022-05-23 7:14 ` Florian Weimer
2022-03-17 19:30 ` Florian Weimer [this message]
2022-05-20 18:16 ` [PATCH 13/26] locale: Remove cleanup function pointer from struct __localedata Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 14/26] locale: Remove private union from struct __locale_data Florian Weimer
2022-05-20 18:22 ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 15/26] locale: Add more cached data to LC_CTYPE Florian Weimer
2022-05-20 18:29 ` Adhemerval Zanella
2022-05-23 7:20 ` Florian Weimer
2022-03-17 19:31 ` [PATCH 16/26] locale: Implement struct grouping_iterator Florian Weimer
2022-03-17 19:31 ` [PATCH 17/26] stdio-common: Introduce buffers for implementing printf Florian Weimer
2022-03-17 19:31 ` [PATCH 18/26] stdio-common: Add __printf_function_invoke Florian Weimer
2022-03-17 19:31 ` [PATCH 19/26] stdio-common: Add __translated_number_width Florian Weimer
2022-03-17 19:31 ` [PATCH 20/26] stdio-common: Convert vfprintf and related functions to buffers Florian Weimer
2022-03-17 19:31 ` [PATCH 21/26] stdio-common: Add lock optimization to vfprintf and vfwprintf Florian Weimer
2022-03-17 19:31 ` [PATCH 22/26] libio: Convert __vsprintf_internal to buffers Florian Weimer
2022-03-17 19:31 ` [PATCH 23/26] libio: Convert __vasprintf_internal " Florian Weimer
2022-03-17 19:31 ` [PATCH 24/26] libio: Convert __vdprintf_internal " Florian Weimer
2022-03-17 19:32 ` [PATCH 25/26] libio: Convert __obstack_vprintf_internal to buffers (bug 27124) Florian Weimer
2022-03-17 19:32 ` [PATCH 26/26] libio: Convert __vswprintf_internal to buffers (bug 27857) Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=88ed96b666eb032d54b5788f99ed322939f9e8f9.1647544751.git.fweimer@redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).