Commit 0cd1de6f by Benjamin Kosnik Committed by Benjamin Kosnik

std_fstream.h (basic_filebuf::_M_codecvt): Add cached member.


2003-05-12  Benjamin Kosnik  <bkoz@redhat.com>

	* include/std/std_fstream.h (basic_filebuf::_M_codecvt): Add
	cached member.
	* include/bits/fstream.tcc (basic_filebuf::basic_filebuf):
	Initialize _M_codecvt.
	(basic_filebuf::imbue): Same.
	(basic_filebuf::showmanyc): Use it.
	(basic_filebuf::underflow): Use it.
	(basic_filebuf::_M_convert_to_external): Use it.
	(basic_filebuf::seekoff): Use it.
	(basic_filebuf::imbue): Use it, tweaks.
	* include/bits/localefwd.h (__check_facet): New.
	* include/bits/locale_classes.h: Tweaks.
	* include/bits/locale_facets.tcc: Tweaks.
	* include/bits/basic_ios.h (basic_ios::_M_check_facet): Remove.
	_M_fctype to _M_ctype, _M_fnumput to _M_num_put, _M_fnumget to
	_M_num_get. Change _M_check_facet to __check_facet. Tweaks.
	* include/bits/basic_ios.tcc: Same.
	* include/bits/istream.tcc: Same.
	* include/bits/ostream.tcc: Same.
	* include/std/std_streambuf.h: Same.
	* testsuite/27_io/basic_filebuf/imbue/char/2.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/char/3.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc: New.

