bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new module 'duplocale'


From: Bruno Haible
Subject: Re: new module 'duplocale'
Date: Tue, 24 Nov 2009 10:46:33 +0100
User-agent: KMail/1.9.9

> +       base_name = nl_langinfo (_NL_LOCALE_NAME (LC_CTYPE));
> +       if (base_name[0] == '\0')
> +     /* Fallback code for glibc < 2.4, which did not implement
> +        nl_langinfo (_NL_LOCALE_NAME (category)).  */
> +     base_name = setlocale (LC_CTYPE, NULL);

Oops, the use of nl_langinfo was wrong in the first place. I'm extending the
unit test and applying this fix:


2009-11-24  Bruno Haible  <address@hidden>

        duplocale: Fix logic bug.
        * lib/duplocale.c: Don't include <langinfo.h>.
        (_NL_LOCALE_NAME): Remove macro.
        (rpl_duplocale): Use setlocale instead of nl_langinfo.
        * tests/test-duplocale.c (main): Also test duplocale after uselocale.

*** lib/duplocale.c.orig        2009-11-24 10:41:21.000000000 +0100
--- lib/duplocale.c     2009-11-24 10:40:48.000000000 +0100
***************
*** 22,36 ****
  #include <locale.h>
  
  #include <errno.h>
- #include <langinfo.h>
  #include <string.h>
  
- /* Work around an incorrect definition of the _NL_LOCALE_NAME macro in
-    glibc < 2.12.
-    See <http://sourceware.org/bugzilla/show_bug.cgi?id=10968>.  */
- #undef _NL_LOCALE_NAME
- #define _NL_LOCALE_NAME(category) _NL_ITEM ((category), _NL_ITEM_INDEX (-1))
- 
  #define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
  
  #undef duplocale
--- 22,29 ----
***************
*** 74,84 ****
        locale_t base_copy;
        unsigned int i;
  
!       base_name = nl_langinfo (_NL_LOCALE_NAME (LC_CTYPE));
!       if (base_name[0] == '\0')
!       /* Fallback code for glibc < 2.4, which did not implement
!          nl_langinfo (_NL_LOCALE_NAME (category)).  */
!       base_name = setlocale (LC_CTYPE, NULL);
        base_copy = newlocale (LC_ALL_MASK, base_name, NULL);
        if (base_copy == NULL)
        return NULL;
--- 67,73 ----
        locale_t base_copy;
        unsigned int i;
  
!       base_name = setlocale (LC_CTYPE, NULL);
        base_copy = newlocale (LC_ALL_MASK, base_name, NULL);
        if (base_copy == NULL)
        return NULL;
***************
*** 87,97 ****
        {
          int category = categories[i].cat;
          int category_mask = categories[i].mask;
!         const char *name = nl_langinfo (_NL_LOCALE_NAME (category));
!         if (name[0] == '\0')
!           /* Fallback code for glibc < 2.4, which did not implement
!              nl_langinfo (_NL_LOCALE_NAME (category)).  */
!           name = setlocale (category, NULL);
          if (strcmp (name, base_name) != 0)
            {
              locale_t copy = newlocale (category_mask, name, base_copy);
--- 76,82 ----
        {
          int category = categories[i].cat;
          int category_mask = categories[i].mask;
!         const char *name = setlocale (category, NULL);
          if (strcmp (name, base_name) != 0)
            {
              locale_t copy = newlocale (category_mask, name, base_copy);
*** tests/test-duplocale.c.orig 2009-11-24 10:41:21.000000000 +0100
--- tests/test-duplocale.c      2009-11-24 10:37:06.000000000 +0100
***************
*** 64,70 ****
  main ()
  {
    struct locale_dependent_values expected_results;
!   locale_t mixed;
  
    /* Set up a locale which is a mix between different system locales.  */
    setlocale (LC_ALL, "en_US.UTF-8");
--- 64,71 ----
  main ()
  {
    struct locale_dependent_values expected_results;
!   locale_t mixed1;
!   locale_t mixed2;
  
    /* Set up a locale which is a mix between different system locales.  */
    setlocale (LC_ALL, "en_US.UTF-8");
***************
*** 73,90 ****
    get_locale_dependent_values (&expected_results);
  
    /* Save the locale in a locale_t object.  */
!   mixed = duplocale (LC_GLOBAL_LOCALE);
!   ASSERT (mixed != NULL);
  
    /* Set up a default locale.  */
    setlocale (LC_ALL, "C");
    {
      struct locale_dependent_values c_results;
      get_locale_dependent_values (&c_results);
    }
  
!   /* Now use the saved locale again.  */
!   uselocale (mixed);
    {
      struct locale_dependent_values results;
      get_locale_dependent_values (&results);
--- 74,113 ----
    get_locale_dependent_values (&expected_results);
  
    /* Save the locale in a locale_t object.  */
!   mixed1 = duplocale (LC_GLOBAL_LOCALE);
!   ASSERT (mixed1 != NULL);
! 
!   /* Use a per-thread locale.  */
!   uselocale (newlocale (LC_ALL_MASK, "es_ES.UTF-8", NULL));
! 
!   /* Save the locale in a locale_t object again.  */
!   mixed2 = duplocale (LC_GLOBAL_LOCALE);
!   ASSERT (mixed2 != NULL);
  
    /* Set up a default locale.  */
    setlocale (LC_ALL, "C");
+   uselocale (LC_GLOBAL_LOCALE);
    {
      struct locale_dependent_values c_results;
      get_locale_dependent_values (&c_results);
    }
  
!   /* Now use the saved locale mixed1 again.  */
!   setlocale (LC_ALL, "C");
!   uselocale (LC_GLOBAL_LOCALE);
!   uselocale (mixed1);
!   {
!     struct locale_dependent_values results;
!     get_locale_dependent_values (&results);
!     ASSERT (strcmp (results.monetary, expected_results.monetary) == 0);
!     ASSERT (strcmp (results.numeric, expected_results.numeric) == 0);
!     ASSERT (strcmp (results.time, expected_results.time) == 0);
!   }
! 
!   /* Now use the saved locale mixed2 again.  */
!   setlocale (LC_ALL, "C");
!   uselocale (LC_GLOBAL_LOCALE);
!   uselocale (mixed2);
    {
      struct locale_dependent_values results;
      get_locale_dependent_values (&results);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]