hashtable exception safety patch
François Dumont
frs.dumont@gmail.com
Mon Sep 12 19:08:00 GMT 2011
On 09/12/2011 12:48 PM, Paolo Carlini wrote:
> 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.
Hi
Yes, ext/throw_allocator.h was just what I needed, with even better
type names. Here is the patch again with the same ChangeLog entry.
Tested under linux x86_64.
Ok to commit ?
François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable_1.patch
Type: text/x-patch
Size: 10999 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20110912/a1917fa5/attachment.bin>
More information about the Libstdc++
mailing list