std_streambuf.h: Remove cached locale facets.

2001-03-14  Benjamin Kosnik  <bkoz@redhat.com>

	libstdc++/2020
	* include/bits/std_streambuf.h: Remove cached locale facets.
	(basic_streambuf::_M_buf_fctype): Remove.
	(basic_streambuf::~basic_streambuf): Remove here.
	(basic_streambuf::basic_streambuf): Same.
	(basic_streambuf::imbue): Same.
	* include/bits/fstream.tcc (filebuf::imbue): Remove _M_buf_fctype.
	* include/bits/std_fstream.h (basic_filebuf::_M_fcvt): Remove.
	(basic_filebuf::~basic_filebuf()): Remove here.
	* include/bits/fstream.tcc (basic_filebuf::basic_filebuf): Same.
	(basic_filebuf::imbue): Same.
	* include/bits/localefwd.h (_Count_ones): Remove.
	(locale::_S_num_categories): Just use 6, since this doesn't
	actually change, ever.
	* include/bits/locale_facets.tcc (has_facet): Simplify.
	(use_facet): Same.
	* testsuite/27_io/filebuf.cc (test06): Add tests.

From-SVN: r40472
This commit is contained in:
Benjamin Kosnik 2001-03-14 20:46:34 +00:00 committed by Benjamin Kosnik
parent 16a0fe5059
commit 69302d8b5e
7 changed files with 73 additions and 59 deletions

View File

@ -1,3 +1,23 @@
2001-03-14 Benjamin Kosnik <bkoz@redhat.com>
libstdc++/2020
* include/bits/std_streambuf.h: Remove cached locale facets.
(basic_streambuf::_M_buf_fctype): Remove.
(basic_streambuf::~basic_streambuf): Remove here.
(basic_streambuf::basic_streambuf): Same.
(basic_streambuf::imbue): Same.
* include/bits/fstream.tcc (filebuf::imbue): Remove _M_buf_fctype.
* include/bits/std_fstream.h (basic_filebuf::_M_fcvt): Remove.
(basic_filebuf::~basic_filebuf()): Remove here.
* include/bits/fstream.tcc (basic_filebuf::basic_filebuf): Same.
(basic_filebuf::imbue): Same.
* include/bits/localefwd.h (_Count_ones): Remove.
(locale::_S_num_categories): Just use 6, since this doesn't
actually change, ever.
* include/bits/locale_facets.tcc (has_facet): Simplify.
(use_facet): Same.
* testsuite/27_io/filebuf.cc (test06): Add tests.
2001-03-13 Steve Ellcey <sje@cup.hp.com>
* libstdc++-v3/config/os/hpux/bits/ctype_base.h: Make ctype masks

View File

