Blame SOURCES/glibc-rh1307241-1.patch

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