This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Use of LC_ALL vs. __LC_LAST
- To: libc-alpha at sourceware dot cygnus dot com
- Subject: Use of LC_ALL vs. __LC_LAST
- From: Bruno Haible <haible at ilog dot fr>
- Date: Mon, 24 Jul 2000 18:27:40 +0200 (CEST)
It seems that when categories were added after LC_ALL, not all uses of LC_ALL
were changed to __LC_LAST. The following patch fixes this in two places:
- nl_langinfo (it would not accept any of the newly introduced values),
- __locale_struct in <xlocale.h>. I don't think binary compatibility
is an issue here, because the function __newlocale was quite broken
anyway, because libstdc++ is going for a major upgrade anyway and
because of the comment "Don't rely on it." in <xlocale.h>.
The third place, locale_file_list (static array too small), has
already been fixed by Mark.
2000-07-22 Bruno Haible <haible@clisp.cons.org>
* locale/nl_langinfo.c (nl_langinfo): Accept items belonging to the
new categories LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE,
LC_MEASUREMENT, LC_IDENTIFICATION.
* locale/xlocale.h (struct __locale_struct): Increase size of
__locales array.
* locale/duplocale.c (__duplocale): Copy newly added categories as
well.
* locale/freelocale.c (__freelocale): Free newly added categories.
* locale/newlocale.c (__newlocale): Fix typo in sanity check.
If a base is given, use it, don't simply return it.
*** glibc-20000714/locale/nl_langinfo.c.bak Wed Feb 16 14:12:20 2000
--- glibc-20000714/locale/nl_langinfo.c Sat Jul 22 18:35:51 2000
***************
*** 33,39 ****
unsigned int index = _NL_ITEM_INDEX (item);
const struct locale_data *data;
! if (category < 0 || category >= LC_ALL)
/* Bogus category: bogus item. */
return (char *) "";
--- 33,39 ----
unsigned int index = _NL_ITEM_INDEX (item);
const struct locale_data *data;
! if (category < 0 || category == LC_ALL || category >= __LC_LAST)
/* Bogus category: bogus item. */
return (char *) "";
*** glibc-20000714/locale/duplocale.c.bak Tue Sep 7 16:54:14 1999
--- glibc-20000714/locale/duplocale.c Sat Jul 22 18:56:49 2000
***************
*** 1,5 ****
/* Duplicate handle for selection of locales.
! Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
--- 1,5 ----
/* Duplicate handle for selection of locales.
! Copyright (C) 1997, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
***************
*** 42,53 ****
if (result != NULL)
{
int cnt;
! for (cnt = 0; cnt < LC_ALL; ++cnt)
! {
! result->__locales[cnt] = dataset->__locales[cnt];
! if (result->__locales[cnt]->usage_count < MAX_USAGE_COUNT)
! ++result->__locales[cnt]->usage_count;
! }
}
/* It's done. */
--- 42,54 ----
if (result != NULL)
{
int cnt;
! for (cnt = 0; cnt < __LC_LAST; ++cnt)
! if (cnt != LC_ALL)
! {
! result->__locales[cnt] = dataset->__locales[cnt];
! if (result->__locales[cnt]->usage_count < MAX_USAGE_COUNT)
! ++result->__locales[cnt]->usage_count;
! }
}
/* It's done. */
*** glibc-20000714/locale/freelocale.c.bak Tue Sep 7 16:54:15 1999
--- glibc-20000714/locale/freelocale.c Sat Jul 22 18:57:56 2000
***************
*** 1,5 ****
/* Free data allocated by a call to setlocale_r
! Copyright (C) 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
--- 1,5 ----
/* Free data allocated by a call to setlocale_r
! Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
***************
*** 37,44 ****
/* We modify global data. */
__libc_lock_lock (__libc_setlocale_lock);
! for (cnt = 0; cnt < LC_ALL; ++cnt)
! if (dataset->__locales[cnt]->usage_count != UNDELETABLE)
/* We can remove the data. */
_nl_remove_locale (cnt, dataset->__locales[cnt]);
--- 37,44 ----
/* We modify global data. */
__libc_lock_lock (__libc_setlocale_lock);
! for (cnt = 0; cnt < __LC_LAST; ++cnt)
! if (cnt != LC_ALL && dataset->__locales[cnt]->usage_count != UNDELETABLE)
/* We can remove the data. */
_nl_remove_locale (cnt, dataset->__locales[cnt]);
*** glibc-20000714/locale/newlocale.c.bak Thu Sep 30 20:16:41 1999
--- glibc-20000714/locale/newlocale.c Sat Jul 22 19:15:13 2000
***************
*** 1,5 ****
/* Return a reference to locale information record.
! Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
--- 1,5 ----
/* Return a reference to locale information record.
! Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
***************
*** 54,60 ****
category_mask = (1 << __LC_LAST) - 1 - (1 << LC_ALL);
/* Sanity check for CATEGORY argument. */
! if ((category_mask & ~((1 << LC_ALL) - 1 - (1 << LC_ALL))) != 0)
ERROR_RETURN;
/* `newlocale' does not support asking for the locale name. */
--- 54,60 ----
category_mask = (1 << __LC_LAST) - 1 - (1 << LC_ALL);
/* Sanity check for CATEGORY argument. */
! if ((category_mask & ~((1 << __LC_LAST) - 1 - (1 << LC_ALL))) != 0)
ERROR_RETURN;
/* `newlocale' does not support asking for the locale name. */
***************
*** 63,90 ****
/* Allocate memory for the result. */
if (base != NULL)
! {
! if (base != NULL)
! return base;
!
! result = *base;
! }
else
{
! /* Fill with pointers to C locale data to . */
for (cnt = 0; cnt < __LC_LAST; ++cnt)
if (cnt != LC_ALL)
result.__locales[cnt] = _nl_C[cnt];
! /* If no category is to be set we return BASE if available or a
! dataset using the C locale data. */
! if (category_mask == 0)
! {
! result_ptr = (__locale_t) malloc (sizeof (struct __locale_struct));
! *result_ptr = result;
! goto update;
! }
}
/* We perhaps really have to load some data. So we determine the
--- 63,87 ----
/* Allocate memory for the result. */
if (base != NULL)
! result = *base;
else
{
! /* Fill with pointers to C locale data. */
for (cnt = 0; cnt < __LC_LAST; ++cnt)
if (cnt != LC_ALL)
result.__locales[cnt] = _nl_C[cnt];
+ }
! /* If no category is to be set we return BASE if available or a
! dataset using the C locale data. */
! if (category_mask == 0)
! {
! result_ptr = (__locale_t) malloc (sizeof (struct __locale_struct));
! if (result_ptr == NULL)
! return NULL;
! *result_ptr = result;
! goto update;
}
/* We perhaps really have to load some data. So we determine the
***************
*** 175,186 ****
update:
{
union locale_data_value *ctypes = result_ptr->__locales[LC_CTYPE]->values;
! result_ptr->__ctype_b = (const unsigned short int *)
! (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_CLASS)] .string);
! result_ptr->__ctype_tolower = (const int *)
! (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER)].string);
! result_ptr->__ctype_toupper = (const int *)
! (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER)].string);
}
return result_ptr;
--- 172,183 ----
update:
{
union locale_data_value *ctypes = result_ptr->__locales[LC_CTYPE]->values;
! result_ptr->__ctype_b = (const unsigned short int *)
! (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_CLASS)].string);
! result_ptr->__ctype_tolower = (const int *)
! (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER)].string);
! result_ptr->__ctype_toupper = (const int *)
! (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER)].string);
}
return result_ptr;
*** glibc-20000714/locale/xlocale.h.bak Tue Sep 7 16:54:23 1999
--- glibc-20000714/locale/xlocale.h Sat Jul 22 20:31:52 2000
***************
*** 1,5 ****
/* Definition of locale datatype.
! Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
--- 1,5 ----
/* Definition of locale datatype.
! Copyright (C) 1997, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
***************
*** 27,33 ****
go away without warning. */
typedef struct __locale_struct
{
! struct locale_data *__locales[6]; /* XXX LC_ALL should be used here */
/* To increase the speed of this solution we add some special members. */
const unsigned short int *__ctype_b;
--- 27,34 ----
go away without warning. */
typedef struct __locale_struct
{
! /* Note: LC_ALL is not a valid index into this array. */
! struct locale_data *__locales[13]; /* 13 = __LC_LAST. */
/* To increase the speed of this solution we add some special members. */
const unsigned short int *__ctype_b;