summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2003-05-26 14:54:42 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2003-05-26 14:54:42 +0000
commit748d903e34527d9876c8a1a26fb22be0066b0fe5 (patch)
tree87e029216a1b1646c2d61ba790662dfbc132990a /libstdc++-v3/include
parent7e297659d791f20bada9bbf0639b4b054212d882 (diff)
downloadppe42-gcc-748d903e34527d9876c8a1a26fb22be0066b0fe5.tar.gz
ppe42-gcc-748d903e34527d9876c8a1a26fb22be0066b0fe5.zip
2003-05-26 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/9339 * include/std/std_fstream.h (basic_filebuf::_M_overflow): Remove. (_M_pback): No array necessary. * include/bits/fstream.tcc (basic_filebuf::_M_overflow): Add unbuffered case, coalesec into ... (basic_filebuf::overflow): ...this. * testsuite/27_io/basic_filebuf/sputn/char/9339.cc: New. * testsuite/27_io/basic_filebuf/sputc/char/2.cc: Unbuffered. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@67175 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/bits/fstream.tcc86
-rw-r--r--libstdc++-v3/include/bits/streambuf.tcc6
-rw-r--r--libstdc++-v3/include/std/std_fstream.h29
3 files changed, 45 insertions, 76 deletions
diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc
index cda0bacd9f9..9bbb5cc1a52 100644
--- a/libstdc++-v3/include/bits/fstream.tcc
+++ b/libstdc++-v3/include/bits/fstream.tcc
@@ -73,7 +73,7 @@ namespace std
basic_filebuf() : __streambuf_type(), _M_file(&_M_lock),
_M_state_cur(__state_type()), _M_state_beg(__state_type()),
_M_buf(NULL), _M_buf_size(BUFSIZ), _M_buf_allocated(false),
- _M_last_overflowed(false), _M_pback_cur_save(0),
+ _M_last_overflowed(false), _M_filepos(0), _M_pback_cur_save(0),
_M_pback_end_save(0), _M_pback_init(false), _M_codecvt(0)
{
this->_M_buf_unified = true;
@@ -125,7 +125,7 @@ namespace std
const bool __testput = this->_M_out_beg < this->_M_out_lim;
if (__testput
- && traits_type::eq_int_type(_M_overflow(__eof), __eof))
+ && traits_type::eq_int_type(this->overflow(), __eof))
__testfail = true;
#if 0
@@ -133,7 +133,7 @@ namespace std
if (_M_last_overflowed)
{
_M_output_unshift();
- _M_overflow(__eof);
+ this->overflow();
}
#endif
}
@@ -204,7 +204,7 @@ namespace std
// Sync internal and external buffers.
if (__testout && this->_M_out_beg < this->_M_out_lim)
- _M_overflow();
+ this->overflow();
if (_M_buf_size > 1)
{
@@ -324,64 +324,46 @@ namespace std
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 __testeof = traits_type::eq_int_type(__c, __ret);
- 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 != this->_M_out_beg)
- _M_file.seekoff(this->_M_out_beg - _M_filepos, ios_base::cur);
-
- // If appropriate, append the overflow char.
- if (!__testeof)
- *this->_M_out_lim++ = traits_type::to_char_type(__c);
-
- // Convert pending sequence to external representation,
- // output.
- if (_M_convert_to_external(this->_M_out_beg,
- this->_M_out_lim - this->_M_out_beg)
- && (!__testeof || (__testeof && !_M_file.sync())))
- {
- _M_set_buffer(0);
- __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();
- const bool __testput = this->_M_out_cur < this->_M_out_end;
+ const bool __testeof = traits_type::eq_int_type(__c, __ret);
const bool __testout = this->_M_mode & ios_base::out;
- // Perhaps set below in _M_overflow.
- _M_last_overflowed = false;
-
if (__testout)
{
- if (traits_type::eq_int_type(__c, traits_type::eof()))
- __ret = traits_type::not_eof(__c);
- else if (__testput)
+ if (this->_M_out_beg < this->_M_out_lim)
+ {
+ // 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 != this->_M_out_beg)
+ _M_file.seekoff(this->_M_out_beg - _M_filepos, ios_base::cur);
+
+ // If appropriate, append the overflow char.
+ if (!__testeof)
+ *this->_M_out_lim++ = traits_type::to_char_type(__c);
+
+ // Convert pending sequence to external representation,
+ // output.
+ if (_M_convert_to_external(this->_M_out_beg,
+ this->_M_out_lim - this->_M_out_beg)
+ && (!__testeof || (__testeof && !_M_file.sync())))
+ {
+ _M_set_buffer(0);
+ __ret = traits_type::not_eof(__c);
+ }
+ }
+ else
{
- *this->_M_out_cur = traits_type::to_char_type(__c);
- _M_move_out_cur(1);
- __ret = traits_type::not_eof(__c);
+ // Unbuffered.
+ char_type __conv = traits_type::to_char_type(__c);
+ if (!__testeof && _M_convert_to_external(&__conv, 1))
+ __ret = __c;
}
- else
- __ret = this->_M_overflow(__c);
}
+ _M_last_overflowed = true;
return __ret;
}
diff --git a/libstdc++-v3/include/bits/streambuf.tcc b/libstdc++-v3/include/bits/streambuf.tcc
index f80a815aa42..5b76c40f928 100644
--- a/libstdc++-v3/include/bits/streambuf.tcc
+++ b/libstdc++-v3/include/bits/streambuf.tcc
@@ -115,7 +115,7 @@ namespace std
while (__ret < __n)
{
const size_t __buf_len = _M_in_end - _M_in_cur;
- if (__buf_len > 0)
+ if (__buf_len)
{
const size_t __remaining = __n - __ret;
const size_t __len = std::min(__buf_len, __remaining);
@@ -149,7 +149,7 @@ namespace std
while (__ret < __n)
{
const size_t __buf_len = _M_out_end - _M_out_cur;
- if (__buf_len > 0)
+ if (__buf_len)
{
const size_t __remaining = __n - __ret;
const size_t __len = std::min(__buf_len, __remaining);
@@ -161,7 +161,7 @@ namespace std
if (__ret < __n)
{
- const int_type __c = this->overflow(traits_type::to_int_type(*__s));
+ int_type __c = this->overflow(traits_type::to_int_type(*__s));
if (!traits_type::eq_int_type(__c, traits_type::eof()))
{
++__ret;
diff --git a/libstdc++-v3/include/std/std_fstream.h b/libstdc++-v3/include/std/std_fstream.h
index 27794881c75..9faf7373006 100644
--- a/libstdc++-v3/include/std/std_fstream.h
+++ b/libstdc++-v3/include/std/std_fstream.h
@@ -158,7 +158,7 @@ namespace std
* @note pbacks of over one character are not currently supported.
* @endif
*/
- char_type _M_pback[1];
+ char_type _M_pback;
char_type* _M_pback_cur_save;
char_type* _M_pback_end_save;
bool _M_pback_init;
@@ -177,7 +177,7 @@ namespace std
{
_M_pback_cur_save = this->_M_in_cur;
_M_pback_end_save = this->_M_in_end;
- this->setg(_M_pback, _M_pback, _M_pback + 1);
+ this->setg(&_M_pback, &_M_pback, &_M_pback + 1);
_M_pback_init = true;
}
}
@@ -191,8 +191,8 @@ namespace std
if (_M_pback_init)
{
// Length _M_in_cur moved in the pback buffer.
- const size_t __off_cur = this->_M_in_cur - _M_pback;
- this->setg(this->_M_buf, _M_pback_cur_save + __off_cur,
+ const size_t __off = this->_M_in_cur == &_M_pback ? 0 : 1;
+ this->setg(this->_M_buf, _M_pback_cur_save + __off,
_M_pback_end_save);
_M_pback_init = false;
}
@@ -311,19 +311,6 @@ namespace std
virtual int_type
pbackfail(int_type __c = _Traits::eof());
- // NB: For what the standard expects of the overflow function,
- // see _M_overflow(), below. Because basic_streambuf's
- // sputc/sputn call overflow directly, and the complications of
- // this implementation's setting of the initial pointers all
- // equal to _M_buf when initializing, it seems essential to have
- // this in actuality be a helper function that checks for the
- // eccentricities of this implementation, and then call
- // overflow() if indeed the buffer is full.
-
- // [documentation is inherited]
- virtual int_type
- overflow(int_type __c = _Traits::eof());
-
// Stroustrup, 1998, p 648
// The overflow() function is called to transfer characters to the
// real output destination when the buffer is full. A call to
@@ -336,8 +323,8 @@ namespace std
* @doctodo
* @endif
*/
- int_type
- _M_overflow(int_type __c = _Traits::eof());
+ virtual int_type
+ overflow(int_type __c = _Traits::eof());
// Convert internal byte sequence to external, char-based
// sequence via codecvt.
@@ -389,7 +376,7 @@ namespace std
off_type __off = this->_M_out_cur - this->_M_out_lim;
// _M_file.sync() will be called within
- if (traits_type::eq_int_type(_M_overflow(), traits_type::eof()))
+ if (traits_type::eq_int_type(this->overflow(), traits_type::eof()))
__ret = -1;
else if (__off)
_M_file.seekoff(__off, ios_base::cur);
@@ -444,7 +431,7 @@ namespace std
// This function sets the pointers of the internal buffer, both get
// and put areas. Typically, __off == _M_in_end - _M_in_beg upon
- // _M_underflow; __off == 0 upon _M_overflow, seekoff, open, setbuf.
+ // _M_underflow; __off == 0 upon overflow, seekoff, open, setbuf.
//
// NB: _M_out_end - _M_out_beg == _M_buf_size - 1, since _M_buf_size
// reflects the actual allocated memory and the last cell is reserved
OpenPOWER on IntegriCloud