You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Farid Zaripov <Fa...@epam.com> on 2007/11/14 19:10:09 UTC
[PATCH] 22.locale.ctype.is.cpp
The 22.locale.ctype.is.cpp test contains two functions: test_libc<>()
and test_libstd<>().
If I understand correctly, the test_libc<>() designed to check the
system locales (it
iterates the all locales, returned by rw_locales()), and test_libstd<>()
designed to
check the "test-locale" locale (created by rw_create_locale()).
First invoked test_libstd<char>(). From there invoked
rw_create_locale() function,
which set RWSTD_LOCALE_ROOT environment variable to the temporary
directory
with "test-locale" locale.
Then invoked test_libc<char>(). It invokes rw_locales(), which uses
"locale -a" command.
But locale utility, if RWSTD_LOCALE_ROOT environment variable is
defined, returns
list of the library locales. In this case it returns "C" and
"test-locale". Also rw_locales()
checks the locale names by invoking std::setlocale(). Of course
std::setlocale(LC_ALL, "test-locale")
fails and as a result the rw_locales returns "C\0\0" string.
The patch below resolves this situation by invoking first both
test_libc<char> and test_libc<wchar_t>
and then test_libstd<char> and test_libstd<wchar_t>.
ChangeLog:
* 22.locale.ctype.is.cpp (run_test<>): The compile time
checks moved to test_libstd(); The function run_test<>()
removed; The test_libstd() and test_libc() funtions are
invoked from non-template run_test() to invoke them in
the following order: test_libc<char>(), test_libc<wchar_t>(),
test_libstd<char>(), test_libstd<wchar_t>().
Index: 22.locale.ctype.is.cpp
===================================================================
--- 22.locale.ctype.is.cpp (revision 594578)
+++ 22.locale.ctype.is.cpp (working copy)
@@ -840,6 +840,12 @@
template <class charT>
void test_libstd (charT, const char *cname)
{
+ if (0) {
+ // do a compile time only test on use_facet and has_facet
+ _STD_HAS_FACET (std::ctype_byname<charT>, std::locale ());
+ _STD_USE_FACET (std::ctype_byname<charT>, std::locale ());
+ }
+
const char cmap_1[] = {
"<code_set_name> \"ANSI_X3.4-1968\"\n"
"<mb_cur_max> 1\n"
@@ -1025,27 +1031,15 @@
/***********************************************************************
***/
-template <class charT>
-void run_test (charT, const char *cname)
-{
- if (0) {
- // do a compile time only test on use_facet and has_facet
- _STD_HAS_FACET (std::ctype_byname<charT>, std::locale ());
- _STD_USE_FACET (std::ctype_byname<charT>, std::locale ());
- }
-
- test_libstd (charT (), cname);
- test_libc (charT (), cname);
-}
-
-/**********************************************************************
****/
-
static int
run_test (int, char**)
{
- run_test (char (), "char");
- run_test (wchar_t (), "wchar_t");
+ test_libc (char (), "char");
+ test_libc (wchar_t (), "wchar_t");
+ test_libstd (char (), "char");
+ test_libstd (wchar_t (), "wchar_t");
+
return 0;
}
Farid.
Re: [PATCH] 22.locale.ctype.is.cpp
Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>> -----Original Message-----
>> From: Martin Sebor [mailto:sebor@roguewave.com]
>> Sent: Monday, November 19, 2007 8:30 PM
>> To: stdcxx-dev@incubator.apache.org
>> Subject: Re: [PATCH] 22.locale.ctype.is.cpp
>>
>> Martin Sebor wrote:
>>> Seems reasonable. We should also guard the calls to the the wchar_t
>>> specializations of the function with _RWSTD_NO_WCHAR_T.
>> On second thought, isn't there a more robust way of fixing
>> this, one that makes it work regardless of the order of the
>> calls to the function? E.g., have the function that needs the
>> environment variable defined always define it and the one
>> that needs it undefined always undefine it?
>
> The environment variable is defined in rw_create_locale() by invoking
> rw_set_locale_root (). But rw_create_locale() designed to set
> environment
> variable and exec localedef utility only once.
That sounds like a design limitation of rw_create_locale(), don't
you think? It seems there should be a way to switch back to the libc
locale implementation...
>
> But we can save the variable value in test_libc(), then undefine it
> and
> restore the value at the end of the function.
...such as this :)
I guess this would work. Although I'm not sure I'm completely
comfortable with this approach either. It seems that the functions
shouldn't have to worry about these details (i.e., that some other
functions might have switched things around underneath them before
they were called). They should "just work" :) Maybe we should just
document the current behavior and be done with it. It's your call.
Martin
RE: [PATCH] 22.locale.ctype.is.cpp
Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:sebor@roguewave.com]
> Sent: Monday, November 19, 2007 8:30 PM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: [PATCH] 22.locale.ctype.is.cpp
>
> Martin Sebor wrote:
> > Seems reasonable. We should also guard the calls to the the wchar_t
> > specializations of the function with _RWSTD_NO_WCHAR_T.
>
> On second thought, isn't there a more robust way of fixing
> this, one that makes it work regardless of the order of the
> calls to the function? E.g., have the function that needs the
> environment variable defined always define it and the one
> that needs it undefined always undefine it?
The environment variable is defined in rw_create_locale() by invoking
rw_set_locale_root (). But rw_create_locale() designed to set
environment
variable and exec localedef utility only once.
But we can save the variable value in test_libc(), then undefine it
and
restore the value at the end of the function.
Farid.
Re: [PATCH] 22.locale.ctype.is.cpp
Posted by Martin Sebor <se...@roguewave.com>.
Martin Sebor wrote:
> Seems reasonable. We should also guard the calls to the the wchar_t
> specializations of the function with _RWSTD_NO_WCHAR_T.
On second thought, isn't there a more robust way of fixing this,
one that makes it work regardless of the order of the calls to
the function? E.g., have the function that needs the environment
variable defined always define it and the one that needs it
undefined always undefine it?
>
> Martin
>
>
> Farid Zaripov-2 wrote:
>> The 22.locale.ctype.is.cpp test contains two functions: test_libc<>()
>> and test_libstd<>().
>>
>> If I understand correctly, the test_libc<>() designed to check the
>> system locales (it
>> iterates the all locales, returned by rw_locales()), and test_libstd<>()
>> designed to
>> check the "test-locale" locale (created by rw_create_locale()).
>>
>> First invoked test_libstd<char>(). From there invoked
>> rw_create_locale() function,
>> which set RWSTD_LOCALE_ROOT environment variable to the temporary
>> directory
>> with "test-locale" locale.
>>
>> Then invoked test_libc<char>(). It invokes rw_locales(), which uses
>> "locale -a" command.
>> But locale utility, if RWSTD_LOCALE_ROOT environment variable is
>> defined, returns
>> list of the library locales. In this case it returns "C" and
>> "test-locale". Also rw_locales()
>> checks the locale names by invoking std::setlocale(). Of course
>> std::setlocale(LC_ALL, "test-locale")
>> fails and as a result the rw_locales returns "C\0\0" string.
>>
>> The patch below resolves this situation by invoking first both
>> test_libc<char> and test_libc<wchar_t>
>> and then test_libstd<char> and test_libstd<wchar_t>.
>>
>>
>> ChangeLog:
>> * 22.locale.ctype.is.cpp (run_test<>): The compile time
>> checks moved to test_libstd(); The function run_test<>()
>> removed; The test_libstd() and test_libc() funtions are
>> invoked from non-template run_test() to invoke them in
>> the following order: test_libc<char>(), test_libc<wchar_t>(),
>> test_libstd<char>(), test_libstd<wchar_t>().
>>
>>
>> Index: 22.locale.ctype.is.cpp
>> ===================================================================
>> --- 22.locale.ctype.is.cpp (revision 594578)
>> +++ 22.locale.ctype.is.cpp (working copy)
>> @@ -840,6 +840,12 @@
>> template <class charT>
>> void test_libstd (charT, const char *cname)
>> {
>> + if (0) {
>> + // do a compile time only test on use_facet and has_facet
>> + _STD_HAS_FACET (std::ctype_byname<charT>, std::locale ());
>> + _STD_USE_FACET (std::ctype_byname<charT>, std::locale ());
>> + }
>> +
>> const char cmap_1[] = {
>> "<code_set_name> \"ANSI_X3.4-1968\"\n"
>> "<mb_cur_max> 1\n"
>> @@ -1025,27 +1031,15 @@
>>
>>
>> /***********************************************************************
>> ***/
>>
>> -template <class charT>
>> -void run_test (charT, const char *cname)
>> -{
>> - if (0) {
>> - // do a compile time only test on use_facet and has_facet
>> - _STD_HAS_FACET (std::ctype_byname<charT>, std::locale ());
>> - _STD_USE_FACET (std::ctype_byname<charT>, std::locale ());
>> - }
>> -
>> - test_libstd (charT (), cname);
>> - test_libc (charT (), cname);
>> -}
>> -
>> -/**********************************************************************
>> ****/
>> -
>> static int
>> run_test (int, char**)
>> {
>> - run_test (char (), "char");
>> - run_test (wchar_t (), "wchar_t");
>> + test_libc (char (), "char");
>> + test_libc (wchar_t (), "wchar_t");
>>
>> + test_libstd (char (), "char");
>> + test_libstd (wchar_t (), "wchar_t");
>> +
>> return 0;
>> }
>>
>>
>>
>> Farid.
>>
>>
>
Re: [PATCH] 22.locale.ctype.is.cpp
Posted by Martin Sebor <se...@roguewave.com>.
Seems reasonable. We should also guard the calls to the the wchar_t
specializations of the function with _RWSTD_NO_WCHAR_T.
Martin
Farid Zaripov-2 wrote:
>
> The 22.locale.ctype.is.cpp test contains two functions: test_libc<>()
> and test_libstd<>().
>
> If I understand correctly, the test_libc<>() designed to check the
> system locales (it
> iterates the all locales, returned by rw_locales()), and test_libstd<>()
> designed to
> check the "test-locale" locale (created by rw_create_locale()).
>
> First invoked test_libstd<char>(). From there invoked
> rw_create_locale() function,
> which set RWSTD_LOCALE_ROOT environment variable to the temporary
> directory
> with "test-locale" locale.
>
> Then invoked test_libc<char>(). It invokes rw_locales(), which uses
> "locale -a" command.
> But locale utility, if RWSTD_LOCALE_ROOT environment variable is
> defined, returns
> list of the library locales. In this case it returns "C" and
> "test-locale". Also rw_locales()
> checks the locale names by invoking std::setlocale(). Of course
> std::setlocale(LC_ALL, "test-locale")
> fails and as a result the rw_locales returns "C\0\0" string.
>
> The patch below resolves this situation by invoking first both
> test_libc<char> and test_libc<wchar_t>
> and then test_libstd<char> and test_libstd<wchar_t>.
>
>
> ChangeLog:
> * 22.locale.ctype.is.cpp (run_test<>): The compile time
> checks moved to test_libstd(); The function run_test<>()
> removed; The test_libstd() and test_libc() funtions are
> invoked from non-template run_test() to invoke them in
> the following order: test_libc<char>(), test_libc<wchar_t>(),
> test_libstd<char>(), test_libstd<wchar_t>().
>
>
> Index: 22.locale.ctype.is.cpp
> ===================================================================
> --- 22.locale.ctype.is.cpp (revision 594578)
> +++ 22.locale.ctype.is.cpp (working copy)
> @@ -840,6 +840,12 @@
> template <class charT>
> void test_libstd (charT, const char *cname)
> {
> + if (0) {
> + // do a compile time only test on use_facet and has_facet
> + _STD_HAS_FACET (std::ctype_byname<charT>, std::locale ());
> + _STD_USE_FACET (std::ctype_byname<charT>, std::locale ());
> + }
> +
> const char cmap_1[] = {
> "<code_set_name> \"ANSI_X3.4-1968\"\n"
> "<mb_cur_max> 1\n"
> @@ -1025,27 +1031,15 @@
>
>
> /***********************************************************************
> ***/
>
> -template <class charT>
> -void run_test (charT, const char *cname)
> -{
> - if (0) {
> - // do a compile time only test on use_facet and has_facet
> - _STD_HAS_FACET (std::ctype_byname<charT>, std::locale ());
> - _STD_USE_FACET (std::ctype_byname<charT>, std::locale ());
> - }
> -
> - test_libstd (charT (), cname);
> - test_libc (charT (), cname);
> -}
> -
> -/**********************************************************************
> ****/
> -
> static int
> run_test (int, char**)
> {
> - run_test (char (), "char");
> - run_test (wchar_t (), "wchar_t");
> + test_libc (char (), "char");
> + test_libc (wchar_t (), "wchar_t");
>
> + test_libstd (char (), "char");
> + test_libstd (wchar_t (), "wchar_t");
> +
> return 0;
> }
>
>
>
> Farid.
>
>
--
View this message in context: http://www.nabble.com/-PATCH--22.locale.ctype.is.cpp-tf4807057.html#a13828139
Sent from the stdcxx-dev mailing list archive at Nabble.com.