diff options
author | Jakub Jelinek <jakub@redhat.com> | 2008-04-08 07:59:52 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2008-04-08 07:59:52 +0000 |
commit | e6e467b8352b6a62b8187fd241671eb55d0f6fc4 (patch) | |
tree | 2e7c2ddae1aa58a70c384e1d5b49d3ad198a2718 /intl/dcigettext.c | |
parent | 09b731ac2b1b5e79050991f6a9dab964f9a7a60f (diff) |
Updated to fedora-glibc-20080408T0706
Diffstat (limited to 'intl/dcigettext.c')
-rw-r--r-- | intl/dcigettext.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/intl/dcigettext.c b/intl/dcigettext.c index 7004cd49cf..e0782446e4 100644 --- a/intl/dcigettext.c +++ b/intl/dcigettext.c @@ -1,5 +1,6 @@ /* Implementation of the internal dcigettext function. - Copyright (C) 1995-2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1995-2005, 2006, 2007, 2008 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -449,6 +450,11 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category) : n == 1 ? (char *) msgid1 : (char *) msgid2); #endif +#ifdef _LIBC + __libc_rwlock_define (extern, __libc_setlocale_lock attribute_hidden) + __libc_rwlock_rdlock (__libc_setlocale_lock); +#endif + __libc_rwlock_rdlock (_nl_state_lock); /* If DOMAINNAME is NULL, we are interested in the default domain. If @@ -466,7 +472,7 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category) search.category = category; # ifdef HAVE_PER_THREAD_LOCALE # ifdef _LIBC - localename = __current_locale_name (category); + localename = strdupa (__current_locale_name (category)); # endif search.localename = localename; # endif @@ -489,6 +495,9 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category) else retval = (char *) (*foundp)->translation; +# ifdef _LIBC + __libc_rwlock_unlock (__libc_setlocale_lock); +# endif __libc_rwlock_unlock (_nl_state_lock); return retval; } @@ -548,6 +557,7 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category) /* We cannot get the current working directory. Don't signal an error but simply return the default string. */ FREE_BLOCKS (block_list); + __libc_rwlock_unlock (__libc_setlocale_lock); __libc_rwlock_unlock (_nl_state_lock); __set_errno (saved_errno); return (plural == 0 @@ -614,6 +624,7 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category) { no_translation: FREE_BLOCKS (block_list); + __libc_rwlock_unlock (__libc_setlocale_lock); __libc_rwlock_unlock (_nl_state_lock); __set_errno (saved_errno); return (plural == 0 @@ -727,6 +738,7 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category) if (plural) retval = plural_lookup (domain, n, retval, retlen); + __libc_rwlock_unlock (__libc_setlocale_lock); __libc_rwlock_unlock (_nl_state_lock); return retval; } @@ -879,6 +891,7 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp) { /* We have to allocate a new conversions table. */ __libc_rwlock_wrlock (domain->conversions_lock); + nconversions = domain->nconversions; /* Maybe in the meantime somebody added the translation. Recheck. */ @@ -1033,6 +1046,7 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp) # endif ) { + __libc_lock_define_initialized (static, lock) /* We are supposed to do a conversion. First allocate an appropriate table with the same structure as the table of translations in the file, where we can put the pointers @@ -1042,13 +1056,21 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp) handle this case by converting RESULTLEN bytes, including NULs. */ - if (convd->conv_tab == NULL - && ((convd->conv_tab = - (char **) calloc (nstrings + domain->n_sysdep_strings, - sizeof (char *))) - == NULL)) - /* Mark that we didn't succeed allocating a table. */ - convd->conv_tab = (char **) -1; + if (__builtin_expect (convd->conv_tab == NULL, 0)) + { + __libc_lock_lock (lock); + if (convd->conv_tab == NULL) + { + convd->conv_tab + = calloc (nstrings + domain->n_sysdep_strings, + sizeof (char *)); + if (convd->conv_tab != NULL) + goto not_translated_yet; + /* Mark that we didn't succeed allocating a table. */ + convd->conv_tab = (char **) -1; + } + __libc_lock_unlock (lock); + } if (__builtin_expect (convd->conv_tab == (char **) -1, 0)) /* Nothing we can do, no more memory. We cannot use the @@ -1057,12 +1079,14 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp) if (convd->conv_tab[act] == NULL) { + __libc_lock_lock (lock); + not_translated_yet:; + /* We haven't used this string so far, so it is not translated yet. Do this now. */ /* We use a bit more efficient memory handling. We allocate always larger blocks which get used over time. This is faster than many small allocations. */ - __libc_lock_define_initialized (static, lock) # define INITIAL_BLOCK_SIZE 4080 static unsigned char *freemem; static size_t freemem_size; @@ -1074,8 +1098,6 @@ _nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp) transmem_block_t *transmem_list = NULL; # endif - __libc_lock_lock (lock); - inbuf = (const unsigned char *) result; outbuf = freemem + sizeof (size_t); |