hashtable exception safety patch

François Dumont frs.dumont@gmail.com
Wed Sep 7 20:23:00 GMT 2011


On 09/01/2011 08:36 PM, Paolo Carlini wrote:
> Hi,
>>      After some additional time spent on hashtable I prefer to do this
>> new proposal. It fixes
>> - I deal with allocation failure directly in _M_rehash method to avoid
>> introducing new try/catch blocks. I also reset hash policy next resize
>> value when the container is emptied on a hash functor exception.
>>
> For points 3 and 4 above, I would like to see separate patches and
> separate testcases. Is it possible?
>
> Also, please be more descriptive in the ChangeLog entry, saying which
> specific functions are touched. Then, splitting the big patch will also
> help clarifying the rationale behind each smaller one.
>
> Paolo.
>
Hi

     Here is the patch regarding exception safety issues. Writing 
dedicated tests I even found an other situation where the _M_next_resize 
was not correctly restored on exception. It was in _M_insert_bucket 
method if the node allocation fails. I also considered using some kind 
of guard object that would automatically restore hash policy previous 
resize value on exception but as it is not the case when the exception 
is raised by the hash functor the code wouldn't have been simpler.

2011-09-07  François Dumont <fdumont@gcc.gnu.org>

         * include/bits/hashtable.h (_Hashtable<>::_M_rehash): Take and 
restore
         hash policy _M_prev_resize on bad_alloc exception.
         (_Hashtable<>::_M_insert_bucket): Capture hash policy next resize
         before using it and use latter method to have it restore on 
exception.
         (_Hashtable<>::_M_insert(_Arg&& __v, std::false_type): Likewise.
         (_Hashtable<>::insert(_InputIterator, _InputIterator): Likewise.
         (_Hashtable<>::rehash): Likewise.
         * testsuite/util/testsuite_allocators.h: Add throw_allocator
         std::allocator implementation that offer controls on generation of
         std::bad_alloc exceptions.
         * testsuite/23_containers/unordered_set/insert/hash_policy.cc: New.
         * testsuite/23_containers/unordered_multiset/insert/hash_policy.cc:
         Likewise.

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable_1.patch
Type: text/x-patch
Size: 15583 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20110907/1f6f51b2/attachment.bin>


More information about the Libstdc++ mailing list