Commit 47b90d6b by David Krauss Committed by Paolo Carlini

re PR libstdc++/45841 (r164529 cris-elf libstdc++ 27_io/basic_filebuf/seekoff/char/2-io.cc)

2010-10-05  David Krauss  <potswa@mac.com>

	PR libstdc++/45841
	* include/bits/fstream.h (basic_filebuf::underflow): Overflow
	success does not preclude returning failure.
	(basic_filebuf::pbackfail): Likewise.
	(basic_filebuf::xsputn): Fix indentation problem.
	(basic_filebuf::xsgetn): Likewise. Also, add similar overflow
	call to enable optimized case from write mode.
	* testsuite/27_io/basic_filebuf/underflow/char/45841.cc: New.
	* testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc: Likewise.

From-SVN: r165009
parent 94a9600c
2010-10-05 David Krauss <potswa@mac.com>
PR libstdc++/45841
* include/bits/fstream.h (basic_filebuf::underflow): Overflow
success does not preclude returning failure.
(basic_filebuf::pbackfail): Likewise.
(basic_filebuf::xsputn): Fix indentation problem.
(basic_filebuf::xsgetn): Likewise. Also, add similar overflow
call to enable optimized case from write mode.
* testsuite/27_io/basic_filebuf/underflow/char/45841.cc: New.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc: Likewise.
2010-10-05 Jonathan Wakely <jwakely.gcc@gmail.com> 2010-10-05 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/bits/locale_facets_nonio.h (time_get::get_time): Doc typo. * include/bits/locale_facets_nonio.h (time_get::get_time): Doc typo.
......
...@@ -209,8 +209,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -209,8 +209,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ {
if (_M_writing) if (_M_writing)
{ {
__ret = overflow(); if (overflow() == traits_type::eof())
if (__ret == traits_type::eof())
return __ret; return __ret;
_M_set_buffer(-1); _M_set_buffer(-1);
_M_writing = false; _M_writing = false;
...@@ -369,8 +368,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -369,8 +368,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ {
if (_M_writing) if (_M_writing)
{ {
__ret = overflow(); if (overflow() == traits_type::eof())
if (__ret == traits_type::eof())
return __ret; return __ret;
_M_set_buffer(-1); _M_set_buffer(-1);
_M_writing = false; _M_writing = false;
...@@ -556,13 +554,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -556,13 +554,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ {
if (__n > 0 && this->gptr() == this->eback()) if (__n > 0 && this->gptr() == this->eback())
{ {
*__s++ = *this->gptr(); *__s++ = *this->gptr(); // emulate non-underflowing sbumpc
this->gbump(1); this->gbump(1);
__ret = 1; __ret = 1;
--__n; --__n;
} }
_M_destroy_pback(); _M_destroy_pback();
} }
else if (_M_writing)
{
if (overflow() == traits_type::eof())
return __ret;
_M_set_buffer(-1);
_M_writing = false;
}
// Optimization in the always_noconv() case, to be generalized in the // Optimization in the always_noconv() case, to be generalized in the
// future: when __n > __buflen we read directly instead of using the // future: when __n > __buflen we read directly instead of using the
...@@ -571,7 +576,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -571,7 +576,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const streamsize __buflen = _M_buf_size > 1 ? _M_buf_size - 1 : 1; const streamsize __buflen = _M_buf_size > 1 ? _M_buf_size - 1 : 1;
if (__n > __buflen && __check_facet(_M_codecvt).always_noconv() if (__n > __buflen && __check_facet(_M_codecvt).always_noconv()
&& __testin && !_M_writing) && __testin)
{ {
// First, copy the chars already present in the buffer. // First, copy the chars already present in the buffer.
const streamsize __avail = this->egptr() - this->gptr(); const streamsize __avail = this->egptr() - this->gptr();
...@@ -633,10 +638,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -633,10 +638,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
basic_filebuf<_CharT, _Traits>:: basic_filebuf<_CharT, _Traits>::
xsputn(const _CharT* __s, streamsize __n) xsputn(const _CharT* __s, streamsize __n)
{ {
streamsize __ret = 0;
// Optimization in the always_noconv() case, to be generalized in the // Optimization in the always_noconv() case, to be generalized in the
// future: when __n is sufficiently large we write directly instead of // future: when __n is sufficiently large we write directly instead of
// using the buffer. // using the buffer.
streamsize __ret = 0;
const bool __testout = _M_mode & ios_base::out; const bool __testout = _M_mode & ios_base::out;
if (__check_facet(_M_codecvt).always_noconv() if (__check_facet(_M_codecvt).always_noconv()
&& __testout && !_M_reading) && __testout && !_M_reading)
...@@ -933,7 +938,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -933,7 +938,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ {
// External position corresponding to gptr(). // External position corresponding to gptr().
_M_ext_next = _M_ext_buf _M_ext_next = _M_ext_buf
+ _M_codecvt->length(_M_state_last, _M_ext_buf, _M_ext_next, + _M_codecvt->length(_M_state_last, _M_ext_buf,
_M_ext_next,
this->gptr() - this->eback()); this->gptr() - this->eback());
const streamsize __remainder = _M_ext_end - _M_ext_next; const streamsize __remainder = _M_ext_end - _M_ext_next;
if (__remainder) if (__remainder)
......
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// 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 3, 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 COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-require-fileio "" }
#include <fstream>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
using namespace std;
filebuf fb_in_out;
fb_in_out.open("tmp_underflow.tst", ios::in | ios::out | ios::trunc);
VERIFY( fb_in_out.sputc('x') == 'x' );
VERIFY( fb_in_out.sgetc() == filebuf::traits_type::eof() );
fb_in_out.close();
}
int main()
{
test01();
return 0;
}
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// 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 3, 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 COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-require-fileio "" }
#include <fstream>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
using namespace std;
wfilebuf fb_in_out;
fb_in_out.open("tmp_underflow.tst", ios::in | ios::out | ios::trunc);
VERIFY( fb_in_out.sputc(L'x') == L'x' );
VERIFY( fb_in_out.sgetc() == wfilebuf::traits_type::eof() );
fb_in_out.close();
}
int main()
{
test01();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment