PR libstdc++/17038 (partial)
2004-08-25 Paolo Carlini <pcarlini@suse.de> PR libstdc++/17038 (partial) * include/bits/locale_facets.tcc (time_put<>::do_put): Increase __maxlen to 128. * include/bits/locale_facets.h (class __timepunct): Add FIXME comment about _M_put. * config/locale/generic/time_members.cc (_M_put): Always null terminate __s. * config/locale/gnu/time_members.cc (_M_put): Likewise. * testsuite/22_locale/time_put/put/char/17038.cc: New. * testsuite/22_locale/time_put/put/wchar_t/17038.cc: New. From-SVN: r86586
This commit is contained in:
parent
6d1c50cce4
commit
cb79308987
7 changed files with 162 additions and 7 deletions
|
@ -1,3 +1,16 @@
|
|||
2004-08-25 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
PR libstdc++/17038 (partial)
|
||||
* include/bits/locale_facets.tcc (time_put<>::do_put): Increase
|
||||
__maxlen to 128.
|
||||
* include/bits/locale_facets.h (class __timepunct): Add FIXME
|
||||
comment about _M_put.
|
||||
* config/locale/generic/time_members.cc (_M_put): Always null
|
||||
terminate __s.
|
||||
* config/locale/gnu/time_members.cc (_M_put): Likewise.
|
||||
* testsuite/22_locale/time_put/put/char/17038.cc: New.
|
||||
* testsuite/22_locale/time_put/put/wchar_t/17038.cc: New.
|
||||
|
||||
2004-08-24 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* testsuite/27_io/basic_istringstream/rdbuf/wchar_t/2832.cc: New.
|
||||
|
|
|
@ -46,9 +46,12 @@ namespace std
|
|||
{
|
||||
char* __old = strdup(setlocale(LC_ALL, NULL));
|
||||
setlocale(LC_ALL, _M_name_timepunct);
|
||||
strftime(__s, __maxlen, __format, __tm);
|
||||
const size_t __len = strftime(__s, __maxlen, __format, __tm);
|
||||
setlocale(LC_ALL, __old);
|
||||
free(__old);
|
||||
// Make sure __s is null terminated.
|
||||
if (__len == 0)
|
||||
__s[0] = '\0';
|
||||
}
|
||||
|
||||
template<>
|
||||
|
@ -125,9 +128,12 @@ namespace std
|
|||
{
|
||||
char* __old = strdup(setlocale(LC_ALL, NULL));
|
||||
setlocale(LC_ALL, _M_name_timepunct);
|
||||
wcsftime(__s, __maxlen, __format, __tm);
|
||||
const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
|
||||
setlocale(LC_ALL, __old);
|
||||
free(__old);
|
||||
// Make sure __s is null terminated.
|
||||
if (__len == 0)
|
||||
__s[0] = L'\0';
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
|
@ -46,14 +46,18 @@ namespace std
|
|||
const tm* __tm) const
|
||||
{
|
||||
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
|
||||
__strftime_l(__s, __maxlen, __format, __tm, _M_c_locale_timepunct);
|
||||
const size_t __len = __strftime_l(__s, __maxlen, __format, __tm,
|
||||
_M_c_locale_timepunct);
|
||||
#else
|
||||
char* __old = strdup(setlocale(LC_ALL, NULL));
|
||||
setlocale(LC_ALL, _M_name_timepunct);
|
||||
strftime(__s, __maxlen, __format, __tm);
|
||||
const size_t __len = strftime(__s, __maxlen, __format, __tm);
|
||||
setlocale(LC_ALL, __old);
|
||||
free(__old);
|
||||
#endif
|
||||
// Make sure __s is null terminated.
|
||||
if (__len == 0)
|
||||
__s[0] = '\0';
|
||||
}
|
||||
|
||||
template<>
|
||||
|
@ -195,14 +199,18 @@ namespace std
|
|||
const tm* __tm) const
|
||||
{
|
||||
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
|
||||
__wcsftime_l(__s, __maxlen, __format, __tm, _M_c_locale_timepunct);
|
||||
const size_t __len = __wcsftime_l(__s, __maxlen, __format, __tm,
|
||||
_M_c_locale_timepunct);
|
||||
#else
|
||||
char* __old = strdup(setlocale(LC_ALL, NULL));
|
||||
setlocale(LC_ALL, _M_name_timepunct);
|
||||
wcsftime(__s, __maxlen, __format, __tm);
|
||||
const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
|
||||
setlocale(LC_ALL, __old);
|
||||
free(__old);
|
||||
#endif
|
||||
// Make sure __s is null terminated.
|
||||
if (__len == 0)
|
||||
__s[0] = L'\0';
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
|
@ -2834,6 +2834,8 @@ namespace std
|
|||
explicit
|
||||
__timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0);
|
||||
|
||||
// FIXME: for error checking purposes _M_put should return the return
|
||||
// value of strftime/wcsftime.
|
||||
void
|
||||
_M_put(_CharT* __s, size_t __maxlen, const _CharT* __format,
|
||||
const tm* __tm) const;
|
||||
|
|
|
@ -2246,7 +2246,7 @@ namespace std
|
|||
|
||||
// NB: This size is arbitrary. Should this be a data member,
|
||||
// initialized at construction?
|
||||
const size_t __maxlen = 64;
|
||||
const size_t __maxlen = 128;
|
||||
char_type* __res =
|
||||
static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen));
|
||||
|
||||
|
|
63
libstdc++-v3/testsuite/22_locale/time_put/put/char/17038.cc
Normal file
63
libstdc++-v3/testsuite/22_locale/time_put/put/char/17038.cc
Normal file
|
@ -0,0 +1,63 @@
|
|||
// 2004-08-25 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
// Copyright (C) 2004 Free Software Foundation
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// 22.2.5.3.1 time_put members
|
||||
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
// libstdc++/17038
|
||||
void test01()
|
||||
{
|
||||
using namespace std;
|
||||
typedef ostreambuf_iterator<char> iterator_type;
|
||||
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
// create "C" time objects
|
||||
tm time1 = { 0, 0, 12, 4, 3, 71, 0, 93, 0 };
|
||||
|
||||
// basic construction
|
||||
locale loc_c = locale::classic();
|
||||
locale loc_in = __gnu_test::try_named_locale("ta_IN");
|
||||
assert( loc_in != loc_c );
|
||||
|
||||
// create an ostream-derived object, cache the time_put facet
|
||||
ostringstream oss;
|
||||
oss.imbue(loc_in);
|
||||
const time_put<char>& tim_put =
|
||||
use_facet<time_put<char> >(oss.getloc());
|
||||
|
||||
iterator_type os_it01 = tim_put.put(oss.rdbuf(), oss, '*', &time1, 'c');
|
||||
string result1 = oss.str();
|
||||
|
||||
char time_buffer[128];
|
||||
setlocale(LC_ALL, "ta_IN");
|
||||
VERIFY( strftime(time_buffer, 128, "%c", &time1) );
|
||||
|
||||
VERIFY( result1 == time_buffer );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
// 2004-08-25 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
// Copyright (C) 2004 Free Software Foundation
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// 22.2.5.3.1 time_put members
|
||||
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
// libstdc++/17038
|
||||
void test01()
|
||||
{
|
||||
using namespace std;
|
||||
typedef ostreambuf_iterator<wchar_t> iterator_type;
|
||||
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
// create "C" time objects
|
||||
tm time1 = { 0, 0, 12, 4, 3, 71, 0, 93, 0 };
|
||||
|
||||
// basic construction
|
||||
locale loc_c = locale::classic();
|
||||
locale loc_in = __gnu_test::try_named_locale("ta_IN");
|
||||
assert( loc_in != loc_c );
|
||||
|
||||
// create an ostream-derived object, cache the time_put facet
|
||||
wostringstream oss;
|
||||
oss.imbue(loc_in);
|
||||
const time_put<wchar_t>& tim_put =
|
||||
use_facet<time_put<wchar_t> >(oss.getloc());
|
||||
|
||||
iterator_type os_it01 = tim_put.put(oss.rdbuf(), oss, L'*', &time1, 'c');
|
||||
wstring result1 = oss.str();
|
||||
|
||||
wchar_t time_buffer[128];
|
||||
setlocale(LC_ALL, "ta_IN");
|
||||
VERIFY( wcsftime(time_buffer, 128, L"%c", &time1) );
|
||||
|
||||
VERIFY( result1 == time_buffer );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue