This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] filebuf::_M_overflow tweaks
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, pcarlini at unitus dot i
- Date: Mon, 12 May 2003 14:10:04 -0400 (EDT)
- Subject: [v3] filebuf::_M_overflow tweaks
Removes unbuffered bits for overflow, some simplifications for
_M_convert. There is still no error checking for the convert bits,
which needs to change. Also, I'm going to look into unifying
overflow/underflow convert semantics, and cache the codecvt facet in
fileubuf. More later.
tested x86/linux
2003-05-12 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/fstream.tcc (_M_overflow): Remove unbuffered bits.
2003-05-12 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.
Index: include/bits/fstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.73
diff -c -p -r1.73 fstream.tcc
*** include/bits/fstream.tcc 11 May 2003 04:20:55 -0000 1.73
--- include/bits/fstream.tcc 12 May 2003 18:07:35 -0000
*************** namespace std
*** 182,188 ****
template<typename _CharT, typename _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type
! basic_filebuf<_CharT, _Traits>::_M_underflow(bool __bump)
{
int_type __ret = traits_type::eof();
const bool __testin = this->_M_mode & ios_base::in;
--- 182,189 ----
template<typename _CharT, typename _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type
! basic_filebuf<_CharT, _Traits>::
! _M_underflow(bool __bump)
{
int_type __ret = traits_type::eof();
const bool __testin = this->_M_mode & ios_base::in;
*************** namespace std
*** 333,338 ****
--- 334,386 ----
template<typename _CharT, typename _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type
basic_filebuf<_CharT, _Traits>::
+ _M_overflow(int_type __c)
+ {
+ int_type __ret = traits_type::eof();
+ const bool __testput = this->_M_out_beg < this->_M_out_lim;
+
+ if (__testput)
+ {
+ // 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.
+ if (_M_filepos && _M_filepos != this->_M_out_beg)
+ {
+ off_type __off = this->_M_out_beg - _M_filepos;
+ _M_file.seekoff(__off, ios_base::cur);
+ }
+
+ // Convert internal buffer to external representation, output.
+ if (_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()))
+ {
+ // User code must flush when switching modes (thus
+ // don't sync).
+ char_type __pending = traits_type::to_char_type(__c);
+ if (_M_convert_to_external(&__pending, 1))
+ {
+ _M_set_indeterminate();
+ __ret = traits_type::not_eof(__c);
+ }
+ }
+ else if (!_M_file.sync())
+ {
+ _M_set_indeterminate();
+ __ret = traits_type::not_eof(__c);
+ }
+ }
+ }
+ _M_last_overflowed = true;
+ return __ret;
+ }
+
+ template<typename _CharT, typename _Traits>
+ typename basic_filebuf<_CharT, _Traits>::int_type
+ basic_filebuf<_CharT, _Traits>::
overflow(int_type __c)
{
int_type __ret = traits_type::eof();
*************** namespace std
*** 358,371 ****
}
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)
{
__elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), __ilen);
--- 406,421 ----
}
template<typename _CharT, typename _Traits>
! bool
basic_filebuf<_CharT, _Traits>::
! _M_convert_to_external(_CharT* __ibuf, streamsize __ilen)
{
+ // Sizes of external and pending output.
+ streamsize __elen = 0;
+ streamsize __plen = 0;
+
const locale __loc = this->getloc();
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
if (__cvt.always_noconv() && __ilen)
{
__elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), __ilen);
*************** namespace std
*** 420,486 ****
}
}
}
- }
-
- template<typename _CharT, typename _Traits>
- typename basic_filebuf<_CharT, _Traits>::int_type
- basic_filebuf<_CharT, _Traits>::
- _M_overflow(int_type __c)
- {
- int_type __ret = traits_type::eof();
- const bool __testput = this->_M_out_beg < this->_M_out_lim;
- const bool __testunbuffered = _M_file.is_open() && !this->_M_buf_size;
-
- 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.
! if (_M_filepos && _M_filepos != this->_M_out_beg)
! {
! off_type __off = this->_M_out_beg - _M_filepos;
! _M_file.seekoff(__off, ios_base::cur);
! }
!
! // 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);
! }
! }
! else if (!_M_file.sync())
! {
! _M_set_indeterminate();
! __ret = traits_type::not_eof(__c);
! }
! }
! }
! _M_last_overflowed = true;
! return __ret;
}
template<typename _CharT, typename _Traits>
--- 470,477 ----
}
}
}
! return __elen && __elen == __plen;
}
template<typename _CharT, typename _Traits>
Index: include/std/std_fstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_fstream.h,v
retrieving revision 1.35
diff -c -p -r1.35 std_fstream.h
*** include/std/std_fstream.h 11 May 2003 04:20:56 -0000 1.35
--- include/std/std_fstream.h 12 May 2003 18:07:36 -0000
*************** 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.