This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Re: Doubts about uselocale semantics (aka, libstdc++/12859)


On Fri, Oct 31, 2003 at 03:36:37PM -0800, Roland McGrath wrote:
> No confusion, just a bug.  I've fixed it.  The bug affected ctype functions
> after uselocale (LC_GLOBAL_LOCALE), but not other uses of locale data.

I think we need testcases badly too.  I found just tst-ftime_l.c
which is testing it.  Here is Paolo's one:

2003-11-01  Jakub Jelinek  <jakub@redhat.com>

	* ctype/Makefile (tests): Add tst-uselocale.
	(tst-uselocale-ENV): New.
	* ctype/tst-uselocale.c: New test by
	Paolo Carlini <pcarlini@suse.de>.

--- libc/ctype/Makefile.jj	2002-09-01 20:26:06.000000000 +0200
+++ libc/ctype/Makefile	2003-11-01 11:31:00.000000000 +0100
@@ -25,6 +25,8 @@ headers	:= ctype.h
 routines	:= ctype ctype-extn ctype_l isctype
 aux		:= ctype-info
 
-tests	:= test_ctype
+tests	:= test_ctype tst-uselocale
 
 include ../Rules
+
+tst-uselocale-ENV = LOCPATH=${common-objpfx}localedata
--- libc/ctype/tst-uselocale.c.jj	2003-11-01 11:03:50.000000000 +0100
+++ libc/ctype/tst-uselocale.c	2003-11-01 11:40:02.000000000 +0100
@@ -0,0 +1,117 @@
+#include <ctype.h>
+#include <locale.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+  int ret = 0;
+
+  if (uselocale (NULL) != LC_GLOBAL_LOCALE)
+    {
+      puts ("initial locale not LC_GLOBAL_LOCALE");
+      ret = 1;
+    }
+
+  if (isalpha (0xE4))
+    {
+      puts ("isalpha (0xE4) != 0 for C locale");
+      ret = 1;
+    }
+
+  if (toupper (0xE4) != 0xE4)
+    {
+      puts ("toupper (0xE4) != 0xE4 for C locale");
+      ret = 1;
+    }
+
+  if (tolower (0xC4) != 0xC4)
+    {
+      puts ("tolower (0xC4) != 0xC4 for C locale");
+      ret = 1;
+    }
+
+  if (setlocale (LC_ALL, "de_DE.ISO-8859-1") == NULL)
+    {
+      puts ("setlocale failed: %m");
+      ret = 1;
+    }
+
+  if (!isalpha (0xE4))
+    {
+      puts ("isalpha (0xE4) == 0 for de_DE locale");
+      ret = 1;
+    }
+    
+  if (toupper (0xE4) != 0xC4)
+    {
+      puts ("toupper (0xE4) != 0xC4 for de_DE locale");
+      ret = 1;
+    }
+
+  if (tolower (0xC4) != 0xE4)
+    {
+      puts ("tolower (0xC4) != 0xE4 for de_DE locale");
+      ret = 1;
+    }
+
+  locale_t loc_new = newlocale (LC_ALL_MASK, "C", 0);
+  if (loc_new == NULL)
+    {
+      puts ("newlocale failed: %m");
+      ret = 1;
+    }
+
+  locale_t loc_old = uselocale (loc_new);
+  if (loc_old != LC_GLOBAL_LOCALE)
+    {
+      puts ("uselocale did not return LC_GLOBAL_LOCALE");
+      ret = 1;
+    }
+
+  if (isalpha (0xE4))
+    {
+      puts ("isalpha (0xE4) != 0 for C locale after uselocale");
+      ret = 1;
+    }
+       
+  if (toupper (0xE4) != 0xE4)
+    {
+      puts ("toupper (0xE4) != 0xE4 for C locale after uselocale");
+      ret = 1;
+    }
+
+  if (tolower (0xC4) != 0xC4)
+    {
+      puts ("tolower (0xC4) != 0xC4 for C locale after uselocale");
+      ret = 1;
+    }
+
+  if (uselocale (loc_old) != loc_new)
+    {
+      puts ("uselocale did not return previous locale");
+      ret = 1;
+    }
+
+  if (!isalpha (0xE4))
+    {
+      puts ("isalpha (0xE4) == 0 for de_DE locale after uselocale");
+      ret = 1;
+    }
+         
+  if (toupper (0xE4) != 0xC4)
+    {
+      puts ("toupper (0xE4) != 0xC4 for de_DE locale after uselocale");
+      ret = 1;
+    }
+
+  if (tolower (0xC4) != 0xE4)
+    {
+      puts ("tolower (0xC4) != 0xE4 for de_DE locale after uselocale");
+      ret = 1;
+    }
+
+  freelocale (loc_new);
+  return ret;
+}


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]