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