00db10
The upstream patch is backported by excluding a dependency in
00db10
stdlib/Makefile whose task is to ensure that locales are generated before
00db10
the relevant tests are run. The dependency was added in order to fix
00db10
SWBZ#18969 which is triggered when running `make check' for a specific
00db10
subdirectory (stdlib here). Instead of this, the locales necessary for the
00db10
test are generated via an addition in localedata/Makefile.
00db10
00db10
commit 985fc132f23dbb83de76c5af9e783ef1b5900148
00db10
Author: Florian Weimer <fweimer@redhat.com>
00db10
Date:   Mon Apr 4 15:18:13 2016 +0200
00db10
00db10
    strfmon_l: Use specified locale for number formatting [BZ #19633]
00db10
00db10
Index: b/include/printf.h
00db10
===================================================================
00db10
--- a/include/printf.h
00db10
+++ b/include/printf.h
00db10
@@ -1,6 +1,7 @@
00db10
 #ifndef	_PRINTF_H
00db10
 
00db10
 #include <stdio-common/printf.h>
00db10
+#include <xlocale.h>
00db10
 
00db10
 /* Now define the internal interfaces.  */
00db10
 extern int __printf_fphex (FILE *, const struct printf_info *,
00db10
@@ -8,5 +9,8 @@ extern int __printf_fphex (FILE *, const
00db10
 extern int __printf_fp (FILE *, const struct printf_info *,
00db10
 			const void *const *);
00db10
 libc_hidden_proto (__printf_fp)
00db10
+extern int __printf_fp_l (FILE *, locale_t, const struct printf_info *,
00db10
+			  const void *const *);
00db10
+libc_hidden_proto (__printf_fp_l)
00db10
 
00db10
 #endif
00db10
Index: b/locale/localeinfo.h
00db10
===================================================================
00db10
--- a/locale/localeinfo.h
00db10
+++ b/locale/localeinfo.h
00db10
@@ -290,6 +290,27 @@ extern __thread struct __locale_data *co
00db10
 
00db10
 #endif
00db10
 
00db10
+/* Extract CATEGORY locale's string for ITEM.  */
00db10
+static inline const char *
00db10
+_nl_lookup (locale_t l, int category, int item)
00db10
+{
00db10
+  return l->__locales[category]->values[_NL_ITEM_INDEX (item)].string;
00db10
+}
00db10
+
00db10
+/* Extract CATEGORY locale's wide string for ITEM.  */
00db10
+static inline const wchar_t *
00db10
+_nl_lookup_wstr (locale_t l, int category, int item)
00db10
+{
00db10
+  return (wchar_t *) l->__locales[category]
00db10
+    ->values[_NL_ITEM_INDEX (item)].wstr;
00db10
+}
00db10
+
00db10
+/* Extract the CATEGORY locale's word for ITEM.  */
00db10
+static inline uint32_t
00db10
+_nl_lookup_word (locale_t l, int category, int item)
00db10
+{
00db10
+  return l->__locales[category]->values[_NL_ITEM_INDEX (item)].word;
00db10
+}
00db10
 
00db10
 /* Default search path if no LOCPATH environment variable.  */
00db10
 extern const char _nl_default_locale_path[] attribute_hidden;
00db10
Index: b/stdio-common/printf_fp.c
00db10
===================================================================
00db10
--- a/stdio-common/printf_fp.c
00db10
+++ b/stdio-common/printf_fp.c
00db10
@@ -153,9 +153,9 @@ static wchar_t *group_number (wchar_t *b
00db10
 
00db10
 
00db10
 int
00db10
-___printf_fp (FILE *fp,
00db10
-	      const struct printf_info *info,
00db10
-	      const void *const *args)
00db10
+___printf_fp_l (FILE *fp, locale_t loc,
00db10
+		const struct printf_info *info,
00db10
+		const void *const *args)
00db10
 {
00db10
   /* The floating-point value to output.  */
00db10
   union
00db10
@@ -263,18 +263,19 @@ ___printf_fp (FILE *fp,
00db10
   /* Figure out the decimal point character.  */
00db10
   if (info->extra == 0)
00db10
     {
00db10
-      decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
00db10
-      decimalwc = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
00db10
+      decimal = _nl_lookup (loc, LC_NUMERIC, DECIMAL_POINT);
00db10
+      decimalwc = _nl_lookup_word
00db10
+	(loc, LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
00db10
     }
00db10
   else
00db10
     {
00db10
-      decimal = _NL_CURRENT (LC_MONETARY, MON_DECIMAL_POINT);
00db10
+      decimal = _nl_lookup (loc, LC_MONETARY, MON_DECIMAL_POINT);
00db10
       if (*decimal == '\0')
00db10
-	decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
00db10
-      decimalwc = _NL_CURRENT_WORD (LC_MONETARY,
00db10
+	decimal = _nl_lookup (loc, LC_NUMERIC, DECIMAL_POINT);
00db10
+      decimalwc = _nl_lookup_word (loc, LC_MONETARY,
00db10
 				    _NL_MONETARY_DECIMAL_POINT_WC);
00db10
       if (decimalwc == L'\0')
00db10
-	decimalwc = _NL_CURRENT_WORD (LC_NUMERIC,
00db10
+	decimalwc = _nl_lookup_word (loc, LC_NUMERIC,
00db10
 				      _NL_NUMERIC_DECIMAL_POINT_WC);
00db10
     }
00db10
   /* The decimal point character must not be zero.  */
00db10
@@ -284,9 +285,9 @@ ___printf_fp (FILE *fp,
00db10
   if (info->group)
00db10
     {
00db10
       if (info->extra == 0)
00db10
-	grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
00db10
+	grouping = _nl_lookup (loc, LC_NUMERIC, GROUPING);
00db10
       else
00db10
-	grouping = _NL_CURRENT (LC_MONETARY, MON_GROUPING);
00db10
+	grouping = _nl_lookup (loc, LC_MONETARY, MON_GROUPING);
00db10
 
00db10
       if (*grouping <= 0 || *grouping == CHAR_MAX)
00db10
 	grouping = NULL;
00db10
@@ -296,19 +297,20 @@ ___printf_fp (FILE *fp,
00db10
 	  if (wide)
00db10
 	    {
00db10
 	      if (info->extra == 0)
00db10
-		thousands_sepwc =
00db10
-		  _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_THOUSANDS_SEP_WC);
00db10
+		thousands_sepwc = _nl_lookup_word
00db10
+		  (loc, LC_NUMERIC, _NL_NUMERIC_THOUSANDS_SEP_WC);
00db10
 	      else
00db10
 		thousands_sepwc =
00db10
-		  _NL_CURRENT_WORD (LC_MONETARY,
00db10
+		  _nl_lookup_word (loc, LC_MONETARY,
00db10
 				    _NL_MONETARY_THOUSANDS_SEP_WC);
00db10
 	    }
00db10
 	  else
00db10
 	    {
00db10
 	      if (info->extra == 0)
00db10
-		thousands_sep = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
00db10
+		thousands_sep = _nl_lookup (loc, LC_NUMERIC, THOUSANDS_SEP);
00db10
 	      else
00db10
-		thousands_sep = _NL_CURRENT (LC_MONETARY, MON_THOUSANDS_SEP);
00db10
+		thousands_sep = _nl_lookup
00db10
+		  (loc, LC_MONETARY, MON_THOUSANDS_SEP);
00db10
 	    }
00db10
 
00db10
 	  if ((wide && thousands_sepwc == L'\0')
00db10
@@ -1170,9 +1172,11 @@ ___printf_fp (FILE *fp,
00db10
 	  size_t decimal_len;
00db10
 	  size_t thousands_sep_len;
00db10
 	  wchar_t *copywc;
00db10
-	  size_t factor = (info->i18n
00db10
-			   ? _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX)
00db10
-			   : 1);
00db10
+	  size_t factor;
00db10
+	  if (info->i18n)
00db10
+	    factor = _nl_lookup_word (loc, LC_CTYPE, _NL_CTYPE_MB_CUR_MAX);
00db10
+	  else
00db10
+	    factor = 1;
00db10
 
00db10
 	  decimal_len = strlen (decimal);
00db10
 
00db10
@@ -1243,8 +1247,18 @@ ___printf_fp (FILE *fp,
00db10
   }
00db10
   return done;
00db10
 }
00db10
+ldbl_hidden_def (___printf_fp_l, __printf_fp_l)
00db10
+ldbl_strong_alias (___printf_fp_l, __printf_fp_l)
00db10
+
00db10
+int
00db10
+___printf_fp (FILE *fp, const struct printf_info *info,
00db10
+	      const void *const *args)
00db10
+{
00db10
+  return ___printf_fp_l (fp, _NL_CURRENT_LOCALE, info, args);
00db10
+}
00db10
 ldbl_hidden_def (___printf_fp, __printf_fp)
00db10
 ldbl_strong_alias (___printf_fp, __printf_fp)
00db10
+
00db10
 
00db10
 /* Return the number of extra grouping characters that will be inserted
00db10
    into a number with INTDIG_MAX integer digits.  */
00db10
Index: b/stdlib/Makefile
00db10
===================================================================
00db10
--- a/stdlib/Makefile
00db10
+++ b/stdlib/Makefile
00db10
@@ -71,7 +71,7 @@ tests		:= tst-strtol tst-strtod testmb t
00db10
 		   tst-qsort2 tst-makecontext2 tst-strtod6 tst-unsetenv1    \
00db10
 		   tst-makecontext3 bug-getcontext bug-fmtmsg1		    \
00db10
 		   tst-secure-getenv tst-strtod-overflow tst-strtod-round   \
00db10
-		   tst-tininess tst-strtod-underflow
00db10
+		   tst-tininess tst-strtod-underflow tst-strfmon_l
00db10
 tests-static	:= tst-secure-getenv
00db10
 
00db10
 include ../Makeconfig
00db10
Index: b/stdlib/strfmon_l.c
00db10
===================================================================
00db10
--- a/stdlib/strfmon_l.c
00db10
+++ b/stdlib/strfmon_l.c
00db10
@@ -68,9 +68,6 @@
00db10
 #define _NL_CURRENT(category, item) \
00db10
   (current->values[_NL_ITEM_INDEX (item)].string)
00db10
 
00db10
-extern int __printf_fp (FILE *, const struct printf_info *,
00db10
-			const void *const *);
00db10
-libc_hidden_proto (__printf_fp)
00db10
 /* This function determines the number of digit groups in the output.
00db10
    The definition is in printf_fp.c.  */
00db10
 extern unsigned int __guess_grouping (unsigned int intdig_max,
00db10
@@ -532,7 +529,7 @@ __vstrfmon_l (char *s, size_t maxsize, _
00db10
       info.extra = 1;		/* This means use values from LC_MONETARY.  */
00db10
 
00db10
       ptr = &fpnum;
00db10
-      done = __printf_fp (&f._sbf._f, &info, &ptr);
00db10
+      done = __printf_fp_l (&f._sbf._f, loc, &info, &ptr);
00db10
       if (done < 0)
00db10
 	return -1;
00db10
 
00db10
Index: b/stdlib/tst-strfmon_l.c
00db10
===================================================================
00db10
--- /dev/null
00db10
+++ b/stdlib/tst-strfmon_l.c
00db10
@@ -0,0 +1,220 @@
00db10
+/* Test locale dependence of strfmon_l.
00db10
+   Copyright (C) 2016 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#include <stdbool.h>
00db10
+#include <stdio.h>
00db10
+#include <monetary.h>
00db10
+#include <string.h>
00db10
+#include <stdlib.h>
00db10
+#include <locale.h>
00db10
+
00db10
+static const char *const en_us_name = "en_US.ISO-8859-1";
00db10
+
00db10
+/* Locale value to be used by tests.  */
00db10
+static locale_t loc;
00db10
+static const char *loc_name;
00db10
+
00db10
+/* Set the global locale to GLOBAL_NAME, and the locale referenced by
00db10
+   the loc variable above to LOCAL_NAME.  */
00db10
+static void
00db10
+init_loc (const char *global_name, const char *local_name)
00db10
+{
00db10
+  loc = newlocale (LC_ALL_MASK, local_name, 0);
00db10
+  if (loc == 0)
00db10
+    {
00db10
+      printf ("error: newlocale (%s): %m\n", local_name);
00db10
+      abort ();
00db10
+    }
00db10
+  loc_name = local_name;
00db10
+
00db10
+  if (setlocale (LC_ALL, global_name) == NULL)
00db10
+    {
00db10
+      printf ("error: setlocale (%s): %m\n", global_name);
00db10
+      abort ();
00db10
+    }
00db10
+}
00db10
+
00db10
+/* Expected strings for a positive or negative value.  */
00db10
+struct testcase
00db10
+{
00db10
+  const char *i;                /* %i */
00db10
+  const char *n;                /* %n */
00db10
+  const char *i_ungrouped;      /* %^i */
00db10
+  const char *n_ungrouped;      /* %^n */
00db10
+};
00db10
+
00db10
+/* Collected expected strings for both positive and negative
00db10
+   values.  */
00db10
+struct testcase_pair
00db10
+{
00db10
+  struct testcase positive;     /* 1234567.89 */
00db10
+  struct testcase negative;     /* -1234567.89 */
00db10
+};
00db10
+
00db10
+static bool errors;
00db10
+
00db10
+/* Test one value using the locale loc.  */
00db10
+static void
00db10
+test_one (const char *format, double value, const char *expected)
00db10
+{
00db10
+  static char actual[64];
00db10
+  int result = strfmon_l (actual, sizeof (actual), loc, format, value);
00db10
+  if (result < 0)
00db10
+    {
00db10
+      printf ("error: locale %s, format \"%s\", value %g: strfmon_l: %m\n",
00db10
+              loc_name, format, value);
00db10
+      errors = true;
00db10
+    }
00db10
+  else if (strcmp (actual, expected) != 0)
00db10
+    {
00db10
+      printf ("error: locale %s, format \"%s\", value %g: mismatch\n",
00db10
+              loc_name, format, value);
00db10
+      printf ("error:   expected: \"%s\"\n", expected);
00db10
+      printf ("error:   actual:   \"%s\"\n", actual);
00db10
+      errors = true;
00db10
+    }
00db10
+}
00db10
+
00db10
+static void
00db10
+test_pair (const struct testcase_pair *pair)
00db10
+{
00db10
+  double positive = 1234567.89;
00db10
+  test_one ("%i", positive, pair->positive.i);
00db10
+  test_one ("%n", positive, pair->positive.n);
00db10
+  test_one ("%^i", positive, pair->positive.i_ungrouped);
00db10
+  test_one ("%^n", positive, pair->positive.n_ungrouped);
00db10
+  double negative = -1234567.89;
00db10
+  test_one ("%i", negative, pair->negative.i);
00db10
+  test_one ("%n", negative, pair->negative.n);
00db10
+  test_one ("%^i", negative, pair->negative.i_ungrouped);
00db10
+  test_one ("%^n", negative, pair->negative.n_ungrouped);
00db10
+}
00db10
+
00db10
+static const struct testcase_pair en_us =
00db10
+  {
00db10
+    {
00db10
+      "USD 1,234,567.89", "$1,234,567.89",
00db10
+      "USD 1234567.89", "$1234567.89"
00db10
+    },
00db10
+    {
00db10
+      "-USD 1,234,567.89", "-$1,234,567.89",
00db10
+      "-USD 1234567.89", "-$1234567.89"
00db10
+    }
00db10
+  };
00db10
+
00db10
+static void
00db10
+test_en_us (const char *other_name)
00db10
+{
00db10
+  init_loc (other_name, en_us_name);
00db10
+  test_pair (&en_us);
00db10
+  freelocale (loc);
00db10
+}
00db10
+
00db10
+struct locale_pair
00db10
+{
00db10
+  const char *locale_name;
00db10
+  struct testcase_pair pair;
00db10
+};
00db10
+
00db10
+static const struct locale_pair tests[] =
00db10
+  {
00db10
+    {
00db10
+      "de_DE.UTF-8",
00db10
+      {
00db10
+        {
00db10
+         "1.234.567,89 EUR", "1.234.567,89 \u20ac",
00db10
+         "1234567,89 EUR", "1234567,89 \u20ac"
00db10
+        },
00db10
+        {
00db10
+         "-1.234.567,89 EUR", "-1.234.567,89 \u20ac",
00db10
+         "-1234567,89 EUR", "-1234567,89 \u20ac"
00db10
+        }
00db10
+      },
00db10
+    },
00db10
+    {
00db10
+      "tg_TJ.UTF-8",
00db10
+      {
00db10
+        {
00db10
+          "1 234 567.89 TJS", "1 234 567.89 \u0440\u0443\u0431",
00db10
+          "1234567.89 TJS", "1234567.89 \u0440\u0443\u0431"
00db10
+        },
00db10
+        {
00db10
+          "-1 234 567.89 TJS", "-1 234 567.89 \u0440\u0443\u0431",
00db10
+          "-1234567.89 TJS", "-1234567.89 \u0440\u0443\u0431"
00db10
+        }
00db10
+      }
00db10
+    },
00db10
+    {
00db10
+      "te_IN.UTF-8",
00db10
+      {
00db10
+        {
00db10
+          "INR12,34,567.89", "\u20b912,34,567.89",
00db10
+          "INR1234567.89", "\u20b91234567.89"
00db10
+        },
00db10
+        {
00db10
+          "-INR12,34,567.89", "-\u20b912,34,567.89",
00db10
+          "-INR1234567.89", "-\u20b91234567.89"
00db10
+        }
00db10
+      }
00db10
+    },
00db10
+    {
00db10
+      "bn_IN.UTF-8",
00db10
+      {
00db10
+        {
00db10
+          "INR 12,345,67.89", "\u20b9 12,345,67.89",
00db10
+          "INR 1234567.89", "\u20b9 1234567.89"
00db10
+        },
00db10
+        {
00db10
+          "-INR 12,345,67.89", "-\u20b9 12,345,67.89",
00db10
+          "-INR 1234567.89", "-\u20b9 1234567.89"
00db10
+        }
00db10
+      }
00db10
+    },
00db10
+    {
00db10
+      "el_GR.UTF-8",
00db10
+      {
00db10
+        {
00db10
+          "1.234.567,89EUR", "1.234.567,89\u20ac",
00db10
+          "1234567,89EUR", "1234567,89\u20ac"
00db10
+        },
00db10
+        {
00db10
+          "-EUR1.234.567,89", "-\u20ac1.234.567,89",
00db10
+          "-EUR1234567,89", "-\u20ac1234567,89",
00db10
+        }
00db10
+      }
00db10
+    },
00db10
+    {}
00db10
+  };
00db10
+
00db10
+static int
00db10
+do_test (void)
00db10
+{
00db10
+  for (const struct locale_pair *test = tests;
00db10
+       test->locale_name != NULL; ++test)
00db10
+    {
00db10
+      init_loc (en_us_name, test->locale_name);
00db10
+      test_pair (&test->pair);
00db10
+      freelocale (loc);
00db10
+      test_en_us (test->locale_name);
00db10
+    }
00db10
+
00db10
+  return errors;
00db10
+}
00db10
+
00db10
+#define TEST_FUNCTION do_test ()
00db10
+#include "../test-skeleton.c"
00db10
Index: b/localedata/Makefile
00db10
===================================================================
00db10
--- a/localedata/Makefile
00db10
+++ b/localedata/Makefile
00db10
@@ -120,7 +120,7 @@ LOCALES := de_DE.ISO-8859-1 de_DE.UTF-8
00db10
 	   hr_HR.ISO-8859-2 sv_SE.ISO-8859-1 ja_JP.SJIS fr_FR.ISO-8859-1 \
00db10
 	   nb_NO.ISO-8859-1 nn_NO.ISO-8859-1 tr_TR.UTF-8 cs_CZ.UTF-8 \
00db10
 	   zh_TW.EUC-TW fa_IR.UTF-8 fr_FR.UTF-8 ja_JP.UTF-8 si_LK.UTF-8 \
00db10
-	   tr_TR.ISO-8859-9
00db10
+	   tr_TR.ISO-8859-9 tg_TJ.UTF-8 te_IN.UTF-8 bn_IN.UTF-8 el_GR.UTF-8
00db10
 LOCALE_SRCS := $(shell echo "$(LOCALES)"|sed 's/\([^ .]*\)[^ ]*/\1/g')
00db10
 CHARMAPS := $(shell echo "$(LOCALES)" | \
00db10
 		    sed -e 's/[^ .]*[.]\([^ ]*\)/\1/g' -e s/SJIS/SHIFT_JIS/g)