OSDN Git Service

2004-03-27 Benjamin Kosnik <bkoz@redhat.com>
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 27 Mar 2004 16:21:21 +0000 (16:21 +0000)
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 27 Mar 2004 16:21:21 +0000 (16:21 +0000)
libstdc++ PR/13598
* config/locale/ieee_1003.1-2001/codecvt_specializations.h
(__enc_traits::_M_destroy): New.
(__enc_traits::~__enc_traits): Use it.
(__enc_traits::operator=): Use _M_destroy, _M_init.
(__enc_traits::__enc_traits): Same.

2004-03-27  Petur Runolfsson  <peturr02@ru.is>

* testsuite/ext/enc_filebuf/char/13598.cc: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@80027 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/config/locale/ieee_1003.1-2001/codecvt_specializations.h
libstdc++-v3/testsuite/ext/enc_filebuf/char/13598.cc [new file with mode: 0644]

index ce9d7b0..1756701 100644 (file)
@@ -1,3 +1,16 @@
+2004-03-27  Benjamin Kosnik  <bkoz@redhat.com>
+
+       libstdc++ PR/13598
+       * config/locale/ieee_1003.1-2001/codecvt_specializations.h
+       (__enc_traits::_M_destroy): New.
+       (__enc_traits::~__enc_traits): Use it.
+       (__enc_traits::operator=): Use _M_destroy, _M_init.
+       (__enc_traits::__enc_traits): Same.
+
+2004-03-27  Petur Runolfsson  <peturr02@ru.is>
+
+       * testsuite/ext/enc_filebuf/char/13598.cc: New.
+
 2004-03-27  Paolo Carlini  <pcarlini@suse.de>
 
        * include/ext/mt_allocator.h: Uglify consistently names of
 2004-03-27  Paolo Carlini  <pcarlini@suse.de>
 
        * include/ext/mt_allocator.h: Uglify consistently names of
index efa8c37..ef0923d 100644 (file)
@@ -1,6 +1,6 @@
 // Locale support (codecvt) -*- C++ -*-
 
 // Locale support (codecvt) -*- C++ -*-
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2001, 2002, 2003, 2004 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
 //
 // 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
@@ -85,6 +85,7 @@
     {
       strncpy(_M_int_enc, __int, _S_max_size);
       strncpy(_M_ext_enc, __ext, _S_max_size);
     {
       strncpy(_M_int_enc, __int, _S_max_size);
       strncpy(_M_ext_enc, __ext, _S_max_size);
+      _M_init();
     }
 
     // 21.1.2 traits typedefs
     }
 
     // 21.1.2 traits typedefs
     // typedef STATE_T state_type
     // requires: state_type shall meet the requirements of
     // CopyConstructible types (20.1.3)
     // typedef STATE_T state_type
     // requires: state_type shall meet the requirements of
     // CopyConstructible types (20.1.3)
+    // NB: This does not preseve the actual state of the conversion
+    // descriptor member, but it does duplicate the encoding
+    // information.
     __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);
       _M_ext_bom = __obj._M_ext_bom;
       _M_int_bom = __obj._M_int_bom;
     __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);
       _M_ext_bom = __obj._M_ext_bom;
       _M_int_bom = __obj._M_int_bom;
+      _M_destroy();
+      _M_init();
     }
 
     // Need assignment operator as well.
     }
 
     // Need assignment operator as well.
     {
       strncpy(_M_int_enc, __obj._M_int_enc, _S_max_size);
       strncpy(_M_ext_enc, __obj._M_ext_enc, _S_max_size);
     {
       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;
       _M_ext_bom = __obj._M_ext_bom;
       _M_int_bom = __obj._M_int_bom;
+      _M_destroy();
+      _M_init();
       return *this;
     }
 
     ~__enc_traits()
       return *this;
     }
 
     ~__enc_traits()
-    {
-      __desc_type __err = reinterpret_cast<iconv_t>(-1);
-      if (_M_in_desc && _M_in_desc != __err) 
-       iconv_close(_M_in_desc);
-      if (_M_out_desc && _M_out_desc != __err) 
-       iconv_close(_M_out_desc);
-    } 
+    { _M_destroy(); } 
 
     void
     _M_init()
 
     void
     _M_init()
        }
     }
 
        }
     }
 
+    void
+    _M_destroy()
+    {
+      const __desc_type __err = reinterpret_cast<iconv_t>(-1);
+      if (_M_in_desc && _M_in_desc != __err) 
+       {
+         iconv_close(_M_in_desc);
+         _M_in_desc = 0;
+       }
+      if (_M_out_desc && _M_out_desc != __err) 
+       {
+         iconv_close(_M_out_desc);
+         _M_out_desc = 0;
+       }
+    }
+
     bool
     _M_good()
     { 
     bool
     _M_good()
     { 
 
     const char* 
     _M_get_external_enc()
 
     const char* 
     _M_get_external_enc()
-    { return _M_ext_enc; }
+    { return _M_ext_enc; }    
   };
 
   // Partial specialization
   };
 
   // Partial specialization
diff --git a/libstdc++-v3/testsuite/ext/enc_filebuf/char/13598.cc b/libstdc++-v3/testsuite/ext/enc_filebuf/char/13598.cc
new file mode 100644 (file)
index 0000000..a9270e1
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (C) 2004 Free Software Foundation
+//
+// 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 <locale>
+#include <cstring>
+#include <cassert>
+#ifdef _GLIBCXX_USE___ENC_TRAITS
+#include <ext/enc_filebuf.h>
+#endif
+
+int main()
+{
+#ifdef _GLIBCXX_USE___ENC_TRAITS
+  const char* str = "Hello, world!\n";
+
+  std::locale loc(std::locale::classic(),
+                 new std::codecvt<char, char, std::__enc_traits>());
+  std::__enc_traits st("ISO-8859-1", "ISO-8859-1");
+  __gnu_cxx::enc_filebuf<char> fb(st);
+  fb.pubimbue(loc);
+
+  fb.open("tmp_13598", std::ios_base::out);
+  std::streamsize n = fb.sputn(str, std::strlen(str));
+  int s = fb.pubsync();
+  fb.close();
+  
+  assert(n == std::strlen(str));
+  assert(s == 0);
+#endif
+  
+  return 0;
+}