summary refs log tree commit diff
path: root/intl
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2008-04-08 07:59:52 +0000
committerJakub Jelinek <jakub@redhat.com>2008-04-08 07:59:52 +0000
commite6e467b8352b6a62b8187fd241671eb55d0f6fc4 (patch)
tree2e7c2ddae1aa58a70c384e1d5b49d3ad198a2718 /intl
parent09b731ac2b1b5e79050991f6a9dab964f9a7a60f (diff)
downloadglibc-e6e467b8352b6a62b8187fd241671eb55d0f6fc4.tar.gz
glibc-e6e467b8352b6a62b8187fd241671eb55d0f6fc4.tar.xz
glibc-e6e467b8352b6a62b8187fd241671eb55d0f6fc4.zip
Updated to fedora-glibc-20080408T0706
Diffstat (limited to 'intl')
-rw-r--r--intl/Makefile13
-rw-r--r--intl/dcigettext.c46
-rw-r--r--intl/tst-gettext6.c86
-rw-r--r--intl/tst-gettext6.sh41
4 files changed, 170 insertions, 16 deletions
diff --git a/intl/Makefile b/intl/Makefile
index 9da445aa38..1511edd490 100644
--- a/intl/Makefile
+++ b/intl/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1995-2003, 2005 Free Software Foundation, Inc.
+# Copyright (C) 1995-2003, 2005, 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
@@ -32,11 +32,11 @@ distribute = gmo.h gettextP.h hash-string.h loadinfo.h locale.alias \
 	     tst-codeset.sh tstcodeset.po \
 	     tst-gettext3.sh \
 	     tst-gettext4.sh tst-gettext4-de.po tst-gettext4-fr.po \
-	     tst-gettext5.sh
+	     tst-gettext5.sh tst-gettext6.sh
 
 include ../Makeconfig
 
-multithread-test-srcs := tst-gettext4 tst-gettext5
+multithread-test-srcs := tst-gettext4 tst-gettext5 tst-gettext6
 test-srcs := tst-gettext tst-translit tst-gettext2 tst-codeset tst-gettext3
 ifeq ($(have-thread-library),yes)
 test-srcs += $(multithread-test-srcs)
@@ -67,7 +67,8 @@ ifneq ($(strip $(MSGFMT)),:)
 tests: $(objpfx)tst-translit.out $(objpfx)tst-gettext2.out \
        $(objpfx)tst-codeset.out $(objpfx)tst-gettext3.out
 ifeq ($(have-thread-library),yes)
-tests: $(objpfx)tst-gettext4.out $(objpfx)tst-gettext5.out
+tests: $(objpfx)tst-gettext4.out $(objpfx)tst-gettext5.out \
+       $(objpfx)tst-gettext6.out
 endif
 ifneq (no,$(PERL))
 tests: $(objpfx)mtrace-tst-gettext
@@ -90,6 +91,8 @@ $(objpfx)tst-gettext4.out: tst-gettext4.sh $(objpfx)tst-gettext4
 	$(SHELL) -e $< $(common-objpfx) '$(run-program-prefix)' $(common-objpfx)intl/
 $(objpfx)tst-gettext5.out: tst-gettext5.sh $(objpfx)tst-gettext5
 	$(SHELL) -e $< $(common-objpfx) '$(run-program-prefix)' $(common-objpfx)intl/
+$(objpfx)tst-gettext6.out: tst-gettext6.sh $(objpfx)tst-gettext6
+	$(SHELL) -e $< $(common-objpfx) '$(run-program-prefix)' $(common-objpfx)intl/
 endif
 endif
 
@@ -104,6 +107,7 @@ CFLAGS-tst-codeset.c = -DOBJPFX=\"$(objpfx)\"
 CFLAGS-tst-gettext3.c = -DOBJPFX=\"$(objpfx)\"
 CFLAGS-tst-gettext4.c = -DOBJPFX=\"$(objpfx)\"
 CFLAGS-tst-gettext5.c = -DOBJPFX=\"$(objpfx)\"
