From commits-return-2415-apmail-stdcxx-commits-archive=stdcxx.apache.org@stdcxx.apache.org Wed Feb 13 01:19:45 2008 Return-Path: Delivered-To: apmail-stdcxx-commits-archive@www.apache.org Received: (qmail 98371 invoked from network); 13 Feb 2008 01:19:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Feb 2008 01:19:45 -0000 Received: (qmail 77241 invoked by uid 500); 13 Feb 2008 01:19:39 -0000 Delivered-To: apmail-stdcxx-commits-archive@stdcxx.apache.org Received: (qmail 77223 invoked by uid 500); 13 Feb 2008 01:19:39 -0000 Mailing-List: contact commits-help@stdcxx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@stdcxx.apache.org Delivered-To: mailing list commits@stdcxx.apache.org Received: (qmail 77214 invoked by uid 99); 13 Feb 2008 01:19:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Feb 2008 17:19:39 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Feb 2008 01:19:01 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C4F7E1A9838; Tue, 12 Feb 2008 17:19:21 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r627212 - in /stdcxx/trunk/include: fstream fstream.cc Date: Wed, 13 Feb 2008 01:19:21 -0000 To: commits@stdcxx.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080213011921.C4F7E1A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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; }