{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
13,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
19,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
1, /* Enable transliteration by default. */
NR_FIXED + NR_CLASSES + NR_MAPS,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
16,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
2,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
5,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
46,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
7,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
6,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
3,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
5,
{
_nl_C_name,
NULL, 0, 0, /* no file mapped */
- { NULL, }, /* no cached data */
+ NULL, /* No cached data. */
UNDELETABLE,
0,
159,
} alloc;
/* 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
- {
- struct lc_time_data *time;
- const struct gconv_fcts *ctype;
- } private;
+ computed about this locale. Type of the data pointed to:
+
+ LC_CTYPE struct gconv_fcts (get_gconv_fcts, __wcsmbs_load_conv)
+ LC_TIME struct lc_time_data (_nl_init_alt_digit, _nl_init_era_entries)
+
+ This data deallocated at the start of _nl_unload_locale. */
+ void *private;
unsigned int usage_count; /* Counter for users. */
#define CURRENT_WSTR(item) \
((wchar_t *) current->values[_NL_ITEM_INDEX (item)].wstr)
-static void
+static struct lc_time_data *
_nl_init_alt_digit (struct __locale_data *current)
{
- struct lc_time_data *data;
+ struct lc_time_data *data = current->private;
- if (current->private.time == NULL)
+ if (data == NULL)
{
- current->private.time = malloc (sizeof *current->private.time);
- if (current->private.time == NULL)
- return;
- memset (current->private.time, 0, sizeof *current->private.time);
+ data = calloc (sizeof *data, 1);
+ if (data == NULL)
+ return NULL;
+ current->private = data;
}
- data = current->private.time;
if (! data->alt_digits_initialized)
{
}
}
+ return data;
}
const char *
__libc_rwlock_wrlock (__libc_setlocale_lock);
- if (current->private.time == NULL
- || ! current->private.time->alt_digits_initialized)
- _nl_init_alt_digit (current);
+ struct lc_time_data *data = _nl_init_alt_digit (current);
- result = ((current->private.time != NULL
- && current->private.time->alt_digits != NULL)
- ? current->private.time->alt_digits[number]
+ result = ((data != NULL
+ && data->alt_digits != NULL)
+ ? data->alt_digits[number]
: NULL);
__libc_rwlock_unlock (__libc_setlocale_lock);
_nl_get_walt_digit (unsigned int number, struct __locale_data *current)
{
const wchar_t *result = NULL;
- struct lc_time_data *data;
if (number >= 100 || CURRENT_WSTR (_NL_WALT_DIGITS)[0] == L'\0')
return NULL;
__libc_rwlock_wrlock (__libc_setlocale_lock);
- if (current->private.time == NULL)
+ struct lc_time_data *data = current->private;
+ if (data == NULL)
{
- current->private.time = malloc (sizeof *current->private.time);
- if (current->private.time == NULL)
+ data = calloc (sizeof *data, 1);
+ if (data == NULL)
goto out;
- memset (current->private.time, 0, sizeof *current->private.time);
+ current->private = data;
}
- data = current->private.time;
if (! data->walt_digits_initialized)
{
__libc_rwlock_wrlock (__libc_setlocale_lock);
- if (current->private.time == NULL
- || ! current->private.time->alt_digits_initialized)
- _nl_init_alt_digit (current);
-
- if (current->private.time != NULL
- && current->private.time->alt_digits != NULL)
+ struct lc_time_data *data = _nl_init_alt_digit (current);
+ if (data != NULL && data->alt_digits != NULL)
/* Matching is not unambiguous. The alternative digits could be like
I, II, III, ... and the first one is a substring of the second
and third. Therefore we must keep on searching until we found
the standard. */
for (cnt = 0; cnt < 100; ++cnt)
{
- const char *const dig = current->private.time->alt_digits[cnt];
+ const char *const dig = data->alt_digits[cnt];
size_t len = strlen (dig);
if (len > maxlen && strncmp (dig, str, len) == 0)
/* Look up the era information in CURRENT's locale strings and
cache it in CURRENT->private. */
-static void
+static struct lc_time_data *
_nl_init_era_entries (struct __locale_data *current)
{
size_t cnt;
/* Avoid touching CURRENT if there is no data at all, for _nl_C_LC_TIME. */
if (CURRENT_WORD (_NL_TIME_ERA_NUM_ENTRIES) == 0)
- return;
+ return NULL;
+
+ data = current->private;
+ if (data != NULL && atomic_load_acquire (&data->era_initialized))
+ return data;
__libc_rwlock_wrlock (__libc_setlocale_lock);
- if (current->private.time == NULL)
+ data = current->private;
+ if (data == NULL)
{
- current->private.time = malloc (sizeof *current->private.time);
- if (current->private.time == NULL)
+ data = calloc (sizeof *data, 1);
+ if (data == NULL)
goto out;
- memset (current->private.time, 0, sizeof *current->private.time);
+ current->private = data;
}
- data = current->private.time;
if (! data->era_initialized)
{
}
}
- data->era_initialized = 1;
+ atomic_store_release (&data->era_initialized, 1);
}
out:
__libc_rwlock_unlock (__libc_setlocale_lock);
+ return data;
}
struct era_entry *
_nl_get_era_entry (const struct tm *tp, struct __locale_data *current)
{
- if (current->private.time == NULL || !current->private.time->era_initialized)
- _nl_init_era_entries (current);
+ struct lc_time_data *data = _nl_init_era_entries (current);
- if (current->private.time != NULL)
+ if (data != NULL)
{
/* Now compare date with the available eras. */
const int32_t tdate[3] = { tp->tm_year, tp->tm_mon, tp->tm_mday };
size_t cnt;
- for (cnt = 0; cnt < current->private.time->num_eras; ++cnt)
- if ((ERA_DATE_CMP (current->private.time->eras[cnt].start_date, tdate)
- && ERA_DATE_CMP (tdate,
- current->private.time->eras[cnt].stop_date))
- || (ERA_DATE_CMP (current->private.time->eras[cnt].stop_date,
- tdate)
- && ERA_DATE_CMP (tdate,
- current->private.time->eras[cnt].start_date)))
- return ¤t->private.time->eras[cnt];
+ for (cnt = 0; cnt < data->num_eras; ++cnt)
+ if ((ERA_DATE_CMP (data->eras[cnt].start_date, tdate)
+ && ERA_DATE_CMP (tdate, data->eras[cnt].stop_date))
+ || (ERA_DATE_CMP (data->eras[cnt].stop_date, tdate)
+ && ERA_DATE_CMP (tdate, data->eras[cnt].start_date)))
+ return &data->eras[cnt];
}
return NULL;
struct era_entry *
_nl_select_era_entry (int cnt, struct __locale_data *current)
{
- if (current->private.time == NULL || !current->private.time->era_initialized)
- _nl_init_era_entries (current);
-
- return (current->private.time == NULL
- ? NULL : ¤t->private.time->eras[cnt]);
+ struct lc_time_data *data = _nl_init_era_entries (current);
+ return data == NULL ? NULL : &data->eras[cnt];
}
void
_nl_cleanup_time (struct __locale_data *locale)
{
- struct lc_time_data *const data = locale->private.time;
+ struct lc_time_data *const data = locale->private;
if (data != NULL)
{
- locale->private.time = NULL;
+ locale->private = NULL;
free (data->eras);
free (data->alt_digits);
/* We should repeat the test since while we waited some other thread
might have run this function. */
- if (__glibc_likely (new_category->private.ctype == NULL))
+ if (__glibc_likely (new_category->private == NULL))
{
/* We must find the real functions. */
const char *charset_name;
free (new_fcts);
failed:
- new_category->private.ctype = &__wcsmbs_gconv_fcts_c;
+ new_category->private = (void *) &__wcsmbs_gconv_fcts_c;
}
else
- new_category->private.ctype = new_fcts;
+ new_category->private = new_fcts;
}
__libc_rwlock_unlock (__libc_setlocale_lock);
void
_nl_cleanup_ctype (struct __locale_data *locale)
{
- const struct gconv_fcts *const data = locale->private.ctype;
+ const struct gconv_fcts *const data = locale->private;
if (data != NULL && data != &__wcsmbs_gconv_fcts_c)
{
- locale->private.ctype = NULL;
+ locale->private = NULL;
/* Free the old conversions. */
__gconv_close_transform (data->tomb, data->tomb_nsteps);
static inline const struct gconv_fcts *
get_gconv_fcts (struct __locale_data *data)
{
- if (__glibc_unlikely (data->private.ctype == NULL))
+ struct gconv_fcts *private = data->private;
+ if (private == NULL)
{
- if (__glibc_unlikely (data == &_nl_C_LC_CTYPE))
+ if (data == &_nl_C_LC_CTYPE)
return &__wcsmbs_gconv_fcts_c;
__wcsmbs_load_conv (data);
+ private = data->private;
}
- return data->private.ctype;
+ return private;
}
#endif /* wcsmbsload.h */