+CFLAGS-tst-gettext6.c = -DOBJPFX=\"$(objpfx)\"
 
 ifeq ($(have-thread-library),yes)
 ifeq (yes,$(build-shared))
@@ -122,6 +126,7 @@ $(objpfx)tst-codeset.out: $(objpfx)tst-gettext.out
 $(objpfx)tst-gettext3.out: $(objpfx)tst-gettext.out
 $(objpfx)tst-gettext4.out: $(objpfx)tst-gettext.out
 $(objpfx)tst-gettext5.out: $(objpfx)tst-gettext.out
+$(objpfx)tst-gettext6.out: $(objpfx)tst-gettext.out
 
 CPPFLAGS += -D'LOCALEDIR="$(msgcatdir)"' \
 	    -D'LOCALE_ALIAS_PATH="$(msgcatdir)"'
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);
 
diff --git a/intl/tst-gettext6.c b/intl/tst-gettext6.c
new file mode 100644
index 0000000000..39611aa3b6
--- /dev/null
+++ b/intl/tst-gettext6.c
@@ -0,0 +1,86 @@
+/* Test that gettext() in multithreaded applications works correctly.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2008.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <libintl.h>
+#include <locale.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+pthread_barrier_t b;
+
+static void *
+tf (void *arg)
+{
+  pthread_barrier_wait (&b);
+  return gettext ("Operation not permitted");
+}
+
+int
+test (void)
+{
+  pthread_t th[4];
+  unsetenv ("LANGUAGE");
+  unsetenv ("OUTPUT_CHARSET");
+  textdomain ("tstgettext6");
+  bindtextdomain ("tstgettext6", OBJPFX "domaindir");
+  setlocale (LC_ALL, "ja_JP.UTF-8");
+  pthread_barrier_init (&b, NULL, 4);
+  for (int i = 0; i < 4; i++)
+    if (pthread_create (&th[i], NULL, tf, NULL))
+      {
+	puts ("pthread_create failed");
+	return 1;
+      }
+  for (int i = 0; i < 4; i++)
+    pthread_join (th[i], NULL);
+  return 0;
+}
+
+int
+main (void)
+{
+  for (int i = 0; i < 300; i++)
+    {
+      pid_t p = fork ();
+      if (p == -1)
+	{
+	  printf ("fork failed: %m\n");
+	  return 1;
+	}
+      if (p == 0)
+	_exit (test ());
+      int status;
+      wait (&status);
+      if (WIFEXITED (status) && WEXITSTATUS (status) != 0)
+	{
+	  printf ("child exited with %d\n", WEXITSTATUS (status));
+	  return 1;
+	}
+      else if (WIFSIGNALED (status))
+	{
+	  printf ("child killed by signal %d\n", WTERMSIG (status));
+	  return 1;
+	}
+    }
+  return 0;
+}
diff --git a/intl/tst-gettext6.sh b/intl/tst-gettext6.sh
new file mode 100644
index 0000000000..95e5ff91a8
--- /dev/null
+++ b/intl/tst-gettext6.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Test that gettext() in multithreaded applications works correctly.
+# Copyright (C) 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
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA.
+
+common_objpfx=$1
+run_program_prefix=$2
+objpfx=$3
+
+LC_ALL=C
+export LC_ALL
+
+# Create the domain directory.
+mkdir -p ${objpfx}domaindir/ja_JP/LC_MESSAGES
+# Populate it.
+msgfmt -o ${objpfx}domaindir/ja_JP/LC_MESSAGES/tstgettext6.mo ../po/ja.po
+
+GCONV_PATH=${common_objpfx}iconvdata
+export GCONV_PATH
+LOCPATH=${common_objpfx}localedata
+export LOCPATH
+
+${run_program_prefix} ${objpfx}tst-gettext6 > ${objpfx}tst-gettext6.out
+
+exit $?