This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Change _M_convert_to_external to return bool
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: bkoz <bkoz at redhat dot com>
- Date: Sun, 11 May 2003 17:50:47 +0200
- Subject: [Patch] Change _M_convert_to_external to return bool
Hi,
this is the less controversial part of my small project of
turning _M_overflow to call _M_convert_to_external just one
time (instead of once for buffer + once for overflow char).
Tested x86-linux.
Ok?
Paolo.
//////////
2003-05-11 Paolo Carlini <pcarlini@unitus.it>
* include/std/std_fstream.h (_M_convert_to_external): Change
to return bool, take two less streamsize parameters.
* include/bits/fstream.tcc (_M_convert_to_external): Tweak
consistently definition.
(_M_overflow): Adjust call points.
* include/bits/fstream.tcc (_M_underflow): Wrap a long line.
diff -prN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
*** libstdc++-v3-orig/include/bits/fstream.tcc Sun May 11 06:20:55 2003
--- libstdc++-v3/include/bits/fstream.tcc Sun May 11 17:22:17 2003
*************** namespace std
*** 223,229 ****
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
if (__cvt.always_noconv())
{
! __elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_M_in_beg), _M_buf_size);
__ilen = __elen;
}
else
--- 223,230 ----
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
if (__cvt.always_noconv())
{
! __elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_M_in_beg),
! _M_buf_size);
__ilen = __elen;
}
else
*************** namespace std
*** 358,370 ****
}
template<typename _CharT, typename _Traits>
! void
basic_filebuf<_CharT, _Traits>::
! _M_convert_to_external(_CharT* __ibuf, streamsize __ilen,
! streamsize& __elen, streamsize& __plen)
{
const locale __loc = this->getloc();
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
if (__cvt.always_noconv() && __ilen)
{
--- 359,373 ----
}
template<typename _CharT, typename _Traits>
! bool
basic_filebuf<_CharT, _Traits>::
! _M_convert_to_external(_CharT* __ibuf, streamsize __ilen)
{
const locale __loc = this->getloc();
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
+ // Sizes of external and pending output.
+ streamsize __elen = 0;
+ streamsize __plen = 0;
if (__cvt.always_noconv() && __ilen)
{
*************** namespace std
*** 420,425 ****
--- 423,430 ----
}
}
}
+
+ return __elen && __elen == __plen;
}
template<typename _CharT, typename _Traits>
*************** namespace std
*** 433,442 ****
if (__testput || __testunbuffered)
{
- // Sizes of external and pending output.
- streamsize __elen = 0;
- streamsize __plen = 0;
-
// Need to restore current position. The position of the external
// byte sequence (_M_file) corresponds to _M_filepos, and we need
// to move it to _M_out_beg for the write.
--- 438,443 ----
*************** namespace std
*** 447,472 ****
}
// Convert internal buffer to external representation, output.
! // NB: In the unbuffered case, no internal buffer exists.
! if (!__testunbuffered)
! _M_convert_to_external(this->_M_out_beg,
! this->_M_out_lim - this->_M_out_beg,
! __elen, __plen);
!
! // Checks for codecvt.out failures and _M_file.xsputn failures,
! // respectively, inside _M_convert_to_external.
! if (__testunbuffered || (__elen && __elen == __plen))
{
// Convert pending sequence to external representation, output.
// If eof, then just attempt sync.
if (!traits_type::eq_int_type(__c, traits_type::eof()))
{
char_type __pending = traits_type::to_char_type(__c);
- _M_convert_to_external(&__pending, 1, __elen, __plen);
-
// User code must flush when switching modes (thus
// don't sync).
! if (__elen == __plen && __elen)
{
_M_set_indeterminate();
__ret = traits_type::not_eof(__c);
--- 448,466 ----
}
// Convert internal buffer to external representation, output.
! // NB: In the unbuffered case, no internal buffer exists.
! if (__testunbuffered || _M_convert_to_external(this->_M_out_beg,
! this->_M_out_lim
! - this->_M_out_beg))
{
// Convert pending sequence to external representation, output.
// If eof, then just attempt sync.
if (!traits_type::eq_int_type(__c, traits_type::eof()))
{
char_type __pending = traits_type::to_char_type(__c);
// User code must flush when switching modes (thus
// don't sync).
! if (_M_convert_to_external(&__pending, 1))
{
_M_set_indeterminate();
__ret = traits_type::not_eof(__c);
diff -prN libstdc++-v3-orig/include/std/std_fstream.h libstdc++-v3/include/std/std_fstream.h
*** libstdc++-v3-orig/include/std/std_fstream.h Sun May 11 06:20:56 2003
--- libstdc++-v3/include/std/std_fstream.h Sun May 11 16:33:33 2003
*************** namespace std
*** 353,360 ****
* @doctodo
* @endif
*/
! void
! _M_convert_to_external(char_type*, streamsize, streamsize&, streamsize&);
/**
* @brief Manipulates the buffer.
--- 353,360 ----
* @doctodo
* @endif
*/
! bool
! _M_convert_to_external(char_type*, streamsize);
/**
* @brief Manipulates the buffer.