[PATCH] STDCXX-970

2012-10-10 Thread Liviu Nicoara
The following patch cleans up most of the failures seen in the collation 
test. It does not fix the transform failures and libstd tests.


2012-10-10  Liviu Nicoara  lnico...@apache.org

Various fixes:

* tests/localization/22.locale.collate.cpp: removed unused
  macros, corrected assertions and their formatting. (c_xfrm):
  corrected use of safety buffers. (make_test_locale): used
  rw_create_locale, used the whole portable character
  set. (check_libc): split code, restored previous locales after
  test. (check_NUL): hard-coded positions of NUL characters.
Index: tests/localization/22.locale.collate.cpp
===
--- tests/localization/22.locale.collate.cpp(revision 1392832)
+++ tests/localization/22.locale.collate.cpp(working copy)
@@ -43,6 +43,9 @@
 #include rw_locale.h
 #include rw_process.h
 
+#define IGNORE0
+#define STR_SIZE  16
+#define LOCNAME_SIZE  256
 
 #if _RWSTD_PATH_SEP == '/'
 #  define SLASH /
@@ -59,10 +62,6 @@
 #define LOCALE_ROOT RWSTD_LOCALE_ROOT
 const char* locale_root;
 
-#define LC_COLLATE_SRC  LC_COLLATE.src
-#define LC_COLLATE_CM   LC_COLLATE.cm
-#define TEST_LOCALE_NAMEtest.locale
-
 /**/
 
 // These overloads are necessary in our template
@@ -77,18 +76,18 @@
 
 std::size_t c_xfrm (char* to, const char* from, std::size_t size)
 {
-char safety_buf [8];
+char safety_buf [8] = { 0 };
+
 if (0 == to  0 == size) {
 // prevent buggy implementations (such as MSVC 8) from trying
 // to write to the destination buffer even though it's 0 and
 // its size is zero (see stdcxx-69)
 to = safety_buf;
-*to = '\0';
 }
 
 std::size_t n = std::strxfrm (to, from, size);
 
-if (to)
+if (to  to != safety_buf)
 n = std::strlen (to);
 
 return n;
@@ -127,45 +126,42 @@
 
 std::size_t c_xfrm (wchar_t* to, const wchar_t* from, std::size_t size)
 {
+std::size_t n = 0;
+
 #if !defined (_MSC_VER) || _MSC_VER  1200
 
-wchar_t safety_buf [8];
+wchar_t safety_buf [8] = { 0 };
+
 if (0 == to  0 == size) {
 // prevent buggy implementations (such as MSVC 8) from trying
 // to write to the destination buffer even though it's 0 and
 // its size is zero (see stdcxx-69)
 to = safety_buf;
-*to = L'\0';
 }
 
-std::size_t n = std::wcsxfrm (to, from, size);
+n = std::wcsxfrm (to, from, size);
 
-if (to)
+if (to  to != safety_buf)
 n = std::wcslen (to);
 
 #else   // MSVC 6 and prior
 
 // working around an MSVC 6.0 libc bug (PR #26437)
-
 if (to) {
-std::size_t n = std::wcsxfrm (to, from, size);
-
+std::wcsxfrm (to, from, size);
 n = std::wcslen (to);
-
-return n;
 }
+else {
+wchar_t tmp [1024];
 
-wchar_t tmp [1024];
-
-std::size_t n = std::wcslen (from);
-
-_RWSTD_ASSERT (n  sizeof tmp / sizeof *tmp);
-
-std::wcscpy (tmp, from);
-
-std::wcsxfrm (tmp, from, sizeof tmp / sizeof *tmp);
-
-n = std::wcslen (tmp);
+n = std::wcslen (from);
+_RWSTD_ASSERT (n  sizeof tmp / sizeof *tmp);
+
+std::wcscpy (tmp, from);
+std::wcsxfrm (tmp, from, sizeof tmp / sizeof *tmp);
+
+n = std::wcslen (tmp);
+}
 
 #endif   // MSVC 6
 
@@ -226,7 +222,7 @@
 /**/
 
 template class charT
-/*static*/ void
+void
 gen_str (charT* str, std::size_t size)
 {
 // generate a random string with the given size
@@ -234,7 +230,7 @@
 return;
 
 // use ASCII characters in the printable range
-for (std::size_t i = 0; i != size - 1; ++i)
+for (std::size_t i = 0; i  size - 1; ++i)
 str [i] = ' ' + std::rand () % ('~' - ' ');
 
 str [size - 1] = charT ();
@@ -243,152 +239,165 @@
 /**/
 
 template class charT
-/*static*/ void
-check_libc (const char* charTname)
+void
+check_libc_locale (const char* charTname, char const* locname,
+   int (nfail) [3])
 {
-// the libc implementation of the library should act the same as
-// the c-library.  Go through all the locales, generate some random
-// strings and make sure that the following holds true:
-// transform acts like strxfrm and wcsxfrm,
-// compare acts like strcoll and wcscoll
+typedef std::char_traitscharT traits_type;
+typedef std::allocatorcharT allocator_type;
+typedef std::basic_string charT, traits_type, allocator_type string_type;
 
-int nfail [3] = { 0 };
+std::locale loc (locname);
 
-rw_info (0, __FILE__, __LINE__,
- libc std::collate%s::transform (), charTname);
+const std::collatecharT co =
+_STD_USE_FACET (std::collatecharT, loc);
 

[PATCH] STDCXX-1073

2012-10-10 Thread Liviu Nicoara

2012-10-10  Liviu Nicoara  lnico...@apache.org

* src/collate.cpp (__rw_strnxfrm): preserved embedded NULs

Index: src/collate.cpp
===
--- src/collate.cpp (revision 1392832)
+++ src/collate.cpp (working copy)
@@ -547,7 +547,7 @@
 
 _TRY {
 // resize the result string to fit itself plus the result
-// of the transformation including the terminatin NUL
+// of the transformation including the terminating NUL
 // appended by strxfrm()
 res.resize (res_size + dst_size + 1);
 }
@@ -557,36 +557,15 @@
 _RETHROW;
 }
 
-// transfor the source string up to the terminating NUL
-size_t xfrm_size =
-strxfrm (res [0] + res_size, psrc, dst_size + 1);
-
-#if defined _MSC_VER  _MSC_VER  1400
-// compute the correct value that should have been returned from
-// strxfrm() after the transformation has completed (MSVC strxfrm()
-// returns a bogus result; see PR #29935)
-xfrm_size = strlen (res [0] + res_size);
-#endif   // MSVC  8.0
-
-// increment the size of the result string by the number
-// of transformed characters excluding the terminating NUL
-// if strxfrm() transforms the empty string into the empty
-// string, keep the terminating NUL, otherwise drop it
-res_size += xfrm_size + (last  !*psrc  !xfrm_size);
-
-_TRY {
-res.resize (res_size);
-}
-_CATCH (...) {
-if (pbuf != buf)
-delete[] pbuf;
-_RETHROW;
-}
+strxfrm (res [0] + res_size, psrc, dst_size + 1);
 }
 
 if (pbuf != buf)
 delete[] pbuf;
 
+if (!res.empty ())
+res.resize (res.size () - 1);
+
 return res;
 }