@ -86,7 +86,7 @@ namespace std
basic_filebuf()
: __streambuf_type(), _M_file(NULL), _M_state_cur(__state_type()),
_M_state_beg(__state_type()), _M_last_overflowed(false)
{ _M_fcvt = &use_facet<__codecvt_type>(this->getloc()); }
{ }
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::
@ -94,7 +94,6 @@ namespace std
: __streambuf_type(), _M_file(NULL), _M_state_cur(__state_type()),
_M_state_beg(__state_type()), _M_last_overflowed(false)
{
_M_fcvt = &use_facet<__codecvt_type>(this->getloc());
_M_filebuf_init();
_M_file->sys_open(__fd, __mode);
if (this->is_open())
@ -486,7 +485,9 @@ namespace std
bool __testopen = this->is_open();
bool __testin = __mode & ios_base::in && _M_mode & ios_base::in;
bool __testout = __mode & ios_base::out && _M_mode & ios_base::out;
int __width = _M_fcvt->encoding();
// Should probably do has_facet checks here.
int __width = use_facet<__codecvt_type>(_M_buf_locale).encoding();
if (__width < 0)
__width = 0;
bool __testfail = __off != 0 && __width <= 0;
@ -557,17 +558,13 @@ namespace std
imbue(const locale& __loc)
{
bool __testbeg = gptr() == eback() && pptr() == pbase();
bool __teststate = _M_fcvt->encoding() == -1;
_M_buf_locale_init = true;
if (__testbeg && !__teststate && _M_buf_locale != __loc)
if (__testbeg && _M_buf_locale != __loc)
{
// XXX Will need to save these older values.
_M_buf_locale = __loc;
_M_fcvt = &use_facet<__codecvt_type>(_M_buf_locale);
// XXX Necessary?
_M_buf_fctype = &use_facet<__ctype_type>(_M_buf_locale);
_M_buf_locale_init = true;
}
// NB this may require the reconversion of previously
// converted chars. This in turn may cause the reconstruction
// of the original file. YIKES!!

View File

@ -70,8 +70,7 @@ namespace std
use_facet(const locale& __loc)
{
typedef locale::_Impl::__vec_facet __vec_facet;
locale::id& __id = _Facet::id;
size_t __i = __id._M_index;
size_t __i = _Facet::id._M_index;
__vec_facet* __facet = __loc._M_impl->_M_facets;
const locale::facet* __fp = (*__facet)[__i];
if (__fp == 0 || __i >= __facet->size())
@ -84,8 +83,7 @@ namespace std
has_facet(const locale& __loc) throw()
{
typedef locale::_Impl::__vec_facet __vec_facet;
locale::id& __id = _Facet::id;
size_t __i = __id._M_index;
size_t __i = _Facet::id._M_index;
__vec_facet* __facet = __loc._M_impl->_M_facets;
return (__i < __facet->size() && (*__facet)[__i] != 0);
}

View File

@ -52,35 +52,6 @@ namespace std
# define _GLIBCPP_NUM_FACETS 13
#endif
// _Count_ones: compile-time computation of number of 1-bits in a value N
// This takes only 5 (or 6) instantiations, doing recursive descent
// in parallel -- ncm
template<unsigned int _Num, int _Shift = (sizeof(unsigned) * CHAR_BIT)/2,
unsigned int _Mask = (~0u >> _Shift) >
struct _Count_ones;
// It is preferable to use enumerators instead of integral static data
// members to avoid emission of superflous variables -- gdr.
template<unsigned int _Num, unsigned int _Mask>
struct _Count_ones<_Num, 0, _Mask>
{
enum
{
_M_count = _Num
};
};
template<unsigned int _Num, int _Shift, unsigned int _Mask>
struct _Count_ones
{
enum
{
_M_halfcount = _Count_ones<_Num, _Shift/2,
(_Mask^((~_Mask)>>(_Shift/2))) >::_M_count,
_M_count = (_M_halfcount&_Mask) + ((_M_halfcount>>_Shift)&_Mask)
};
};
// 22.1.1 Locale
template<typename _Tp, typename _Alloc>
class vector;
@ -297,7 +268,7 @@ namespace std
// Current global reference locale
static _Impl* _S_global;
static const size_t _S_num_categories = _Count_ones<all>::_M_count;
static const size_t _S_num_categories = 6;
static const size_t _S_num_facets = _GLIBCPP_NUM_FACETS;
explicit

View File

@ -75,9 +75,6 @@ namespace std {
__state_type _M_state_cur;
__state_type _M_state_beg;
// Cached value from use_facet.
const __codecvt_type* _M_fcvt;
// MT lock inherited from libio or other low-level io library.
__c_lock _M_lock;
@ -95,7 +92,6 @@ namespace std {
~basic_filebuf()
{
this->close();
_M_fcvt = NULL;
_M_last_overflowed = false;
}

View File

@ -116,9 +116,6 @@ namespace std
// True iff locale is initialized.
bool _M_buf_locale_init;
// Cached use_facet<ctype>, which is based on the current locale info.
const __ctype_type* _M_buf_fctype;
// Necessary bits for putback buffer management. Only used in
// the basic_filebuf class, as necessary for the standard
// requirements. The only basic_streambuf member function that
@ -276,7 +273,6 @@ namespace std
_M_buf_size = 0;
_M_buf_size_opt = 0;
_M_mode = ios_base::openmode(0);
_M_buf_fctype = NULL;
_M_buf_locale_init = false;
}
@ -387,7 +383,7 @@ namespace std
_M_out_end(0), _M_mode(ios_base::openmode(0)), _M_buf_locale(locale()),
_M_buf_locale_init(false), _M_pback_size(1), _M_pback(NULL),
_M_pback_cur_save(NULL), _M_pback_end_save(NULL), _M_pback_init(false)
{ _M_buf_fctype = &use_facet<__ctype_type>(this->getloc()); }
{ }
// Get area:
char_type*
@ -441,10 +437,7 @@ namespace std
{
_M_buf_locale_init = true;
if (_M_buf_locale != __loc)
{
_M_buf_locale = __loc;
_M_buf_fctype = &use_facet<__ctype_type>(_M_buf_locale);
}
_M_buf_locale = __loc;
}
// Buffer management and positioning:

View File

@ -1,6 +1,6 @@
// 990117 bkoz test functionality of basic_filebuf for char_type == char
// Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
// Copyright (C) 1997-1999, 2000, 2001 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
@ -529,6 +529,44 @@ bool test04()
// should be able to instantiate basic_filebuf for non-standard types.
template class std::basic_filebuf<short, std::char_traits<short> >;
// test06
// libstdc++/2020
// should be able to use custom char_type
class gnu_char_type
{
unsigned long character;
public:
// operator ==
bool
operator==(const gnu_char_type& __lhs)
{ return character == __lhs.character; }
// operator <
bool
operator<(const gnu_char_type& __lhs)
{ return character < __lhs.character; }
// to_char_type
gnu_char_type(const unsigned long& __l) : character(__l) { }
// to_int_type
operator unsigned long() const { return character; }
};
bool test06()
{
bool test = true;
typedef std::basic_filebuf<gnu_char_type> gnu_filebuf;
try
{ gnu_filebuf obj; }
catch(std::exception& obj)
{
test = false;
VERIFY( test );
}
return test;
}
int main()
{
@ -538,6 +576,7 @@ int main()
test03();
test04();
test06();
return 0;
}