You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2008/02/13 02:19:21 UTC
svn commit: r627212 - in /stdcxx/trunk/include: fstream fstream.cc
Author: sebor
Date: Tue Feb 12 17:19:20 2008
New Revision: 627212
URL: http://svn.apache.org/viewvc?rev=627212&view=rev
Log:
2008-02-12 Martin Sebor <se...@roguewave.com>
STDCXX-308
* include/fstream (~basic_filebuf): Caught and swallowed all exceptions.
* include/fstream.cc (close): Closed file regardless of whether the call
to overflow() or codecvt::unshift() fails or throws, as required by the
resolution of LWG issue 622.
Modified:
stdcxx/trunk/include/fstream
stdcxx/trunk/include/fstream.cc
Modified: stdcxx/trunk/include/fstream
URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/fstream?rev=627212&r1=627211&r2=627212&view=diff
==============================================================================
--- stdcxx/trunk/include/fstream (original)
+++ stdcxx/trunk/include/fstream Tue Feb 12 17:19:20 2008
@@ -279,7 +279,12 @@
template<class _CharT, class _Traits>
inline basic_filebuf<_CharT, _Traits>::~basic_filebuf ()
{
- close ();
+ _TRY {
+ close ();
+ }
+ _CATCH (...) {
+ // LWG issue 622: swallow all exceptions
+ }
if (this->_C_own_buf ())
delete [] this->_C_buffer;
Modified: stdcxx/trunk/include/fstream.cc
URL: http://svn.apache.org/viewvc/stdcxx/trunk/include/fstream.cc?rev=627212&r1=627211&r2=627212&view=diff
==============================================================================
--- stdcxx/trunk/include/fstream.cc (original)
+++ stdcxx/trunk/include/fstream.cc Tue Feb 12 17:19:20 2008
@@ -23,7 +23,7 @@
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
- * Copyright 1997-2006 Rogue Wave Software, Inc.
+ * Copyright 1997-2008 Rogue Wave Software, Inc.
*
**************************************************************************/
@@ -76,27 +76,52 @@
basic_filebuf<_CharT, _Traits>::
close (bool __close_file /* = true */)
{
+ // close_file is false when close() is called from detach()
+
_RWSTD_ASSERT (this->_C_is_valid ());
if (!is_open ())
return 0; // failure
- // avoid expensive call to overflow() unless necessary
- if (this->pptr () != this->pbase () && this->_C_is_eof (overflow ()))
- return 0; // failure
+ // close() returns this on success, 0 on failure
+ basic_filebuf *__retval = this;
- // write out any unshift sequence if necessary
- // (applies to multibyte, state dependent encodings only)
- if (this->_C_out_last () && !_C_unshift ())
- return 0; // failure
+ _TRY {
+ // avoid expensive call to overflow() unless necessary
+ if (this->pptr () != this->pbase () && this->_C_is_eof (overflow ()))
+ __retval = 0; // failure
+
+ // write out any unshift sequence if necessary
+ // (applies to multibyte, state dependent encodings only)
+ if (__retval && this->_C_out_last () && !_C_unshift ())
+ __retval = 0; // failure
+ }
+ _CATCH (...) {
+ // either overflow() or codecvt::unshift() threw
- if (__close_file && _RW::__rw_fclose (_C_file, this->_C_state))
- return 0; // failure
+ if (__close_file) {
+ _RW::__rw_fclose (_C_file, this->_C_state);
- _C_file = 0;
- _C_cur_pos = _C_beg_pos = pos_type (off_type (-1));
+ // zero out the file pointer except when detaching fd
+ _C_file = 0;
+ _C_cur_pos = _C_beg_pos = pos_type (off_type (-1));
- return this;
+ }
+
+ // rethrow the caught exception
+ _RETHROW;
+ }
+
+ if (__close_file) {
+ if (_RW::__rw_fclose (_C_file, this->_C_state))
+ __retval = 0;
+
+ // zero out the file pointer except when detaching fd
+ _C_file = 0;
+ _C_cur_pos = _C_beg_pos = pos_type (off_type (-1));
+ }
+
+ return __retval;
}