From-SVN: r66781
parent d24273ab
2003-05-12 Benjamin Kosnik <bkoz@redhat.com>
* include/std/std_fstream.h (basic_filebuf::_M_codecvt): Add
cached member.
* include/bits/fstream.tcc (basic_filebuf::basic_filebuf):
Initialize _M_codecvt.
(basic_filebuf::imbue): Same.
(basic_filebuf::showmanyc): Use it.
(basic_filebuf::underflow): Use it.
(basic_filebuf::_M_convert_to_external): Use it.
(basic_filebuf::seekoff): Use it.
(basic_filebuf::imbue): Use it, tweaks.
* include/bits/localefwd.h (__check_facet): New.
* include/bits/locale_classes.h: Tweaks.
* include/bits/locale_facets.tcc: Tweaks.
* include/bits/basic_ios.h (basic_ios::_M_check_facet): Remove.
_M_fctype to _M_ctype, _M_fnumput to _M_num_put, _M_fnumget to
_M_num_get. Change _M_check_facet to __check_facet. Tweaks.
* include/bits/basic_ios.tcc: Same.
* include/bits/istream.tcc: Same.
* include/bits/ostream.tcc: Same.
* include/std/std_streambuf.h: Same.
* testsuite/27_io/basic_filebuf/imbue/char/2.cc: New.
* testsuite/27_io/basic_filebuf/imbue/char/3.cc: New.
* testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc: New.
* testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc: New.
* testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc: New.
* testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc: New.
2003-05-12 Paolo Carlini <pcarlini@unitus.it> 2003-05-12 Paolo Carlini <pcarlini@unitus.it>
* testsuite/27_io/basic_filebuf/sgetc/char/1.cc: Remove * testsuite/27_io/basic_filebuf/sgetc/char/1.cc: Remove
......
...@@ -90,11 +90,11 @@ namespace std ...@@ -90,11 +90,11 @@ namespace std
basic_streambuf<_CharT, _Traits>* _M_streambuf; basic_streambuf<_CharT, _Traits>* _M_streambuf;
// Cached use_facet<ctype>, which is based on the current locale info. // Cached use_facet<ctype>, which is based on the current locale info.
const __ctype_type* _M_fctype; const __ctype_type* _M_ctype;
// For ostream. // For ostream.
const __numput_type* _M_fnumput; const __numput_type* _M_num_put;
// For istream. // For istream.
const __numget_type* _M_fnumget; const __numget_type* _M_num_get;
public: public:
//@{ //@{
...@@ -241,7 +241,7 @@ namespace std ...@@ -241,7 +241,7 @@ namespace std
*/ */
explicit explicit
basic_ios(basic_streambuf<_CharT, _Traits>* __sb) basic_ios(basic_streambuf<_CharT, _Traits>* __sb)
: ios_base(), _M_fctype(0), _M_fnumput(0), _M_fnumget(0) : ios_base(), _M_ctype(0), _M_num_put(0), _M_num_get(0)
{ this->init(__sb); } { this->init(__sb); }
/** /**
...@@ -419,7 +419,7 @@ namespace std ...@@ -419,7 +419,7 @@ namespace std
* The default constructor does nothing and is not normally * The default constructor does nothing and is not normally
* accessible to users. * accessible to users.
*/ */
basic_ios() : ios_base(), _M_fctype(0), _M_fnumput(0), _M_fnumget(0) basic_ios() : ios_base(), _M_ctype(0), _M_num_put(0), _M_num_get(0)
{ } { }
/** /**
...@@ -431,14 +431,6 @@ namespace std ...@@ -431,14 +431,6 @@ namespace std
void void
init(basic_streambuf<_CharT, _Traits>* __sb); init(basic_streambuf<_CharT, _Traits>* __sb);
bool
_M_check_facet(const locale::facet* __f) const
{
if (!__f)
__throw_bad_cast();
return true;
}
void void
_M_cache_locale(const locale& __loc); _M_cache_locale(const locale& __loc);
......
...@@ -110,22 +110,12 @@ namespace std ...@@ -110,22 +110,12 @@ namespace std
template<typename _CharT, typename _Traits> template<typename _CharT, typename _Traits>
char char
basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
{ { return __check_facet(_M_ctype).narrow(__c, __dfault); }
char __ret = __dfault;
if (_M_check_facet(_M_fctype))
__ret = _M_fctype->narrow(__c, __dfault);
return __ret;
}
template<typename _CharT, typename _Traits> template<typename _CharT, typename _Traits>
_CharT _CharT
basic_ios<_CharT, _Traits>::widen(char __c) const basic_ios<_CharT, _Traits>::widen(char __c) const
{ { return __check_facet(_M_ctype).widen(__c); }
char_type __ret = char_type();
if (_M_check_facet(_M_fctype))
__ret = _M_fctype->widen(__c);
return __ret;
}
// Locales: // Locales:
template<typename _CharT, typename _Traits> template<typename _CharT, typename _Traits>
...@@ -181,11 +171,11 @@ namespace std ...@@ -181,11 +171,11 @@ namespace std
basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc) basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc)
{ {
if (__builtin_expect(has_facet<__ctype_type>(__loc), true)) if (__builtin_expect(has_facet<__ctype_type>(__loc), true))
_M_fctype = &use_facet<__ctype_type>(__loc); _M_ctype = &use_facet<__ctype_type>(__loc);
if (__builtin_expect(has_facet<__numput_type>(__loc), true)) if (__builtin_expect(has_facet<__numput_type>(__loc), true))
_M_fnumput = &use_facet<__numput_type>(__loc); _M_num_put = &use_facet<__numput_type>(__loc);
if (__builtin_expect(has_facet<__numget_type>(__loc), true)) if (__builtin_expect(has_facet<__numget_type>(__loc), true))
_M_fnumget = &use_facet<__numget_type>(__loc); _M_num_get = &use_facet<__numget_type>(__loc);
static_cast<__locale_cache<_CharT>&>(_M_cache())._M_init(__loc); static_cast<__locale_cache<_CharT>&>(_M_cache())._M_init(__loc);
} }
......
...@@ -78,8 +78,13 @@ namespace std ...@@ -78,8 +78,13 @@ namespace std
_M_state_cur(__state_type()), _M_state_beg(__state_type()), _M_state_cur(__state_type()), _M_state_beg(__state_type()),
_M_buf(NULL), _M_buf_size(BUFSIZ), _M_buf_allocated(false), _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_pback_cur_save(0),
_M_pback_end_save(0), _M_pback_init(false) _M_pback_end_save(0), _M_pback_init(false), _M_codecvt(0)
{ this->_M_buf_unified = true; } {
this->_M_buf_unified = true;
if (__builtin_expect(has_facet<__codecvt_type>(this->_M_buf_locale),
true))
_M_codecvt = &use_facet<__codecvt_type>(this->_M_buf_locale);
}
template<typename _CharT, typename _Traits> template<typename _CharT, typename _Traits>
typename basic_filebuf<_CharT, _Traits>::__filebuf_type* typename basic_filebuf<_CharT, _Traits>::__filebuf_type*
...@@ -163,17 +168,14 @@ namespace std ...@@ -163,17 +168,14 @@ namespace std
{ {
streamsize __ret = -1; streamsize __ret = -1;
const bool __testin = this->_M_mode & ios_base::in; const bool __testin = this->_M_mode & ios_base::in;
const locale __loc = this->getloc();
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
if (__testin && this->is_open()) if (__testin && this->is_open())
{ {
__ret = this->_M_in_end - this->_M_in_cur;
// For a stateful encoding (-1) the pending sequence might be just // For a stateful encoding (-1) the pending sequence might be just
// shift and unshift prefixes with no actual character. // shift and unshift prefixes with no actual character.
if (__cvt.encoding() >= 0) __ret = this->_M_in_end - this->_M_in_cur;
__ret += _M_file.showmanyc() / __cvt.max_length(); if (__check_facet(_M_codecvt).encoding() >= 0)
__ret += _M_file.showmanyc() / _M_codecvt->max_length();
} }
_M_last_overflowed = false; _M_last_overflowed = false;
...@@ -220,9 +222,8 @@ namespace std ...@@ -220,9 +222,8 @@ namespace std
{ {
streamsize __elen = 0; streamsize __elen = 0;
streamsize __ilen = 0; streamsize __ilen = 0;
const locale __loc = this->getloc();
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc); if (__check_facet(_M_codecvt).always_noconv())
if (__cvt.always_noconv())
{ {
__elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_M_in_beg), _M_buf_size); __elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_M_in_beg), _M_buf_size);
__ilen = __elen; __ilen = __elen;
...@@ -235,9 +236,9 @@ namespace std ...@@ -235,9 +236,9 @@ namespace std
const char* __eend; const char* __eend;
char_type* __iend; char_type* __iend;
codecvt_base::result __r; codecvt_base::result __r;
__r = __cvt.in(_M_state_cur, __buf, __buf + __elen, __eend, __r = _M_codecvt->in(_M_state_cur, __buf, __buf + __elen,
this->_M_in_beg, __eend, this->_M_in_beg,
this->_M_in_beg + _M_buf_size, __iend); this->_M_in_beg + _M_buf_size, __iend);
if (__r == codecvt_base::ok) if (__r == codecvt_base::ok)
__ilen = __iend - this->_M_in_beg; __ilen = __iend - this->_M_in_beg;
else if (__r == codecvt_base::noconv) else if (__r == codecvt_base::noconv)
...@@ -400,7 +401,6 @@ namespace std ...@@ -400,7 +401,6 @@ namespace std
else else
__ret = this->_M_overflow(__c); __ret = this->_M_overflow(__c);
} }
_M_last_overflowed = false; // Set in _M_overflow, below. _M_last_overflowed = false; // Set in _M_overflow, below.
return __ret; return __ret;
} }
...@@ -414,9 +414,7 @@ namespace std ...@@ -414,9 +414,7 @@ namespace std
streamsize __elen = 0; streamsize __elen = 0;
streamsize __plen = 0; streamsize __plen = 0;
const locale __loc = this->getloc(); if (__check_facet(_M_codecvt).always_noconv() && __ilen)
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
if (__cvt.always_noconv() && __ilen)
{ {
__elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), __ilen); __elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), __ilen);
__plen += __ilen; __plen += __ilen;
...@@ -424,7 +422,7 @@ namespace std ...@@ -424,7 +422,7 @@ namespace std
else else
{ {
// Worst-case number of external bytes needed. // Worst-case number of external bytes needed.
int __ext_multiplier = __cvt.encoding(); int __ext_multiplier = _M_codecvt->encoding();
if (__ext_multiplier == -1 || __ext_multiplier == 0) if (__ext_multiplier == -1 || __ext_multiplier == 0)
__ext_multiplier = sizeof(char_type); __ext_multiplier = sizeof(char_type);
streamsize __blen = __ilen * __ext_multiplier; streamsize __blen = __ilen * __ext_multiplier;
...@@ -432,8 +430,8 @@ namespace std ...@@ -432,8 +430,8 @@ namespace std
char* __bend; char* __bend;
const char_type* __iend; const char_type* __iend;
codecvt_base::result __r; codecvt_base::result __r;
__r = __cvt.out(_M_state_cur, __ibuf, __ibuf + __ilen, __r = _M_codecvt->out(_M_state_cur, __ibuf, __ibuf + __ilen,
__iend, __buf, __buf + __blen, __bend); __iend, __buf, __buf + __blen, __bend);
if (__r == codecvt_base::ok || __r == codecvt_base::partial) if (__r == codecvt_base::ok || __r == codecvt_base::partial)
__blen = __bend - __buf; __blen = __bend - __buf;
...@@ -460,8 +458,9 @@ namespace std ...@@ -460,8 +458,9 @@ namespace std
{ {
const char_type* __iresume = __iend; const char_type* __iresume = __iend;
streamsize __rlen = this->_M_out_lim - __iend; streamsize __rlen = this->_M_out_lim - __iend;
__r = __cvt.out(_M_state_cur, __iresume, __iresume + __rlen, __r = _M_codecvt->out(_M_state_cur, __iresume,
__iend, __buf, __buf + __blen, __bend); __iresume + __rlen, __iend, __buf,
__buf + __blen, __bend);
if (__r != codecvt_base::error) if (__r != codecvt_base::error)
{ {
__rlen = __bend - __buf; __rlen = __bend - __buf;
...@@ -470,7 +469,6 @@ namespace std ...@@ -470,7 +469,6 @@ namespace std
} }
} }
} }
return __elen && __elen == __plen; return __elen && __elen == __plen;
} }
...@@ -510,8 +508,8 @@ namespace std ...@@ -510,8 +508,8 @@ namespace std
const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0; const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
int __width = 0; int __width = 0;
if (has_facet<__codecvt_type>(this->_M_buf_locale)) if (_M_codecvt)
__width = use_facet<__codecvt_type>(this->_M_buf_locale).encoding(); __width = _M_codecvt->encoding();
if (__width < 0) if (__width < 0)
__width = 0; __width = 0;
...@@ -523,20 +521,19 @@ namespace std ...@@ -523,20 +521,19 @@ namespace std
if (__way != ios_base::cur || __off != 0) if (__way != ios_base::cur || __off != 0)
{ {
off_type __computed_off = __width * __off; // Sync the internal and external streams.
const bool __testget = this->_M_in_beg < this->_M_in_end; const bool __testget = this->_M_in_beg < this->_M_in_end;
const bool __testput = this->_M_out_beg < this->_M_out_lim; const bool __testput = this->_M_out_beg < this->_M_out_lim;
// Sync the internal and external streams. off_type __computed_off = __width * __off;
// out
if (__testput || _M_last_overflowed) if (__testput || _M_last_overflowed)
{ {
// Part one: update the output sequence. // Part one: update the output sequence.
this->sync(); this->sync();
// Part two: output unshift sequence. // Part two: output unshift sequence.
_M_output_unshift(); _M_output_unshift();
} }
//in
else if (__testget && __way == ios_base::cur) else if (__testget && __way == ios_base::cur)
__computed_off += this->_M_in_cur - _M_filepos; __computed_off += this->_M_in_cur - _M_filepos;
...@@ -544,10 +541,10 @@ namespace std ...@@ -544,10 +541,10 @@ namespace std
__ret = _M_file.seekoff(__computed_off, __way, __mode); __ret = _M_file.seekoff(__computed_off, __way, __mode);
_M_set_indeterminate(); _M_set_indeterminate();
} }
// NB: Need to do this in case _M_file in indeterminate
// state, ie _M_file._offset == -1
else else
{ {
// NB: Need to do this in case _M_file in indeterminate
// state, ie _M_file._offset == -1
pos_type __tmp = _M_file.seekoff(__off, ios_base::cur, __mode); pos_type __tmp = _M_file.seekoff(__off, ios_base::cur, __mode);
if (__tmp >= 0) if (__tmp >= 0)
{ {
...@@ -584,16 +581,23 @@ namespace std ...@@ -584,16 +581,23 @@ namespace std
basic_filebuf<_CharT, _Traits>:: basic_filebuf<_CharT, _Traits>::
imbue(const locale& __loc) imbue(const locale& __loc)
{ {
const bool __testbeg = this->_M_in_cur == this->_M_in_beg const bool __testbeg = !this->seekoff(0, ios_base::cur, this->_M_mode);
&& this->_M_out_cur == this->_M_out_beg; const bool __teststate = __check_facet(_M_codecvt).encoding() == -1;
if (__testbeg && this->_M_buf_locale != __loc) if (this->_M_buf_locale != __loc
this->_M_buf_locale = __loc; && (!this->is_open() || (__testbeg && !__teststate)))
{
// NB this may require the reconversion of previously this->_M_buf_locale = __loc;
// converted chars. This in turn may cause the reconstruction if (__builtin_expect(has_facet<__codecvt_type>(__loc), true))
// of the original file. YIKES!! _M_codecvt = &use_facet<__codecvt_type>(__loc);
// XXX The part in the above comment is not done.
// NB This may require the reconversion of previously
// converted chars. This in turn may cause the
// reconstruction of the original file. YIKES!! This
// implementation interprets this requirement as requiring
// the file position be at the beginning, and a stateless
// encoding, or that the filebuf be closed. Opinions may differ.
}
_M_last_overflowed = false; _M_last_overflowed = false;
} }
......
...@@ -53,10 +53,10 @@ namespace std ...@@ -53,10 +53,10 @@ namespace std
__streambuf_type* __sb = __in.rdbuf(); __streambuf_type* __sb = __in.rdbuf();
__int_type __c = __sb->sgetc(); __int_type __c = __sb->sgetc();
if (__in._M_check_facet(__in._M_fctype)) __check_facet(__in._M_ctype);
while (!traits_type::eq_int_type(__c, __eof) while (!traits_type::eq_int_type(__c, __eof)
&& __in._M_fctype->is(ctype_base::space, && __in._M_ctype->is(ctype_base::space,
traits_type::to_char_type(__c))) traits_type::to_char_type(__c)))
__c = __sb->snextc(); __c = __sb->snextc();
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
...@@ -114,8 +114,7 @@ namespace std ...@@ -114,8 +114,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -142,8 +141,7 @@ namespace std ...@@ -142,8 +141,7 @@ namespace std
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
long __l; long __l;
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __l);
this->_M_fnumget->get(*this, 0, *this, __err, __l);
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 118. basic_istream uses nonexistent num_get member functions. // 118. basic_istream uses nonexistent num_get member functions.
if (!(__err & ios_base::failbit) if (!(__err & ios_base::failbit)
...@@ -178,8 +176,7 @@ namespace std ...@@ -178,8 +176,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -206,8 +203,7 @@ namespace std ...@@ -206,8 +203,7 @@ namespace std
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
long __l; long __l;
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __l);
this->_M_fnumget->get(*this, 0, *this, __err, __l);
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 118. basic_istream uses nonexistent num_get member functions. // 118. basic_istream uses nonexistent num_get member functions.
if (!(__err & ios_base::failbit) if (!(__err & ios_base::failbit)
...@@ -242,8 +238,7 @@ namespace std ...@@ -242,8 +238,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -269,8 +264,7 @@ namespace std ...@@ -269,8 +264,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -296,8 +290,7 @@ namespace std ...@@ -296,8 +290,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -324,8 +317,7 @@ namespace std ...@@ -324,8 +317,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -351,8 +343,7 @@ namespace std ...@@ -351,8 +343,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -379,8 +370,7 @@ namespace std ...@@ -379,8 +370,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -406,8 +396,7 @@ namespace std ...@@ -406,8 +396,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -433,8 +422,7 @@ namespace std ...@@ -433,8 +422,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
...@@ -460,8 +448,7 @@ namespace std ...@@ -460,8 +448,7 @@ namespace std
try try
{ {
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(this->_M_fnumget)) __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
this->_M_fnumget->get(*this, 0, *this, __err, __n);
this->setstate(__err); this->setstate(__err);
} }
catch(...) catch(...)
......
...@@ -65,13 +65,13 @@ namespace std ...@@ -65,13 +65,13 @@ namespace std
friend class _Impl; friend class _Impl;
template<typename _Facet> template<typename _Facet>
friend const _Facet&
use_facet(const locale&);
template<typename _Facet>
friend bool friend bool
has_facet(const locale&) throw(); has_facet(const locale&) throw();
template<typename _Facet>
friend const _Facet&
use_facet(const locale&);
// Category values: // Category values:
// NB: Order must match _S_facet_categories definition in locale.cc // NB: Order must match _S_facet_categories definition in locale.cc
static const category none = 0; static const category none = 0;
......
...@@ -67,23 +67,23 @@ namespace std ...@@ -67,23 +67,23 @@ namespace std
} }
template<typename _Facet> template<typename _Facet>
const _Facet& inline bool
use_facet(const locale& __loc) has_facet(const locale& __loc) throw()
{ {
size_t __i = _Facet::id._M_id(); size_t __i = _Facet::id._M_id();
const locale::facet** __facets = __loc._M_impl->_M_facets; const locale::facet** __facets = __loc._M_impl->_M_facets;
if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i])) return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
__throw_bad_cast();
return static_cast<const _Facet&>(*__facets[__i]);
} }
template<typename _Facet> template<typename _Facet>
bool inline const _Facet&
has_facet(const locale& __loc) throw() use_facet(const locale& __loc)
{ {
size_t __i = _Facet::id._M_id(); size_t __i = _Facet::id._M_id();
const locale::facet** __facets = __loc._M_impl->_M_facets; const locale::facet** __facets = __loc._M_impl->_M_facets;
return (__i < __loc._M_impl->_M_facets_size && __facets[__i]); if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
__throw_bad_cast();
return static_cast<const _Facet&>(*__facets[__i]);
} }
......
...@@ -172,12 +172,21 @@ namespace std ...@@ -172,12 +172,21 @@ namespace std
class messages_byname; class messages_byname;
template<typename _Facet> template<typename _Facet>
bool
has_facet(const locale& __loc) throw();
template<typename _Facet>
const _Facet& const _Facet&
use_facet(const locale& __loc); use_facet(const locale& __loc);
template<typename _Facet> template<typename _Facet>
bool inline const _Facet&
has_facet(const locale& __loc) throw(); __check_facet(const _Facet* __f)
{
if (!__f)
__throw_bad_cast();
return *__f;
}
} // namespace std } // namespace std
#endif #endif
...@@ -157,10 +157,10 @@ namespace std ...@@ -157,10 +157,10 @@ namespace std
{ {
try try
{ {
if (_M_check_facet(this->_M_fnumput)) __check_facet(this->_M_num_put);
if (this->_M_fnumput->put(*this, *this, if (this->_M_num_put->put(*this, *this, this->fill(),
this->fill(), __n).failed()) __n).failed())
this->setstate(ios_base::badbit); this->setstate(ios_base::badbit);
} }
catch(...) catch(...)
{ {
...@@ -183,23 +183,19 @@ namespace std ...@@ -183,23 +183,19 @@ namespace std
{ {
try try
{ {
bool __b = false;
char_type __c = this->fill(); char_type __c = this->fill();
ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
if (_M_check_facet(this->_M_fnumput)) __check_facet(this->_M_num_put);
if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
{ {
bool __b = false; unsigned long __l = static_cast<unsigned long>(__n);
if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex)) __b = this->_M_num_put->put(*this, *this, __c, __l).failed();
{
unsigned long __l = static_cast<unsigned long>(__n);
__b = this->_M_fnumput->put(*this, *this,
__c, __l).failed();
}
else
__b = this->_M_fnumput->put(*this, *this,
__c, __n).failed();
if (__b)
this->setstate(ios_base::badbit);
} }
else
__b = this->_M_num_put->put(*this, *this, __c, __n).failed();
if (__b)
this->setstate(ios_base::badbit);
} }
catch(...) catch(...)
{ {
...@@ -222,10 +218,10 @@ namespace std ...@@ -222,10 +218,10 @@ namespace std
{ {
try try
{ {
if (_M_check_facet(this->_M_fnumput)) __check_facet(this->_M_num_put);
if (this->_M_fnumput->put(*this, *this, if (this->_M_num_put->put(*this, *this, this->fill(),
this->fill(), __n).failed()) __n).failed())
this->setstate(ios_base::badbit); this->setstate(ios_base::badbit);
} }
catch(...) catch(...)
{ {
...@@ -249,24 +245,20 @@ namespace std ...@@ -249,24 +245,20 @@ namespace std
{ {
try try
{ {
bool __b = false;
char_type __c = this->fill(); char_type __c = this->fill();
ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
if (_M_check_facet(this->_M_fnumput)) __check_facet(this->_M_num_put);
if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
{ {
bool __b = false; unsigned long long __l;
if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex)) __l = static_cast<unsigned long long>(__n);
{ __b = this->_M_num_put->put(*this, *this, __c, __l).failed();
unsigned long long __l;
__l = static_cast<unsigned long long>(__n);
__b = this->_M_fnumput->put(*this, *this,
__c, __l).failed();
}
else
__b = this->_M_fnumput->put(*this, *this,
__c, __n).failed();
if (__b)
this->setstate(ios_base::badbit);
} }
else
__b = this->_M_num_put->put(*this, *this, __c, __n).failed();
if (__b)
this->setstate(ios_base::badbit);
} }
catch(...) catch(...)
{ {
...@@ -289,10 +281,10 @@ namespace std ...@@ -289,10 +281,10 @@ namespace std
{ {
try try
{ {
if (_M_check_facet(this->_M_fnumput)) __check_facet(this->_M_num_put);
if (this->_M_fnumput->put(*this, *this, if (this->_M_num_put->put(*this, *this, this->fill(),
this->fill(), __n).failed()) __n).failed())
this->setstate(ios_base::badbit); this->setstate(ios_base::badbit);
} }
catch(...) catch(...)
{ {
...@@ -316,10 +308,10 @@ namespace std ...@@ -316,10 +308,10 @@ namespace std
{ {
try try
{ {
if (_M_check_facet(this->_M_fnumput)) __check_facet(this->_M_num_put);
if (this->_M_fnumput->put(*this, *this, if (this->_M_num_put->put(*this, *this, this->fill(),
this->fill(), __n).failed()) __n).failed())
this->setstate(ios_base::badbit); this->setstate(ios_base::badbit);
} }
catch(...) catch(...)
{ {
...@@ -342,10 +334,10 @@ namespace std ...@@ -342,10 +334,10 @@ namespace std
{ {
try try
{ {
if (_M_check_facet(this->_M_fnumput)) __check_facet(this->_M_num_put);
if (this->_M_fnumput->put(*this, *this, if (this->_M_num_put->put(*this, *this, this->fill(),
this->fill(), __n).failed()) __n).failed())
this->setstate(ios_base::badbit); this->setstate(ios_base::badbit);
} }
catch(...) catch(...)
{ {
...@@ -368,10 +360,10 @@ namespace std ...@@ -368,10 +360,10 @@ namespace std
{ {
try try
{ {
if (_M_check_facet(this->_M_fnumput)) __check_facet(this->_M_num_put);
if (this->_M_fnumput->put(*this, *this, if (this->_M_num_put->put(*this, *this, this->fill(),
this->fill(), __n).failed()) __n).failed())
this->setstate(ios_base::badbit); this->setstate(ios_base::badbit);
} }
catch(...) catch(...)
{ {
......
...@@ -163,6 +163,9 @@ namespace std ...@@ -163,6 +163,9 @@ namespace std
bool _M_pback_init; bool _M_pback_init;
//@} //@}
// Cached codecvt facet.
const __codecvt_type* _M_codecvt;
// Initializes pback buffers, and moves normal buffers to safety. // Initializes pback buffers, and moves normal buffers to safety.
// Assumptions: // Assumptions:
// _M_in_cur has already been moved back // _M_in_cur has already been moved back
...@@ -403,7 +406,6 @@ namespace std ...@@ -403,7 +406,6 @@ namespace std
} }
else else
_M_file.sync(); _M_file.sync();
_M_last_overflowed = false; _M_last_overflowed = false;
return __ret; return __ret;
} }
......
...@@ -343,9 +343,10 @@ namespace std ...@@ -343,9 +343,10 @@ namespace std
int_type int_type
snextc() snextc()
{ {
int_type __eof = traits_type::eof(); int_type __ret = traits_type::eof();
return (traits_type::eq_int_type(this->sbumpc(), __eof) if (!traits_type::eq_int_type(this->sbumpc(), __ret))
? __eof : this->sgetc()); __ret = this->sgetc();
return __ret;
} }
/** /**
...@@ -699,8 +700,8 @@ namespace std ...@@ -699,8 +700,8 @@ namespace std
uflow() uflow()
{ {
int_type __ret = traits_type::eof(); int_type __ret = traits_type::eof();
const bool __testeof = const bool __testeof = traits_type::eq_int_type(this->underflow(),
traits_type::eq_int_type(this->underflow(), __ret); __ret);
if (!__testeof && _M_in_cur < _M_in_end) if (!__testeof && _M_in_cur < _M_in_end)
{ {
__ret = traits_type::to_int_type(*_M_in_cur); __ret = traits_type::to_int_type(*_M_in_cur);
......
// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 27.8.1.4 Overridden virtual functions
#include <fstream>
#include <locale>
#include <testsuite_hooks.h>
void test02()
{
using namespace std;
bool test = true;
const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
locale loc;
filebuf ob;
VERIFY( ob.getloc() == loc );
ob.open(name_01, ios_base::in);
VERIFY( ob.is_open() );
typedef streambuf::pos_type pos_type;
pos_type bad = pos_type(streambuf::off_type(-1));
pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
VERIFY( p != bad);
// 1 "if file is not positioned at its beginning" fails...
locale loc_de = __gnu_cxx_test::try_named_locale("de_DE");
locale ret = ob.pubimbue(loc_de);
VERIFY( ob.getloc() == loc );
}
main()
{
test02();
return 0;
}
// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 27.8.1.4 Overridden virtual functions
#include <fstream>
#include <locale>
#include <testsuite_hooks.h>
class state_codecvt : public std::codecvt<char, char, std::mbstate_t>
{
protected:
int
do_encoding() const throw()
{ return -1; }
};
void test03()
{
using namespace std;
bool test = true;
locale loc_s(locale::classic(), new state_codecvt);
filebuf ob;
ob.pubimbue(loc_s);
VERIFY( ob.getloc() == loc_s );
// 2 "if encoding of current locale is state dependent" fails...
locale loc_c = locale::classic();
locale ret = ob.pubimbue(loc_s);
VERIFY( ob.getloc() == loc_s );
}
main()
{
test03();
return 0;
}
// 981208 bkoz test functionality of basic_stringbuf for char_type == char
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
#include <fstream>
#include <testsuite_hooks.h>
std::wfilebuf fbuf;
// test the filebuf locale settings
void test02()
{
std::locale loc_c = std::locale::classic();
loc_c = fbuf.getloc();
fbuf.pubimbue(loc_c); //This should initialize _M_init to true
std::locale loc_tmp = fbuf.getloc();
VERIFY( loc_tmp == loc_c );
}
int main()
{
test02();
return 0;
}
// more candy!!!
// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 27.8.1.4 Overridden virtual functions
#include <fstream>
#include <locale>
#include <testsuite_hooks.h>
void test02()
{
using namespace std;
bool test = true;
const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
locale loc;
wfilebuf ob;
VERIFY( ob.getloc() == loc );
ob.open(name_01, ios_base::in);
VERIFY( ob.is_open() );
typedef streambuf::pos_type pos_type;
pos_type bad = pos_type(streambuf::off_type(-1));
pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
VERIFY( p != bad);
// 1 "if file is not positioned at its beginning" fails...
locale loc_de = __gnu_cxx_test::try_named_locale("de_DE");
locale ret = ob.pubimbue(loc_de);
VERIFY( ob.getloc() == loc );
}
main()
{
test02();
return 0;
}
// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 27.8.1.4 Overridden virtual functions
#include <fstream>
#include <locale>
#include <testsuite_hooks.h>
class state_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t>
{
protected:
int
do_encoding() const throw()
{ return -1; }
};
void test03()
{
using namespace std;
bool test = true;
locale loc_s(locale::classic(), new state_codecvt);
wfilebuf ob;
ob.pubimbue(loc_s);
VERIFY( ob.getloc() == loc_s );
// 2 "if encoding of current locale is state dependent" fails...
locale loc_c = locale::classic();
locale ret = ob.pubimbue(loc_s);
VERIFY( ob.getloc() == loc_s );
}
main()
{
test03();
return 0;
}
// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2001, 2002, 2003 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 2, 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 27.8.1.4 Overridden virtual functions
#include <fstream>
#include <locale>
#include <testsuite_hooks.h>
// libstdc++/9322
void test07()
{
using std::locale;
bool test = true;
locale loc;
std::wfilebuf ob;
VERIFY( ob.getloc() == loc );
locale::global(__gnu_cxx_test::try_named_locale("en_US"));
VERIFY( ob.getloc() == loc );
locale loc_de = __gnu_cxx_test::try_named_locale("de_DE");
locale ret = ob.pubimbue(loc_de);
VERIFY( ob.getloc() == loc_de );
VERIFY( ret == loc );
locale::global(loc);
VERIFY( ob.getloc() == loc_de );
}
main()
{
test07();
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