diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2002-04-16 00:45:36 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2002-04-16 00:45:36 +0000 |
commit | d3a193e36cdf55fbff3bd0f244bc36bc09871ee1 (patch) | |
tree | b099d8807cf3e64edeb22eeaae55f91bee6e0c39 /libstdc++-v3/include/bits/locale_facets.h | |
parent | 629111c7320f72d55769c15453aa75cc96877c04 (diff) | |
download | gcc-d3a193e36cdf55fbff3bd0f244bc36bc09871ee1.zip gcc-d3a193e36cdf55fbff3bd0f244bc36bc09871ee1.tar.gz gcc-d3a193e36cdf55fbff3bd0f244bc36bc09871ee1.tar.bz2 |
re PR libstdc++/4164 (33 Memory Leak when using iostream)
2002-04-15 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/4164
Valgrind fixes.
* config/io/basic_file_stdio.cc (__basic_file::~__basic_file):
Call close.
(__basic_file::close): Call fflush. Correct return if fclose ok.
(__basic_file::is_open): Make const.
Change __c_file_type to __c_file.
* config/io/basic_file_stdio.h: Change __c_file_type to __c_file.
(__basic_file::is_open): Make const.
* config/io/c_io_stdio.h: Change __c_file_type to __c_file.
* include/std/std_fstream.h (filebuf::_M_allocate_file): Remove.
(filebuf::_M_unbuf): Add.
(filebuf::_M_file): Change to non-pointer.
(filebuf::_M_allocate_pback_buffer): Remove.
* include/bits/fstream.tcc (filebuf::_M_allocate_file): Remove.
(filebuf::_M_allocate_internal_buffer): Use _M_unbuf.
Change initialization list for _M_file change.
(filebuf::_M_allocate_pback_buffer): Remove.
Change _M_file usage to reflect non-pointer data member.
* config/locale/generic/c_locale.cc
(locale::facet::_S_create_c_locale): Add parameter.
* config/locale/generic/collate_members.cc: Change
_M_compare_helper to _M_compare.
Change _M_transform_helper to _M_transform.
* config/locale/generic/monetary_members.cc: Changeup data types.
Add dtors.
* config/locale/generic/numeric_members.cc: Add dtors.
* config/locale/generic/time_members.cc: Add dtors.
* config/locale/gnu/c_locale.cc: Add parameter.
* config/locale/gnu/collate_members.cc:Change
_M_compare_helper to _M_compare.
Change _M_transform_helper to _M_transform.
* config/locale/gnu/ctype_members.cc: Better error checking.
* config/os/gnu-linux/bits/ctype_noninline.h: Better error checking.
* config/locale/gnu/messages_members.cc: Tweak comment.
* config/locale/gnu/monetary_members.cc: Change data types.
Add dtors.
* config/locale/gnu/numeric_members.cc: Add dtors, better error
checking.
* config/locale/gnu/time_members.cc: Same.
* config/locale/ieee_1003.1-2001/c_locale.cc
(locale::facet::_S_create_c_locale): Add parameter.
* config/locale/ieee_1003.1-2001/c_locale.h: Correct typedef.
* config/locale/ieee_1003.1-2001/codecvt_specializations.h: Remove
bogus ctor.
* include/bits/locale_facets.h (moneypunct): Use string literals.
Don't define dtor.
(numpunct): Same.
(__timepunct): Same.
(locale::_Impl::_M_facets): Change from vector to array.
(locale::_Impl::_M_names): Change from array of strings to array
of string literals.
(locale::facet::_S_create_c_locale): Add parameter.
(locale::locale::_S_num_facets): Move to...
(locale::_Impl::_M_facets_size): Here.
* include/bits/locale_facets.tcc: Fixups for _M_facets, _M_name
changes.
* include/bits/localefwd.h: (locale::id::_M_id): Add member function.
(locale::_Impl::_Impl(facet**, size_t, bool)): Add.
(locale::_Impl::_Impl(string, size_t)): Change to
(locale::_Impl::_Impl(const char*, size_t)): This.
* include/bits/streambuf.tcc (streambuf::_S_pback_size): Define.
* include/std/std_streambuf.h (streambuf::_M_pback_size): Change to
(streambuf::_S_pback_size): This.
* src/globals.cc: Add pre-allocations for "C" facets.
* src/locale-inst.cc: Remove vector instantiations.
* src/locale.cc: Remove vector include. Fixups for _M_names,
_M_facets changes.
* src/localename.cc: Same.
* include/bits/stl_vector.h: Fix odd formatting.
* include/bits/basic_string.tcc: Tweak comment.
* libsupc++/new: Make sure parameters are uglified.
* libsupc++/typeinfo: Same.
* testsuite/22_locale/num_get_members_char.cc: Fixup.
* testsuite/22_locale/num_get_members_wchar_t.cc: Same.
* testsuite/27_io/filebuf_members.cc: Same.
From-SVN: r52345
Diffstat (limited to 'libstdc++-v3/include/bits/locale_facets.h')
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.h | 127 |
1 files changed, 79 insertions, 48 deletions
diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h index a45023f..d63eb5d 100644 --- a/libstdc++-v3/include/bits/locale_facets.h +++ b/libstdc++-v3/include/bits/locale_facets.h @@ -43,13 +43,18 @@ #pragma GCC system_header #include <ctime> // For struct tm -#ifdef _GLIBCPP_USE_WCHAR_T -# include <cwctype> // For wctype_t -#endif +#include <cwctype> // For wctype_t #include <ios> // For ios_base namespace std { + // NB: Don't instantiate required wchar_t facets if no wchar_t support. +#ifdef _GLIBCPP_USE_WCHAR_T +# define _GLIBCPP_NUM_FACETS 28 +#else +# define _GLIBCPP_NUM_FACETS 14 +#endif + // 22.2.1.1 Template class ctype // Include host and configuration specific ctype enums for ctype_base. #include <bits/ctype_base.h> @@ -169,11 +174,11 @@ namespace std typedef _CharT char_type; typedef typename ctype::mask mask; + static locale::id id; + explicit ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { } - static locale::id id; - protected: virtual ~ctype(); @@ -458,9 +463,9 @@ namespace std private: char_type _M_decimal_point; char_type _M_thousands_sep; - string _M_grouping; - string_type _M_truename; - string_type _M_falsename; + const char* _M_grouping; + const char_type* _M_truename; + const char_type* _M_falsename; public: explicit @@ -493,7 +498,7 @@ namespace std protected: virtual - ~numpunct() { } + ~numpunct(); virtual char_type do_decimal_point() const @@ -517,18 +522,24 @@ namespace std // For use at construction time only. void - _M_initialize_numpunct(__c_locale __cloc = NULL); + _M_initialize_numpunct(__c_locale __cloc = _S_c_locale); }; template<typename _CharT> locale::id numpunct<_CharT>::id; template<> + numpunct<char>::~numpunct(); + + template<> void numpunct<char>::_M_initialize_numpunct(__c_locale __cloc); #ifdef _GLIBCPP_USE_WCHAR_T template<> + numpunct<wchar_t>::~numpunct(); + + template<> void numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc); #endif @@ -813,7 +824,7 @@ namespace std explicit collate(size_t __refs = 0) : locale::facet(__refs) - { _M_c_locale_collate = _S_clone_c_locale(_S_c_locale); } + { _M_c_locale_collate = _S_c_locale; } // Non-standard. explicit @@ -836,15 +847,18 @@ namespace std // Used to abstract out _CharT bits in virtual member functions, below. int - _M_compare_helper(const _CharT*, const _CharT*) const; + _M_compare(const _CharT*, const _CharT*) const; size_t - _M_transform_helper(_CharT*, const _CharT*, size_t) const; + _M_transform(_CharT*, const _CharT*, size_t) const; protected: virtual ~collate() - { _S_destroy_c_locale(_M_c_locale_collate); } + { + if (_M_c_locale_collate != _S_c_locale) + _S_destroy_c_locale(_M_c_locale_collate); + } virtual int do_compare(const _CharT* __lo1, const _CharT* __hi1, @@ -863,21 +877,20 @@ namespace std // Specializations. template<> int - collate<char>::_M_compare_helper(const char*, const char*) const; + collate<char>::_M_compare(const char*, const char*) const; template<> size_t - collate<char>::_M_transform_helper(char*, const char*, size_t) const; + collate<char>::_M_transform(char*, const char*, size_t) const; #ifdef _GLIBCPP_USE_WCHAR_T template<> int - collate<wchar_t>::_M_compare_helper(const wchar_t*, const wchar_t*) const; + collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const; template<> size_t - collate<wchar_t>::_M_transform_helper(wchar_t*, const wchar_t*, - size_t) const; + collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const; #endif template<typename _CharT> @@ -891,7 +904,8 @@ namespace std collate_byname(const char* __s, size_t __refs = 0) : collate<_CharT>(__refs) { - _S_destroy_c_locale(_M_c_locale_collate); + if (_M_c_locale_collate != _S_c_locale) + _S_destroy_c_locale(_M_c_locale_collate); _S_create_c_locale(_M_c_locale_collate, __s); } @@ -991,8 +1005,8 @@ namespace std { _M_initialize_timepunct(__cloc); } void - _M_put_helper(_CharT* __s, size_t __maxlen, const _CharT* __format, - const tm* __tm) const; + _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format, + const tm* __tm) const; void _M_date_formats(const _CharT** __date) const @@ -1085,21 +1099,20 @@ namespace std protected: virtual - ~__timepunct() - { - if (_M_c_locale_timepunct) - _S_destroy_c_locale(_M_c_locale_timepunct); - } + ~__timepunct(); // For use at construction time only. void - _M_initialize_timepunct(__c_locale __cloc = NULL); + _M_initialize_timepunct(__c_locale __cloc = _S_c_locale); }; template<typename _CharT> locale::id __timepunct<_CharT>::id; // Specializations. + template<> + __timepunct<char>::~__timepunct(); + template<> const char* __timepunct<char>::_S_timezones[14]; @@ -1110,10 +1123,12 @@ namespace std template<> void - __timepunct<char>::_M_put_helper(char*, size_t, const char*, - const tm*) const; + __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const; #ifdef _GLIBCPP_USE_WCHAR_T + template<> + __timepunct<wchar_t>::~__timepunct(); + template<> const wchar_t* __timepunct<wchar_t>::_S_timezones[14]; @@ -1124,8 +1139,8 @@ namespace std template<> void - __timepunct<wchar_t>::_M_put_helper(wchar_t*, size_t, const wchar_t*, - const tm*) const; + __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*, + const tm*) const; #endif // Generic. @@ -1322,19 +1337,19 @@ namespace std typedef _CharT char_type; typedef basic_string<_CharT> string_type; - static const bool intl = _Intl; - static locale::id id; + static const bool intl = _Intl; + static locale::id id; private: - char_type _M_decimal_point; - char_type _M_thousands_sep; - string _M_grouping; - string_type _M_curr_symbol; - string_type _M_positive_sign; - string_type _M_negative_sign; - int _M_frac_digits; - pattern _M_pos_format; - pattern _M_neg_format; + const char* _M_grouping; + char_type _M_decimal_point; + char_type _M_thousands_sep; + const char_type* _M_curr_symbol; + const char_type* _M_positive_sign; + const char_type* _M_negative_sign; + int _M_frac_digits; + pattern _M_pos_format; + pattern _M_neg_format; public: explicit @@ -1383,7 +1398,7 @@ namespace std protected: virtual - ~moneypunct() { } + ~moneypunct(); virtual char_type do_decimal_point() const @@ -1423,7 +1438,7 @@ namespace std // For use at construction time only. void - _M_initialize_moneypunct(__c_locale __cloc = NULL); + _M_initialize_moneypunct(__c_locale __cloc = _S_c_locale); }; template<typename _CharT, bool _Intl> @@ -1432,6 +1447,12 @@ namespace std template<typename _CharT, bool _Intl> const bool moneypunct<_CharT, _Intl>::intl; + template<> + moneypunct<char, true>::~moneypunct(); + + template<> + moneypunct<char, false>::~moneypunct(); + template<> void moneypunct<char, true>::_M_initialize_moneypunct(__c_locale __cloc); @@ -1441,6 +1462,12 @@ namespace std moneypunct<char, false>::_M_initialize_moneypunct(__c_locale __cloc); #ifdef _GLIBCPP_USE_WCHAR_T + template<> + moneypunct<wchar_t, true>::~moneypunct(); + + template<> + moneypunct<wchar_t, false>::~moneypunct(); + template<> void moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale __cloc); @@ -1586,7 +1613,7 @@ namespace std explicit messages(size_t __refs = 0) : locale::facet(__refs), _M_name_messages("C") - { _M_c_locale_messages = _S_clone_c_locale(_S_c_locale); } + { _M_c_locale_messages = _S_c_locale; } // Non-standard. explicit @@ -1616,7 +1643,10 @@ namespace std protected: virtual ~messages() - { _S_destroy_c_locale(_M_c_locale_messages); } + { + if (_M_c_locale_messages != _S_c_locale) + _S_destroy_c_locale(_M_c_locale_messages); + } virtual catalog do_open(const basic_string<char>&, const locale&) const; @@ -1699,7 +1729,8 @@ namespace std : messages<_CharT>(__refs) { _M_name_messages = __s; - _S_destroy_c_locale(_M_c_locale_messages); + if (_M_c_locale_messages != _S_c_locale) + _S_destroy_c_locale(_M_c_locale_messages); _S_create_c_locale(_M_c_locale_messages, __s); } |