From ed5e79b6d383484e8fc1263bcc7f6109350b588a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 25 Jan 2008 23:07:51 +0000 Subject: [PATCH] 1)Fixed gcc release mode warnings. 2)Replaced throw with BOOST_RETHROW when BOOST_TRY is used. 3)Fixed issues with singly linked lists [SVN r42974] --- .../interprocess/allocators/allocator.hpp | 3 ++ .../allocators/detail/adaptive_node_pool.hpp | 3 -- .../allocators/detail/allocator_common.hpp | 2 +- .../boost/interprocess/containers/deque.hpp | 5 ++-- .../containers/detail/node_alloc_holder.hpp | 5 ++-- .../boost/interprocess/containers/slist.hpp | 22 +++++++------- .../boost/interprocess/containers/string.hpp | 2 +- .../boost/interprocess/containers/vector.hpp | 2 +- .../boost/interprocess/detail/algorithms.hpp | 2 +- .../detail/managed_open_or_create_impl.hpp | 3 +- .../detail/segment_manager_helper.hpp | 2 +- .../indexes/iunordered_set_index.hpp | 5 ++-- .../mem_algo/detail/mem_algo_common.hpp | 5 ++-- .../mem_algo/detail/simple_seq_fit_impl.hpp | 1 + .../interprocess/mem_algo/rbtree_best_fit.hpp | 2 ++ .../boost/interprocess/segment_manager.hpp | 13 ++++---- .../smart_ptr/detail/shared_count.hpp | 2 +- test/file_mapping_test.cpp | 10 +++---- test/get_process_id_name.hpp | 5 ++-- test/list_test.hpp | 30 ++++++++++++------- 20 files changed, 71 insertions(+), 53 deletions(-) diff --git a/include/boost/interprocess/allocators/allocator.hpp b/include/boost/interprocess/allocators/allocator.hpp index 7ce825b..08136dc 100644 --- a/include/boost/interprocess/allocators/allocator.hpp +++ b/include/boost/interprocess/allocators/allocator.hpp @@ -106,6 +106,9 @@ class allocator multiallocation_chain; +// typedef typename SegmentManager:: +// multiallocation_chain multiallocation_chain; + /// @endcond //!Obtains an allocator that allocates diff --git a/include/boost/interprocess/allocators/detail/adaptive_node_pool.hpp b/include/boost/interprocess/allocators/detail/adaptive_node_pool.hpp index 136d29d..87fea06 100644 --- a/include/boost/interprocess/allocators/detail/adaptive_node_pool.hpp +++ b/include/boost/interprocess/allocators/detail/adaptive_node_pool.hpp @@ -199,7 +199,6 @@ class private_adaptive_node_pool_impl //!can throw boost::interprocess::bad_alloc void allocate_nodes(multiallocation_chain &nodes, const std::size_t n) { - std::size_t old_node_count = nodes.size(); try{ priv_invariants(); for(std::size_t i = 0; i != n; ++i){ @@ -215,8 +214,6 @@ class private_adaptive_node_pool_impl this->priv_deallocate_free_chunks(m_max_free_chunks); throw; } - //remove me - assert((n+old_node_count) == (std::size_t)std::distance(nodes.get_it(), multiallocation_iterator())); priv_invariants(); } diff --git a/include/boost/interprocess/allocators/detail/allocator_common.hpp b/include/boost/interprocess/allocators/detail/allocator_common.hpp index 7c5bbcc..da18fc9 100644 --- a/include/boost/interprocess/allocators/detail/allocator_common.hpp +++ b/include/boost/interprocess/allocators/detail/allocator_common.hpp @@ -174,7 +174,7 @@ class cache_impl } BOOST_CATCH(...){ this->cached_deallocation(multiallocation_iterator(chain.get_it())); - throw; + BOOST_RETHROW } BOOST_CATCH_END } diff --git a/include/boost/interprocess/containers/deque.hpp b/include/boost/interprocess/containers/deque.hpp index eb5b17d..0b7183d 100644 --- a/include/boost/interprocess/containers/deque.hpp +++ b/include/boost/interprocess/containers/deque.hpp @@ -1359,9 +1359,9 @@ class deque : protected deque_base size_type new_nodes = (new_elems + this->s_buffer_size() - 1) / this->s_buffer_size(); this->priv_reserve_map_at_front(new_nodes); - size_type i; + size_type i = 1; BOOST_TRY { - for (i = 1; i <= new_nodes; ++i) + for (; i <= new_nodes; ++i) *(this->members_.m_start.m_node - i) = this->priv_allocate_node(); } BOOST_CATCH(...) { @@ -1453,6 +1453,7 @@ class deque : protected deque_base for(;first2 != mid2; ++first2){ detail::get_pointer(&*first2)->~value_type(); } + BOOST_RETHROW } BOOST_CATCH_END } diff --git a/include/boost/interprocess/containers/detail/node_alloc_holder.hpp b/include/boost/interprocess/containers/detail/node_alloc_holder.hpp index 7352019..19901ca 100644 --- a/include/boost/interprocess/containers/detail/node_alloc_holder.hpp +++ b/include/boost/interprocess/containers/detail/node_alloc_holder.hpp @@ -176,7 +176,7 @@ struct node_alloc_holder BOOST_CATCH(...){ valueptr->first.~first_type(); static_cast(nodeptr)->~hook_type(); - throw; + BOOST_RETHROW } BOOST_CATCH_END } @@ -201,7 +201,7 @@ struct node_alloc_holder BOOST_CATCH(...){ valueptr->first.~first_type(); static_cast(nodeptr)->~hook_type(); - throw; + BOOST_RETHROW } BOOST_CATCH_END } @@ -296,6 +296,7 @@ struct node_alloc_holder this->destroy(p); } this->node_alloc().deallocate_many(itbeg); + BOOST_RETHROW } BOOST_CATCH_END return beg; diff --git a/include/boost/interprocess/containers/slist.hpp b/include/boost/interprocess/containers/slist.hpp index 9f57c24..3424175 100644 --- a/include/boost/interprocess/containers/slist.hpp +++ b/include/boost/interprocess/containers/slist.hpp @@ -347,7 +347,7 @@ class slist slist(InpIt first, InpIt last, const allocator_type& a = allocator_type()) : AllocHolder(a) - { this->insert_after(this->end_node(), first, last); } + { this->insert_after(this->before_begin(), first, last); } //! Effects: Copy constructs a list. //! @@ -804,7 +804,7 @@ class slist //! Complexity: Linear to the difference between size() and new_size. void resize(size_type new_size, const T& x) { - typename Icont::iterator end_n(this->icont().end()), cur(end_n), cur_next; + typename Icont::iterator end_n(this->icont().end()), cur(this->icont().before_begin()), cur_next; while (++(cur_next = cur) != end_n && new_size > 0){ --new_size; cur = cur_next; @@ -823,7 +823,7 @@ class slist //! Complexity: Linear to the difference between size() and new_size. void resize(size_type new_size) { - typename Icont::iterator end_n(this->icont().end()), cur(end_n), cur_next; + typename Icont::iterator end_n(this->icont().end()), cur(this->icont().before_begin()), cur_next; size_type len = this->size(); size_type left = new_size; @@ -835,7 +835,7 @@ class slist this->erase_after(iterator(cur), iterator(end_n)); } else{ - this->priv_create_and_insert_nodes(this->end(), new_size - len); + this->priv_create_and_insert_nodes(iterator(cur), new_size - len); } } @@ -1252,9 +1252,9 @@ class slist void priv_fill_assign(size_type n, const T& val) { - iterator end_n(end()); - iterator prev(before_begin()); - iterator node(begin()); + iterator end_n(this->end()); + iterator prev(this->before_begin()); + iterator node(this->begin()); for ( ; node != end_n && n > 0 ; --n){ *node = val; prev = node; @@ -1274,9 +1274,9 @@ class slist void priv_assign_dispatch(InpIt first, InpIt last, detail::false_) { - iterator end_n(end()); - iterator prev(before_begin()); - iterator node(begin()); + iterator end_n(this->end()); + iterator prev(this->before_begin()); + iterator node(this->begin()); while (node != end_n && first != last){ *node = *first; prev = node; @@ -1295,7 +1295,7 @@ class slist template void priv_insert_after_range_dispatch(iterator prev_pos, InIter first, InIter last, detail::false_) - { return priv_create_and_insert_nodes(prev_pos, first, last); } + { this->priv_create_and_insert_nodes(prev_pos, first, last); } //Functors for member algorithm defaults struct value_less diff --git a/include/boost/interprocess/containers/string.hpp b/include/boost/interprocess/containers/string.hpp index 37f3269..1c83a75 100644 --- a/include/boost/interprocess/containers/string.hpp +++ b/include/boost/interprocess/containers/string.hpp @@ -1684,7 +1684,7 @@ class basic_string for (; constructed--; ++dest_init){ this->destroy(dest_init); } - BOOST_RETHROW; + BOOST_RETHROW } BOOST_CATCH_END return (constructed); diff --git a/include/boost/interprocess/containers/vector.hpp b/include/boost/interprocess/containers/vector.hpp index bd7fb5d..f1af804 100644 --- a/include/boost/interprocess/containers/vector.hpp +++ b/include/boost/interprocess/containers/vector.hpp @@ -731,7 +731,7 @@ class vector : private detail::vector_alloc_holder //There is not enough memory, allocate a new //buffer or expand the old one. bool same_buffer_start; - size_type real_cap; + size_type real_cap = 0; std::pair ret = this->allocation_command (allocate_new | expand_fwd | expand_bwd, diff --git a/include/boost/interprocess/detail/algorithms.hpp b/include/boost/interprocess/detail/algorithms.hpp index b95d301..233080d 100644 --- a/include/boost/interprocess/detail/algorithms.hpp +++ b/include/boost/interprocess/detail/algorithms.hpp @@ -92,7 +92,7 @@ InIt n_uninitialized_copy_n for (; new_count--; ++dest_init){ detail::get_pointer(&*dest_init)->~value_type(); } - BOOST_RETHROW; + BOOST_RETHROW } BOOST_CATCH_END return first; diff --git a/include/boost/interprocess/detail/managed_open_or_create_impl.hpp b/include/boost/interprocess/detail/managed_open_or_create_impl.hpp index 2be5c0f..068223e 100644 --- a/include/boost/interprocess/detail/managed_open_or_create_impl.hpp +++ b/include/boost/interprocess/detail/managed_open_or_create_impl.hpp @@ -332,7 +332,8 @@ class managed_open_or_create_impl //If the following throws, we will truncate the file to 1 mapped_region region(dev, read_write, 0, 0, addr); - boost::uint32_t *patomic_word = static_cast(region.get_address()); + boost::uint32_t *patomic_word = 0; //avoid gcc warning + patomic_word = static_cast(region.get_address()); boost::uint32_t previous = detail::atomic_cas32(patomic_word, InitializingSegment, UninitializedSegment); if(previous == UninitializedSegment){ diff --git a/include/boost/interprocess/detail/segment_manager_helper.hpp b/include/boost/interprocess/detail/segment_manager_helper.hpp index 4961422..58bbb56 100644 --- a/include/boost/interprocess/detail/segment_manager_helper.hpp +++ b/include/boost/interprocess/detail/segment_manager_helper.hpp @@ -210,7 +210,7 @@ inline void array_construct(void *mem, std::size_t num, detail::in_place_interfa BOOST_CATCH(...){ std::size_t destroyed = 0; table.destroy_n(mem, constructed, destroyed); - BOOST_RETHROW; + BOOST_RETHROW } BOOST_CATCH_END } diff --git a/include/boost/interprocess/indexes/iunordered_set_index.hpp b/include/boost/interprocess/indexes/iunordered_set_index.hpp index d247adc..1b059a3 100644 --- a/include/boost/interprocess/indexes/iunordered_set_index.hpp +++ b/include/boost/interprocess/indexes/iunordered_set_index.hpp @@ -289,15 +289,14 @@ class iunordered_set_index size_type cur_size = this->size(); size_type cur_count = this->bucket_count(); bucket_ptr old_p = this->bucket_pointer(); - size_type sug_count; if(!this->size() && old_p != bucket_ptr(&this->init_bucket)){ - sug_count = 1; this->rehash(bucket_traits(bucket_ptr(&this->init_bucket), 1)); destroy_buckets(this->alloc, old_p, cur_count); } else{ - sug_count = index_type::suggested_upper_bucket_count(cur_size); + size_type sug_count = 0; //gcc warning + sug_count = index_type::suggested_upper_bucket_count(cur_size); if(sug_count >= cur_count) return; diff --git a/include/boost/interprocess/mem_algo/detail/mem_algo_common.hpp b/include/boost/interprocess/mem_algo/detail/mem_algo_common.hpp index 8c776ff..c98ec06 100644 --- a/include/boost/interprocess/mem_algo/detail/mem_algo_common.hpp +++ b/include/boost/interprocess/mem_algo/detail/mem_algo_common.hpp @@ -588,14 +588,15 @@ class memory_algorithm_common if((received_units - total_used_units) >= (elem_units + MemoryAlgorithm::BlockCtrlUnits)){ std::size_t shrunk_received; std::size_t shrunk_request = elem_units*Alignment - AllocatedCtrlBytes + UsableByPreviousChunk; - bool ret = shrink + bool shrink_ok = shrink (memory_algo ,memory_algo->priv_get_user_buffer(new_block) ,shrunk_request ,shrunk_request ,shrunk_received); + (void)shrink_ok; //Shrink must always succeed with passed parameters - BOOST_ASSERT(ret); + BOOST_ASSERT(shrink_ok); //Some sanity checks BOOST_ASSERT(shrunk_request == shrunk_received); BOOST_ASSERT(elem_units == ((shrunk_request-UsableByPreviousChunk)/Alignment + AllocatedCtrlUnits)); diff --git a/include/boost/interprocess/mem_algo/detail/simple_seq_fit_impl.hpp b/include/boost/interprocess/mem_algo/detail/simple_seq_fit_impl.hpp index a724189..88394ff 100644 --- a/include/boost/interprocess/mem_algo/detail/simple_seq_fit_impl.hpp +++ b/include/boost/interprocess/mem_algo/detail/simple_seq_fit_impl.hpp @@ -394,6 +394,7 @@ void simple_seq_fit_impl::shrink_to_fit() std::size_t received_size; void *addr = priv_check_and_allocate(last_units, prev, last, received_size); + (void)addr; assert(addr); assert(received_size == last_units*Alignment - AllocatedCtrlBytes); diff --git a/include/boost/interprocess/mem_algo/rbtree_best_fit.hpp b/include/boost/interprocess/mem_algo/rbtree_best_fit.hpp index 0d7bab9..f675f1d 100644 --- a/include/boost/interprocess/mem_algo/rbtree_best_fit.hpp +++ b/include/boost/interprocess/mem_algo/rbtree_best_fit.hpp @@ -1138,6 +1138,7 @@ bool rbtree_best_fit::priv_is_prev_alloc } else{ block_ctrl *prev = priv_prev_block(ptr); + (void)prev; assert(!priv_is_allocated_block(prev)); return false; } @@ -1151,6 +1152,7 @@ typename rbtree_best_fit::block_ctrl * assert(first_segment_block->m_prev_allocated); block_ctrl *end_block = reinterpret_cast (detail::char_ptr_cast(first_segment_block) - first_segment_block->m_prev_size*Alignment); + (void)end_block; assert(priv_is_allocated_block(end_block)); assert(end_block > first_segment_block); return end_block; diff --git a/include/boost/interprocess/segment_manager.hpp b/include/boost/interprocess/segment_manager.hpp index daf61a8..c8ee79e 100644 --- a/include/boost/interprocess/segment_manager.hpp +++ b/include/boost/interprocess/segment_manager.hpp @@ -272,7 +272,8 @@ class segment_manager_base //Now construct the header block_header_t * hdr = new(ptr_struct) block_header_t(block_info); - void *ptr = hdr->value(); + void *ptr = 0; //avoid gcc warning + ptr = hdr->value(); //Now call constructors detail::array_construct(ptr, num, table); @@ -1062,7 +1063,7 @@ class segment_manager //Ignore exceptions BOOST_CATCH(...){ if(dothrow) - BOOST_RETHROW; + BOOST_RETHROW return 0; } BOOST_CATCH_END @@ -1096,7 +1097,8 @@ class segment_manager //Now construct the intrusive hook plus the header intrusive_value_type * intrusive_hdr = new(buffer_ptr) intrusive_value_type(); block_header_t * hdr = new(intrusive_hdr->get_block_header())block_header_t(block_info); - void *ptr = hdr->value(); + void *ptr = 0; //avoid gcc warning + ptr = hdr->value(); //Copy name to memory segment and insert data CharT *name_ptr = static_cast(hdr->template name()); @@ -1109,7 +1111,7 @@ class segment_manager //Ignore exceptions BOOST_CATCH(...){ if(dothrow) - BOOST_RETHROW; + BOOST_RETHROW return 0; } BOOST_CATCH_END @@ -1235,7 +1237,8 @@ class segment_manager } hdr = new(hdr)block_header_t(block_info); - void *ptr = hdr->value(); + void *ptr = 0; //avoid gcc warning + ptr = hdr->value(); //Copy name to memory segment and insert data CharT *name_ptr = static_cast(hdr->template name()); diff --git a/include/boost/interprocess/smart_ptr/detail/shared_count.hpp b/include/boost/interprocess/smart_ptr/detail/shared_count.hpp index 1b26426..3c48eda 100644 --- a/include/boost/interprocess/smart_ptr/detail/shared_count.hpp +++ b/include/boost/interprocess/smart_ptr/detail/shared_count.hpp @@ -92,7 +92,7 @@ class shared_count } BOOST_CATCH (...){ d(p); // delete p - throw; + BOOST_RETHROW } BOOST_CATCH_END } diff --git a/test/file_mapping_test.cpp b/test/file_mapping_test.cpp index abe97dd..4c4495e 100644 --- a/test/file_mapping_test.cpp +++ b/test/file_mapping_test.cpp @@ -9,15 +9,15 @@ ////////////////////////////////////////////////////////////////////////////// #include -#include // for std::streamoff -#include +#include //std::streamoff +#include //std::ofstream, std::ifstream #include #include #include -#include -#include -#include +#include //std::auto_ptr +#include //std::exception #include //std::remove +#include //std::size_t #include "get_process_id_name.hpp" using namespace boost::interprocess; diff --git a/test/get_process_id_name.hpp b/test/get_process_id_name.hpp index 26250f6..df3bb8f 100644 --- a/test/get_process_id_name.hpp +++ b/test/get_process_id_name.hpp @@ -12,9 +12,8 @@ #define BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP #include -#include -#include -#include +#include //std::string +#include //std::stringstream #include namespace boost{ diff --git a/test/list_test.hpp b/test/list_test.hpp index c557d1a..a8982f6 100644 --- a/test/list_test.hpp +++ b/test/list_test.hpp @@ -39,7 +39,8 @@ struct push_data_function shmlist->push_back(move(move_me)); stdlist->push_back(i); } - if(!CheckEqualContainers(shmlist, stdlist)) return 1; + if(!CheckEqualContainers(shmlist, stdlist)) + return 1; return 0; } }; @@ -56,7 +57,8 @@ struct push_data_function shmlist->push_front(move(move_me)); stdlist->push_front(i); } - if(!CheckEqualContainers(shmlist, stdlist)) return 1; + if(!CheckEqualContainers(shmlist, stdlist)) + return 1; return 0; } }; @@ -69,7 +71,8 @@ struct pop_back_function { shmlist->pop_back(); stdlist->pop_back(); - if(!CheckEqualContainers(shmlist, stdlist)) return 1; + if(!CheckEqualContainers(shmlist, stdlist)) + return 1; return 0; } }; @@ -177,12 +180,14 @@ int list_test (bool copied_allocators_equal = true) shmlist->unique(); stdlist->unique(); - if(!CheckEqualContainers(shmlist, stdlist)) return 1; + if(!CheckEqualContainers(shmlist, stdlist)) + return 1; if(copied_allocators_equal){ shmlist->sort(std::greater()); stdlist->sort(std::greater()); - if(!CheckEqualContainers(shmlist, stdlist)) return 1; + if(!CheckEqualContainers(shmlist, stdlist)) + return 1; } shmlist->resize(25); @@ -191,7 +196,8 @@ int list_test (bool copied_allocators_equal = true) stdlist->resize(50); shmlist->resize(0); stdlist->resize(0); - if(!CheckEqualContainers(shmlist, stdlist)) return 1; + if(!CheckEqualContainers(shmlist, stdlist)) + return 1; if(push_data_t::execute(max, shmlist, stdlist)){ return 1; @@ -209,7 +215,8 @@ int list_test (bool copied_allocators_equal = true) if(copied_allocators_equal){ shmlist->splice(shmlist->begin(), othershmlist); stdlist->splice(stdlist->begin(), otherstdlist); - if(!CheckEqualContainers(shmlist, stdlist)) return 1; + if(!CheckEqualContainers(shmlist, stdlist)) + return 1; } listsize = (int)shmlist->size(); @@ -225,15 +232,18 @@ int list_test (bool copied_allocators_equal = true) if(copied_allocators_equal){ shmlist->sort(std::greater()); stdlist->sort(std::greater()); - if(!CheckEqualContainers(shmlist, stdlist)) return 1; + if(!CheckEqualContainers(shmlist, stdlist)) + return 1; othershmlist.sort(std::greater()); otherstdlist.sort(std::greater()); - if(!CheckEqualContainers(&othershmlist, &otherstdlist)) return 1; + if(!CheckEqualContainers(&othershmlist, &otherstdlist)) + return 1; shmlist->merge(othershmlist, std::greater()); stdlist->merge(otherstdlist, std::greater()); - if(!CheckEqualContainers(shmlist, stdlist)) return 1; + if(!CheckEqualContainers(shmlist, stdlist)) + return 1; } }