This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Improve old fix for 11095
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 10 Oct 2003 19:12:33 +0200
- Subject: [v3] Improve old fix for 11095
Hi,
tested x86-linux, committed.
Paolo.
/////////
2003-10-10 Paolo Carlini <pcarlini@unitus.it>
* include/bits/ostream.tcc (operator<<(basic_ostream&, _CharT))
Avoid unnecessarily calling __builtin_alloca and dealing
explicitly with width() smaller than zero.
(operator<<(basic_ostream&, char), operator<<(basic_ostream&,
const _CharT*), operator<<(basic_ostream<_CharT, _Traits>&,
const char*), operator<<(basic_ostream<char, _Traits>&,
const char*), operator<<(basic_ostream, const basic_string&)):
Likewise.
diff -prN libstdc++-v3-orig/include/bits/ostream.tcc libstdc++-v3/include/bits/ostream.tcc
*** libstdc++-v3-orig/include/bits/ostream.tcc Tue Aug 12 05:46:17 2003
--- libstdc++-v3/include/bits/ostream.tcc Fri Oct 10 14:54:22 2003
*************** namespace std
*** 471,487 ****
{
try
{
! const streamsize __w = __out.width() > 0 ? __out.width() : 0;
! _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__w + 1)));
! __pads[0] = __c;
streamsize __len = 1;
if (__w > __len)
{
! __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads,
&__c, __w, __len, false);
__len = __w;
}
! __out._M_write(__pads, __len);
__out.width(0);
}
catch(...)
--- 471,488 ----
{
try
{
! const streamsize __w = __out.width();
streamsize __len = 1;
+ _CharT* __cs = &__c;
if (__w > __len)
{
! __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
! * __w));
! __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs,
&__c, __w, __len, false);
__len = __w;
}
! __out._M_write(__cs, __len);
__out.width(0);
}
catch(...)
*************** namespace std
*** 507,523 ****
{
try
{
! const streamsize __w = __out.width() > 0 ? __out.width() : 0;
! char* __pads = static_cast<char*>(__builtin_alloca(__w + 1));
! __pads[0] = __c;
streamsize __len = 1;
if (__w > __len)
{
! __pad<char, _Traits>::_S_pad(__out, __out.fill(), __pads,
&__c, __w, __len, false);
__len = __w;
}
! __out._M_write(__pads, __len);
__out.width(0);
}
catch(...)
--- 508,524 ----
{
try
{
! const streamsize __w = __out.width();
streamsize __len = 1;
+ char* __cs = &__c;
if (__w > __len)
{
! __cs = static_cast<char*>(__builtin_alloca(__w));
! __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs,
&__c, __w, __len, false);
__len = __w;
}
! __out._M_write(__cs, __len);
__out.width(0);
}
catch(...)
*************** namespace std
*** 542,555 ****
{
try
{
! const streamsize __w = __out.width() > 0 ? __out.width() : 0;
! _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
if (__w > __len)
{
! __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads,
__s, __w, __len, false);
! __s = __pads;
__len = __w;
}
__out._M_write(__s, __len);
--- 543,557 ----
{
try
{
! const streamsize __w = __out.width();
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
if (__w > __len)
{
! _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
! * __w));
! __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs,
__s, __w, __len, false);
! __s = __cs;
__len = __w;
}
__out._M_write(__s, __len);
*************** namespace std
*** 583,604 ****
if (__cerb && __s)
{
size_t __clen = __traits_type::length(__s);
! _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1)));
for (size_t __i = 0; __i < __clen; ++__i)
__ws[__i] = __out.widen(__s[__i]);
_CharT* __str = __ws;
try
{
streamsize __len = static_cast<streamsize>(__clen);
- const streamsize __w = __out.width() > 0 ? __out.width() : 0;
- _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
-
if (__w > __len)
{
! __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads,
__ws, __w, __len, false);
! __str = __pads;
__len = __w;
}
__out._M_write(__str, __len);
--- 585,607 ----
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;
try
{
+ const streamsize __w = __out.width();
streamsize __len = static_cast<streamsize>(__clen);
if (__w > __len)
{
! _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
! * __w));
! __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs,
__ws, __w, __len, false);
! __str = __cs;
__len = __w;
}
__out._M_write(__str, __len);
*************** namespace std
*** 629,643 ****
{
try
{
! const streamsize __w = __out.width() > 0 ? __out.width() : 0;
! char* __pads = static_cast<char*>(__builtin_alloca(__w));
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
-
if (__w > __len)
{
! __pad<char, _Traits>::_S_pad(__out, __out.fill(), __pads,
__s, __w, __len, false);
! __s = __pads;
__len = __w;
}
__out._M_write(__s, __len);
--- 632,645 ----
{
try
{
! const streamsize __w = __out.width();
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
if (__w > __len)
{
! char* __cs = static_cast<char*>(__builtin_alloca(__w));
! __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs,
__s, __w, __len, false);
! __s = __cs;
__len = __w;
}
__out._M_write(__s, __len);
*************** namespace std
*** 667,684 ****
typename __ostream_type::sentry __cerb(__out);
if (__cerb)
{
! const _CharT* __s = __str.data();
! const streamsize __w = __out.width() > 0 ? __out.width() : 0;
! _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
streamsize __len = static_cast<streamsize>(__str.size());
#ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
// 25. String operator<< uses width() value wrong
#endif
if (__w > __len)
{
! __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, __s,
__w, __len, false);
! __s = __pads;
__len = __w;
}
__out._M_write(__s, __len);
--- 669,687 ----
typename __ostream_type::sentry __cerb(__out);
if (__cerb)
{
! const streamsize __w = __out.width();
streamsize __len = static_cast<streamsize>(__str.size());
+ const _CharT* __s = __str.data();
#ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
// 25. String operator<< uses width() value wrong
#endif
if (__w > __len)
{
! _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
! * __w));
! __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s,
__w, __len, false);
! __s = __cs;
__len = __w;
}
__out._M_write(__s, __len);