This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] codecvt fixes
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 31 Jan 2002 19:11:08 -0800
- Subject: [v3] codecvt fixes
Simple codecvt fixes so that basic_filebuf can use
codecvt<x,y,__enc_traits> transformations in derived classes. The rest
of the filebuf work is pending, but this is necessary for that to proceed.
tested x86/linux
2002-01-31 Benjamin Kosnik <bkoz@redhat.com>
* config/locale/codecvt_specializations_ieee_1003.1-200x.h:
Initialize all data members in copy ctor.
(__enc_traits::_M_init): Guard against multiple iconv_opens.
* include/std/std_sstream.h (basic_stringbuf): Make data members
protected.
* include/std/std_fstream.h (basic_filebuf): Same.
* include/std/std_streambuf.h: Tweak.
* include/bits/streambuf.tcc: Same.
* include/bits/sstream.tcc: Same.
* include/bits/fstream.tcc: Same.
Index: config/locale/codecvt_specializations_ieee_1003.1-200x.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/locale/codecvt_specializations_ieee_1003.1-200x.h,v
retrieving revision 1.2
diff -c -p -r1.2 codecvt_specializations_ieee_1003.1-200x.h
*** codecvt_specializations_ieee_1003.1-200x.h 2001/10/26 07:21:56 1.2
--- codecvt_specializations_ieee_1003.1-200x.h 2002/02/01 02:46:05
***************
*** 1,6 ****
// Locale support (codecvt) -*- C++ -*-
! // Copyright (C) 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
--- 1,6 ----
// Locale support (codecvt) -*- C++ -*-
! // Copyright (C) 2000, 2001, 2002 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
***************
*** 35,57 ****
// Written by Benjamin Kosnik <bkoz@cygnus.com>
! // XXX
! // __enc_traits may need to move up the locale header hierarchy,
! // depending on if ctype ends up using it.
!
! // Extensions to use icov for dealing with character encodings,
! // including conversions and comparisons between various character
! // sets. This object encapsulates data that may need to be shared between
! // char_traits, codecvt and ctype.
#if _GLIBCPP_USE_SHADOW_HEADERS
using _C_legacy::CODESET;
#endif
-
- // XXX
- // Define this here to codecvt.cc can have _S_max_size definition.
- #define _GLIBCPP_USE___ENC_TRAITS 1
class __enc_traits
{
public:
--- 35,52 ----
// Written by Benjamin Kosnik <bkoz@cygnus.com>
! // XXX
! // Define this here to codecvt.cc can have _S_max_size definition.
! #define _GLIBCPP_USE___ENC_TRAITS 1
#if _GLIBCPP_USE_SHADOW_HEADERS
using _C_legacy::CODESET;
#endif
+ // Extension to use icov for dealing with character encodings,
+ // including conversions and comparisons between various character
+ // sets. This object encapsulates data that may need to be shared between
+ // char_traits, codecvt and ctype.
class __enc_traits
{
public:
***************
*** 81,87 ****
int _M_int_bom;
public:
! __enc_traits(const locale& __loc = locale())
: _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0)
{
// __intc_end = whatever we are using internally, which is
--- 76,89 ----
int _M_int_bom;
public:
! explicit __enc_traits()
! : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0)
! {
! memset(_M_int_enc, 0, _S_max_size);
! memset(_M_ext_enc, 0, _S_max_size);
! }
!
! explicit __enc_traits(const locale& __loc)
: _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0)
{
// __intc_end = whatever we are using internally, which is
***************
*** 98,105 ****
locale::facet::_S_destroy_c_locale(__cloc);
}
! __enc_traits(const char* __int, const char* __ext, int __ibom = 0,
! int __ebom = 0)
: _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0)
{
strncpy(_M_int_enc, __int, _S_max_size);
--- 100,107 ----
locale::facet::_S_destroy_c_locale(__cloc);
}
! explicit __enc_traits(const char* __int, const char* __ext,
! int __ibom = 0, int __ebom = 0)
: _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0)
{
strncpy(_M_int_enc, __int, _S_max_size);
***************
*** 111,117 ****
// typedef STATE_T state_type
// requires: state_type shall meet the requirements of
// CopyConstructible types (20.1.3)
! __enc_traits(const __enc_traits& __obj)
{
strncpy(_M_int_enc, __obj._M_int_enc, _S_max_size);
strncpy(_M_ext_enc, __obj._M_ext_enc, _S_max_size);
--- 113,119 ----
// typedef STATE_T state_type
// requires: state_type shall meet the requirements of
// CopyConstructible types (20.1.3)
! __enc_traits(const __enc_traits& __obj): _M_in_desc(0), _M_out_desc(0)
{
strncpy(_M_int_enc, __obj._M_int_enc, _S_max_size);
strncpy(_M_ext_enc, __obj._M_ext_enc, _S_max_size);
***************
*** 119,126 ****
_M_int_bom = __obj._M_int_bom;
}
! ~__enc_traits()
{
__desc_type __err = reinterpret_cast<iconv_t>(-1);
if (_M_in_desc && _M_in_desc != __err)
iconv_close(_M_in_desc);
--- 121,140 ----
_M_int_bom = __obj._M_int_bom;
}
! // Need assignment operator as well.
! __enc_traits&
! operator=(const __enc_traits& __obj)
{
+ strncpy(_M_int_enc, __obj._M_int_enc, _S_max_size);
+ strncpy(_M_ext_enc, __obj._M_ext_enc, _S_max_size);
+ _M_in_desc = 0;
+ _M_out_desc = 0;
+ _M_ext_bom = __obj._M_ext_bom;
+ _M_int_bom = __obj._M_int_bom;
+ }
+
+ virtual ~__enc_traits()
+ {
__desc_type __err = reinterpret_cast<iconv_t>(-1);
if (_M_in_desc && _M_in_desc != __err)
iconv_close(_M_in_desc);
***************
*** 131,149 ****
void
_M_init()
{
! __desc_type __err = reinterpret_cast<iconv_t>(-1);
! _M_in_desc = iconv_open(_M_int_enc, _M_ext_enc);
! if (_M_in_desc == __err)
! __throw_runtime_error("creating iconv input descriptor failed.");
! _M_out_desc = iconv_open(_M_ext_enc, _M_int_enc);
! if (_M_out_desc == __err)
! __throw_runtime_error("creating iconv output descriptor failed.");
}
bool
_M_good()
{
! __desc_type __err = reinterpret_cast<iconv_t>(-1);
bool __test = _M_in_desc && _M_in_desc != __err;
__test &= _M_out_desc && _M_out_desc != __err;
return __test;
--- 145,169 ----
void
_M_init()
{
! const __desc_type __err = reinterpret_cast<iconv_t>(-1);
! if (!_M_in_desc)
! {
! _M_in_desc = iconv_open(_M_int_enc, _M_ext_enc);
! if (_M_in_desc == __err)
! __throw_runtime_error("creating iconv input descriptor failed.");
! }
! if (!_M_out_desc)
! {
! _M_out_desc = iconv_open(_M_ext_enc, _M_int_enc);
! if (_M_out_desc == __err)
! __throw_runtime_error("creating iconv output descriptor failed.");
! }
}
bool
_M_good()
{
! const __desc_type __err = reinterpret_cast<iconv_t>(-1);
bool __test = _M_in_desc && _M_in_desc != __err;
__test &= _M_out_desc && _M_out_desc != __err;
return __test;
***************
*** 157,170 ****
_M_get_out_descriptor()
{ return &_M_out_desc; }
- const char*
- _M_get_internal_enc()
- { return _M_int_enc; }
-
- const char*
- _M_get_external_enc()
- { return _M_ext_enc; }
-
int
_M_get_external_bom()
{ return _M_ext_bom; }
--- 177,182 ----
***************
*** 172,177 ****
--- 184,197 ----
int
_M_get_internal_bom()
{ return _M_int_bom; }
+
+ const char*
+ _M_get_internal_enc()
+ { return _M_int_enc; }
+
+ const char*
+ _M_get_external_enc()
+ { return _M_ext_enc; }
};
// Partial specialization
***************
*** 250,258 ****
__iconv_adaptor(size_t(*iconv_func)(iconv_t, _T, size_t*, char**, size_t*),
iconv_t cd, char** inbuf, size_t* inbytesleft,
char** outbuf, size_t* outbytesleft)
! {
! return iconv_func(cd, (_T)inbuf, inbytesleft, outbuf, outbytesleft);
! }
template<typename _InternT, typename _ExternT>
codecvt_base::result
--- 270,276 ----
__iconv_adaptor(size_t(*iconv_func)(iconv_t, _T, size_t*, char**, size_t*),
iconv_t cd, char** inbuf, size_t* inbytesleft,
char** outbuf, size_t* outbytesleft)
! { return iconv_func(cd, (_T)inbuf, inbytesleft, outbuf, outbytesleft); }
template<typename _InternT, typename _ExternT>
codecvt_base::result
Index: include/bits/fstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.20
diff -c -p -r1.20 fstream.tcc
*** fstream.tcc 2002/01/26 01:55:08 1.20
--- fstream.tcc 2002/02/01 02:46:07
*************** namespace std
*** 143,151 ****
int
basic_filebuf<_CharT, _Traits>::
fd()
! {
! return _M_file->fd();
! }
template<typename _CharT, typename _Traits>
typename basic_filebuf<_CharT, _Traits>::__filebuf_type*
--- 143,149 ----
int
basic_filebuf<_CharT, _Traits>::
fd()
! { return _M_file->fd(); }
template<typename _CharT, typename _Traits>
typename basic_filebuf<_CharT, _Traits>::__filebuf_type*
*************** namespace std
*** 604,617 ****
// XXX The part in the above comment is not done.
_M_last_overflowed = false;
}
-
} // namespace std
-
- #endif // _CPP_BITS_FSTREAM_TCC
-
-
-
-
-
-
--- 602,607 ----
// XXX The part in the above comment is not done.
_M_last_overflowed = false;
}
} // namespace std
+ #endif
Index: include/bits/sstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/sstream.tcc,v
retrieving revision 1.5
diff -c -p -r1.5 sstream.tcc
*** sstream.tcc 2002/01/16 19:57:31 1.5
--- sstream.tcc 2002/02/01 02:46:08
***************
*** 1,6 ****
// String based streams -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 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
--- 1,7 ----
// String based streams -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2001, 2002
! // 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
***************
*** 38,44 ****
namespace std
{
-
template <class _CharT, class _Traits, class _Alloc>
typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
basic_stringbuf<_CharT, _Traits, _Alloc>::
--- 39,44 ----
*************** namespace std
*** 206,213 ****
return __ret;
}
-
} // namespace std
-
- #endif /* _CPP_BITS_SSTREAM_TCC */
--- 206,211 ----
return __ret;
}
} // namespace std
+ #endif
Index: include/bits/streambuf.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/streambuf.tcc,v
retrieving revision 1.9
diff -c -p -r1.9 streambuf.tcc
*** streambuf.tcc 2001/10/26 05:32:06 1.9
--- streambuf.tcc 2002/02/01 02:46:08
***************
*** 1,6 ****
// Stream buffer classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 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
--- 1,7 ----
// Stream buffer classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
! // 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
***************
*** 34,41 ****
#ifndef _CPP_BITS_STREAMBUF_TCC
#define _CPP_BITS_STREAMBUF_TCC 1
! namespace std {
!
template<typename _CharT, typename _Traits>
typename basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::
--- 35,42 ----
#ifndef _CPP_BITS_STREAMBUF_TCC
#define _CPP_BITS_STREAMBUF_TCC 1
! namespace std
! {
template<typename _CharT, typename _Traits>
typename basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::
Index: include/std/std_fstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_fstream.h,v
retrieving revision 1.2
diff -c -p -r1.2 std_fstream.h
*** std_fstream.h 2002/01/28 22:13:10 1.2
--- std_fstream.h 2002/02/01 02:46:09
***************
*** 44,51 ****
#include <istream>
#include <ostream>
- #include <bits/basic_file.h>
#include <locale> // For codecvt
#include <bits/gthr.h>
namespace std
--- 44,51 ----
#include <istream>
#include <ostream>
#include <locale> // For codecvt
+ #include <bits/basic_file.h>
#include <bits/gthr.h>
namespace std
*************** namespace std
*** 72,78 ****
friend class ios_base; // For sync_with_stdio.
! private:
// Data Members:
// External buffer.
__file_type* _M_file;
--- 72,78 ----
friend class ios_base; // For sync_with_stdio.
! protected:
// Data Members:
// External buffer.
__file_type* _M_file;
*************** namespace std
*** 422,428 ****
};
} // namespace std
-
#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
# define export
#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
--- 422,427 ----
*************** namespace std
*** 431,434 ****
#endif
#endif
-
--- 430,432 ----
Index: include/std/std_sstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_sstream.h,v
retrieving revision 1.2
diff -c -p -r1.2 std_sstream.h
*** std_sstream.h 2002/01/28 22:13:11 1.2
--- std_sstream.h 2002/02/01 02:46:10
*************** namespace std
*** 66,72 ****
typedef basic_string<char_type, _Traits, _Alloc> __string_type;
typedef typename __string_type::size_type __size_type;
! private:
// Data Members:
__string_type _M_string;
--- 66,72 ----
typedef basic_string<char_type, _Traits, _Alloc> __string_type;
typedef typename __string_type::size_type __size_type;
! protected:
// Data Members:
__string_type _M_string;
*************** namespace std
*** 360,367 ****
};
} // namespace std
-
-
#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
# define export
#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
--- 360,365 ----
*************** namespace std
*** 369,372 ****
#endif
#endif
! #endif // _CPP_SSTREAM
--- 367,370 ----
#endif
#endif
! #endif
Index: include/std/std_streambuf.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_streambuf.h,v
retrieving revision 1.2
diff -c -p -r1.2 std_streambuf.h
*** std_streambuf.h 2002/01/28 22:13:11 1.2
--- std_streambuf.h 2002/02/01 02:46:12
*************** namespace std
*** 83,89 ****
__streambuf_type* __sbin,__streambuf_type* __sbout);
protected:
-
// Pointer to the beginning of internally-allocated
// space. Filebuf manually allocates/deallocates this, whereas
// stringstreams attempt to use the built-in intelligence of the
--- 83,88 ----
*************** namespace std
*** 527,533 ****
operator=(const __streambuf_type&);
#endif
};
-
} // namespace std
#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
--- 526,531 ----
*************** namespace std
*** 536,541 ****
#include <bits/streambuf.tcc>
#endif
#endif
-
- #endif /* _CPP_STREAMBUF */
--- 534,538 ----
#include <bits/streambuf.tcc>
#endif
#endif
+ #endif