Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 2582 invoked from network); 7 Feb 2007 15:54:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Feb 2007 15:54:04 -0000 Received: (qmail 49963 invoked by uid 500); 7 Feb 2007 15:54:10 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 49944 invoked by uid 500); 7 Feb 2007 15:54:10 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 49933 invoked by uid 99); 7 Feb 2007 15:54:10 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Feb 2007 07:54:10 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [212.82.213.172] (HELO exkiv.kyiv.vdiweb.com) (212.82.213.172) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Feb 2007 07:54:01 -0800 Received: from [10.11.37.198] ([10.11.37.198]) by exkiv.kyiv.vdiweb.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 7 Feb 2007 17:53:38 +0200 Message-ID: <45C9F602.5050804@kyiv.vdiweb.com> Date: Wed, 07 Feb 2007 17:53:38 +0200 From: Farid Zaripov User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: [PATCH] Fix of STDCXX-268, STDCXX-331 Content-Type: multipart/mixed; boundary="------------090800070801000408060906" X-OriginalArrivalTime: 07 Feb 2007 15:53:38.0531 (UTC) FILETIME=[21DFB330:01C74AD0] X-Virus-Checked: Checked by ClamAV on apache.org --------------090800070801000408060906 Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit Attached is a proposed patch for fix the bugs STDCXX-268 and STDCXX-331. Actually this patch fixes the bug STDCXX-331, but since the std::list constructor uses insert() method so the bug STDCXX-268 is fixed automatically. ChangeLog: STDCXX-268 STDCXX-331 * list (_RWSTD_LIST_SAFE_INSERT_RANGE): New macro for exception safe inserting the range into the list. (_C_insert): Used _RWSTD_LIST_SAFE_INSERT_RANGE macro. (_C_insert): Added try/catch with removing the inserted elements if exception was thrown. Farid. --------------090800070801000408060906 Content-Type: text/plain; name="list.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="list.diff" Index: list =================================================================== --- list (revision 504581) +++ list (working copy) @@ -344,6 +344,22 @@ #endif // _RWSTD_NO_LIST_NODE_BUFFER +# define _RWSTD_LIST_SAFE_INSERT_RANGE(__it, __first, __last) \ + _RWSTD_ASSERT_RANGE (begin (), __it); \ + _RWSTD_ASSERT_RANGE (__first, __last); \ + size_type __n = 0; \ + _TRY { \ + for ( ; !(__first == __last); ++__first, ++__n) \ + insert (__it, *__first); \ + } _CATCH (...) { \ + for ( ; __n; --__n) { \ + iterator __prev = __it; \ + erase (--__prev); \ + } \ + _RETHROW; \ + } typedef void dummy_t + + // here and only here is _C_node initialized void _C_init (bool __empty_list = false) { _C_node = _C_get_node (__empty_list); @@ -577,23 +593,15 @@ void _C_insert (const iterator &__it, _InputIterator __first, _InputIterator __last, bidirectional_iterator_tag) { - _RWSTD_ASSERT_RANGE (begin (), __it); - _RWSTD_ASSERT_RANGE (__first, __last); - - for ( ; !(__first == __last); ++__first) - insert (__it, *__first); + _RWSTD_LIST_SAFE_INSERT_RANGE (__it, __first, __last); } // handles input iterators template - void _C_insert (iterator __it, + void _C_insert (const iterator &__it, _InputIterator __first, _InputIterator __last, input_iterator_tag) { - _RWSTD_ASSERT_RANGE (begin (), __it); - _RWSTD_ASSERT_RANGE (__first, __last); - - for ( ; !(__first == __last); ++__first, ++__it) - __it = insert (__it, *__first); + _RWSTD_LIST_SAFE_INSERT_RANGE (__it, __first, __last); } // handles nonintegral types @@ -643,20 +651,12 @@ } void insert (iterator __it, const_pointer __first, const_pointer __last) { - _RWSTD_ASSERT_RANGE (begin (), __it); - _RWSTD_ASSERT_RANGE (__first, __last); - - for (; !(__first == __last); ++__first) - insert (__it, *__first); + _RWSTD_LIST_SAFE_INSERT_RANGE (__it, __first, __last); } void insert (iterator __it, const_iterator __first, const_iterator __last) { - _RWSTD_ASSERT_RANGE (begin (), __it); - _RWSTD_ASSERT_RANGE (__first, __last); - - for (; !(__first == __last); ++__first) - insert (__it, *__first); + _RWSTD_LIST_SAFE_INSERT_RANGE (__it, __first, __last); } #endif // _RWSTD_NO_INLINE_MEMBER_TEMPLATES @@ -706,8 +706,18 @@ void _C_insert (iterator __it, size_type __n, const_reference __x) { _RWSTD_ASSERT_RANGE (begin (), __it); - while (__n--) - insert (__it, __x); + size_type __i = 0; + + _TRY { + for ( ; __i < __n; ++__i) + insert (__it, __x); + } _CATCH (...) { + for ( ; __i; --__i) { + iterator __prev = __it; + erase (--__prev); + } + _RETHROW; + } } public: --------------090800070801000408060906--