}
/* This does the real work. */
- _nl_unload_locale (data);
+ _nl_unload_locale (locale, data);
}
}
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;
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;
}
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))
{
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. */
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)
/* 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;
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);
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;
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;
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;
if (data != NULL)
{
locale->private.time = NULL;
- locale->private.cleanup = NULL;
free (data->eras);
free (data->alt_digits);
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);
_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);