From 69302d8b5e643da233f4f8fd732282f685b19cec Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Wed, 14 Mar 2001 20:46:34 +0000 Subject: [PATCH] std_streambuf.h: Remove cached locale facets. 2001-03-14 Benjamin Kosnik 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 --- libstdc++-v3/ChangeLog | 20 ++++++++++ libstdc++-v3/include/bits/fstream.tcc | 19 ++++------ libstdc++-v3/include/bits/locale_facets.tcc | 6 +-- libstdc++-v3/include/bits/localefwd.h | 31 +--------------- libstdc++-v3/include/bits/std_fstream.h | 4 -- libstdc++-v3/include/bits/std_streambuf.h | 11 +----- libstdc++-v3/testsuite/27_io/filebuf.cc | 41 ++++++++++++++++++++- 7 files changed, 73 insertions(+), 59 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a0ce10234b6..3fefaa56a01 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2001-03-14 Benjamin Kosnik + + 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 * libstdc++-v3/config/os/hpux/bits/ctype_base.h: Make ctype masks diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index 3969dcd566e..6d5e9bb6c61 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -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 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!! diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index b009de6a77c..edb3d17fa11 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -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); } diff --git a/libstdc++-v3/include/bits/localefwd.h b/libstdc++-v3/include/bits/localefwd.h index 6a1463885dc..dd5cddc44b9 100644 --- a/libstdc++-v3/include/bits/localefwd.h +++ b/libstdc++-v3/include/bits/localefwd.h @@ -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> _Shift) > - struct _Count_ones; - - // It is preferable to use enumerators instead of integral static data - // members to avoid emission of superflous variables -- gdr. - template - struct _Count_ones<_Num, 0, _Mask> - { - enum - { - _M_count = _Num - }; - }; - - template - 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 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::_M_count; + static const size_t _S_num_categories = 6; static const size_t _S_num_facets = _GLIBCPP_NUM_FACETS; explicit diff --git a/libstdc++-v3/include/bits/std_fstream.h b/libstdc++-v3/include/bits/std_fstream.h index 4516f1b7f72..42996465256 100644 --- a/libstdc++-v3/include/bits/std_fstream.h +++ b/libstdc++-v3/include/bits/std_fstream.h @@ -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; } diff --git a/libstdc++-v3/include/bits/std_streambuf.h b/libstdc++-v3/include/bits/std_streambuf.h index 304beeea7b7..013d7e9f1f9 100644 --- a/libstdc++-v3/include/bits/std_streambuf.h +++ b/libstdc++-v3/include/bits/std_streambuf.h @@ -116,9 +116,6 @@ namespace std // True iff locale is initialized. bool _M_buf_locale_init; - // Cached use_facet, 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: diff --git a/libstdc++-v3/testsuite/27_io/filebuf.cc b/libstdc++-v3/testsuite/27_io/filebuf.cc index 7af086e5e71..c59c2912150 100644 --- a/libstdc++-v3/testsuite/27_io/filebuf.cc +++ b/libstdc++-v3/testsuite/27_io/filebuf.cc @@ -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 >; +// 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_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; }