PR libstdc++/28277 (partial: ostream bits 1)

2006-07-15  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/28277 (partial: ostream bits 1)
	* include/bits/ostream.tcc (operator<<(basic_ostream<_CharT>&,
	const char*)): Avoid __builtin_alloca with no limit in the
	widening.
	* testsuite/27_io/basic_ostream/inserters_character/wchar_t/
	28277-1.cc: New.

From-SVN: r115485
This commit is contained in:
Paolo Carlini 2006-07-15 20:30:50 +00:00
parent b0d5d5de78
commit 6f0cb13801
3 changed files with 80 additions and 20 deletions

View File

@ -1,17 +1,26 @@
2006-07-15 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/28277 (partial: ostream bits 1)
* include/bits/ostream.tcc (operator<<(basic_ostream<_CharT>&,
const char*)): Avoid __builtin_alloca with no limit in the
widening.
* testsuite/27_io/basic_ostream/inserters_character/wchar_t/
28277-1.cc: New.
2006-07-14 Benjamin Kosnik <bkoz@redhat.com>
* acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): New.
* configure.ac: Use it.
* configure: Regenerated.
* config.h.in: Regenerated.
* configure.host: Simplify.
* include/bits/atomicity.h: Adjust macros.
* config/cpu/generic/atomicity.h: Move...
* config/cpu/generic/atomicity_mutex: New.
* config/cpu/generic/atomicity_mutex/atomicity.h: ...here.
* config/cpu/generic/atomic_builtins: Rename...
* config/cpu/generic/atomicity_builtins: ...to this.
* config/cpu/generic/atomicity_builtins/atomicity.h: Moved.
* acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): New.
* configure.ac: Use it.
* configure: Regenerated.
* config.h.in: Regenerated.
* configure.host: Simplify.
* include/bits/atomicity.h: Adjust macros.
* config/cpu/generic/atomicity.h: Move...
* config/cpu/generic/atomicity_mutex: New.
* config/cpu/generic/atomicity_mutex/atomicity.h: ...here.
* config/cpu/generic/atomic_builtins: Rename...
* config/cpu/generic/atomicity_builtins: ...to this.
* config/cpu/generic/atomicity_builtins/atomicity.h: Moved.
* config/cpu/mips/atomicity.h: Comment MIPS II requirement.
* scripts/testsuite_flags.in: Make --cxxflags reflect CXXFLAGS.

View File

@ -421,15 +421,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
typename __ostream_type::sentry __cerb(__out);
if (__cerb && __s)
{
size_t __clen = __traits_type::length(__s);
_CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
* __clen));
for (size_t __i = 0; __i < __clen; ++__i)
__ws[__i] = __out.widen(__s[__i]);
_CharT* __str = __ws;
_CharT* __ws = 0;
try
{
const size_t __clen = __traits_type::length(__s);
__ws = new _CharT[__clen];
for (size_t __i = 0; __i < __clen; ++__i)
__ws[__i] = __out.widen(__s[__i]);
_CharT* __str = __ws;
const streamsize __w = __out.width();
streamsize __len = static_cast<streamsize>(__clen);
if (__w > __len)
@ -444,9 +444,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
}
__out._M_write(__str, __len);
__out.width(0);
delete [] __ws;
}
catch(...)
{ __out._M_setstate(ios_base::badbit); }
{
delete [] __ws;
__out._M_setstate(ios_base::badbit);
}
}
else if (!__s)
__out.setstate(ios_base::badbit);

View File

@ -0,0 +1,46 @@
// 2006-07-15 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2006 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 27.6.2.5.4 basic_ostream character inserters
#include <ostream>
#include <sstream>
#include <testsuite_hooks.h>
// libstdc++/28277
void test01()
{
using namespace std;
bool test __attribute__((unused)) = true;
wostringstream oss_01;
const string str_01(5000000, 'a');
oss_01 << str_01.c_str();
VERIFY( oss_01.good() );
VERIFY( oss_01.str().size() == str_01.size() );
}
int main()
{
test01();
return 0;
}