about summary refs log tree commit diff
path: root/wcsmbs
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
commit93ec1cf0fef422b137be7a99fdcdf007c318c71d (patch)
tree1914d79fbb2e93c2e7cb289dad5a94279c67f416 /wcsmbs
parent7ee41feba6b834d9e17e634bfbf222c4d8dd1a4f (diff)
downloadglibc-93ec1cf0fef422b137be7a99fdcdf007c318c71d.tar.gz
glibc-93ec1cf0fef422b137be7a99fdcdf007c318c71d.tar.xz
glibc-93ec1cf0fef422b137be7a99fdcdf007c318c71d.zip
locale: Add more cached data to LC_CTYPE
This data will be used in number formatting.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'wcsmbs')
-rw-r--r--wcsmbs/wcsmbsload.c23
-rw-r--r--wcsmbs/wcsmbsload.h13
2 files changed, 17 insertions, 19 deletions
diff --git a/wcsmbs/wcsmbsload.c b/wcsmbs/wcsmbsload.c
index 2650834e29..0f0f55f9ed 100644
--- a/wcsmbs/wcsmbsload.c
+++ b/wcsmbs/wcsmbsload.c
@@ -150,12 +150,14 @@ __libc_rwlock_define (extern, __libc_setlocale_lock attribute_hidden)
 void
 __wcsmbs_load_conv (struct __locale_data *new_category)
 {
+  struct lc_ctype_data *data = new_category->private;
+
   /* Acquire the lock.  */
   __libc_rwlock_wrlock (__libc_setlocale_lock);
 
   /* We should repeat the test since while we waited some other thread
      might have run this function.  */
-  if (__glibc_likely (new_category->private == NULL))
+  if (__glibc_likely (data->fcts == NULL))
     {
       /* We must find the real functions.  */
       const char *charset_name;
@@ -199,10 +201,10 @@ __wcsmbs_load_conv (struct __locale_data *new_category)
 	  free (new_fcts);
 
 	failed:
-	  new_category->private = (void *) &__wcsmbs_gconv_fcts_c;
+	  data->fcts = (void *) &__wcsmbs_gconv_fcts_c;
 	}
       else
-	new_category->private = new_fcts;
+	data->fcts = new_fcts;
     }
 
   __libc_rwlock_unlock (__libc_setlocale_lock);
@@ -263,14 +265,15 @@ __wcsmbs_named_conv (struct gconv_fcts *copy, const char *name)
 void
 _nl_cleanup_ctype (struct __locale_data *locale)
 {
-  const struct gconv_fcts *const data = locale->private;
-  if (data != NULL && data != &__wcsmbs_gconv_fcts_c)
+  struct lc_ctype_data *data = locale->private;
+  if (data->fcts != NULL && data->fcts != &__wcsmbs_gconv_fcts_c)
     {
-      locale->private = NULL;
-
       /* Free the old conversions.  */
-      __gconv_close_transform (data->tomb, data->tomb_nsteps);
-      __gconv_close_transform (data->towc, data->towc_nsteps);
-      free ((char *) data);
+      __gconv_close_transform (data->fcts->tomb, data->fcts->tomb_nsteps);
+      __gconv_close_transform (data->fcts->towc, data->fcts->towc_nsteps);
+
+      free ((void *) data->fcts);
+      data->fcts = NULL;
+      /* data itself is allocated within locale.  */
     }
 }
diff --git a/wcsmbs/wcsmbsload.h b/wcsmbs/wcsmbsload.h
index 8bbd34ba02..876f8368b1 100644
--- a/wcsmbs/wcsmbsload.h
+++ b/wcsmbs/wcsmbsload.h
@@ -66,15 +66,10 @@ extern const struct __locale_data _nl_C_LC_CTYPE attribute_hidden;
 static inline const struct gconv_fcts *
 get_gconv_fcts (struct __locale_data *data)
 {
-  struct gconv_fcts *private = data->private;
-  if (private == NULL)
-    {
-      if (data == &_nl_C_LC_CTYPE)
-	return &__wcsmbs_gconv_fcts_c;
-      __wcsmbs_load_conv (data);
-      private = data->private;
-    }
-  return private;
+  struct lc_ctype_data *private = data->private;
+  if (private->fcts == NULL)
+    __wcsmbs_load_conv (data);
+  return private->fcts;
 }
 
 #endif	/* wcsmbsload.h */