From patchwork Thu Mar 17 19:30:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 52074 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A46C8384602A for ; Thu, 17 Mar 2022 19:39:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A46C8384602A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1647545988; bh=w+WPnXmzrD12kkiJRrnF6qOtwKu2maYg01gXD/48sTg=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=EnvwPTgiW/xiitkjSNJ5kJ6NqBhO3k/J3G0O3wWItfwNzs3wshWFWngLPI/6RUcPF Kn8sA0+nUxKYZqwKnJ1Wm/lMQy2PW7T3o6TsdULMuzwtxM+rQzISKYFV3PDnRFvdCp er5RwcxEg5ir4bHxHSUg3lQJ4mD8GtvAJat2kEfk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 89D743857C42 for ; Thu, 17 Mar 2022 19:30:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 89D743857C42 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-113-aIAESt0FOCOo3jdSLuOsOQ-1; Thu, 17 Mar 2022 15:30:34 -0400 X-MC-Unique: aIAESt0FOCOo3jdSLuOsOQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CB45C1044561 for ; Thu, 17 Mar 2022 19:30:33 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B977C469A58 for ; Thu, 17 Mar 2022 19:30:32 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 13/26] locale: Remove cleanup function pointer from struct __localedata In-Reply-To: References: X-From-Line: 88ed96b666eb032d54b5788f99ed322939f9e8f9 Mon Sep 17 00:00:00 2001 Message-Id: <88ed96b666eb032d54b5788f99ed322939f9e8f9.1647544751.git.fweimer@redhat.com> Date: Thu, 17 Mar 2022 20:30:30 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" We can call the cleanup functions directly from _nl_unload_locale if we pass the category to it. Reviewed-by: Adhemerval Zanella --- 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);