hashtable exception safety patch
Paolo Carlini
paolo.carlini@oracle.com
Mon Sep 12 10:49:00 GMT 2011
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.
The patch is largely Ok, I'm attaching below what I have been testing
here (formatting fixes in the testcases; resolved a diffing error in
testsuite_allocator.h which had removed ExplicitConsAlloc; naming fixes
(__prev_resize is not ok because wrongly gives the impression to be the
opposite of next_resize), etc).
However, before going ahead, can you see whether you can use instead the
existing ext/throw_allocator.h? Or extend / adapt it, I see redundancy here.
Thanks,
Paolo.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable_1_paolo.patch
Type: text/x-patch
Size: 15919 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20110912/27400493/attachment.bin>
More information about the Libstdc++
mailing list