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]
This commit is contained in:
Ion Gaztañaga
2008-01-25 23:07:51 +00:00
parent 3cd278a169
commit ed5e79b6d3
20 changed files with 71 additions and 53 deletions

View File

@@ -106,6 +106,9 @@ class allocator
<typename SegmentManager::
multiallocation_chain
, T> multiallocation_chain;
// typedef typename SegmentManager::
// multiallocation_chain multiallocation_chain;
/// @endcond
//!Obtains an allocator that allocates

View File

@@ -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();
}

View File

@@ -174,7 +174,7 @@ class cache_impl
}
BOOST_CATCH(...){
this->cached_deallocation(multiallocation_iterator(chain.get_it()));
throw;
BOOST_RETHROW
}
BOOST_CATCH_END
}

View File

@@ -1359,9 +1359,9 @@ class deque : protected deque_base<T, Alloc>
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<T, Alloc>
for(;first2 != mid2; ++first2){
detail::get_pointer(&*first2)->~value_type();
}
BOOST_RETHROW
}
BOOST_CATCH_END
}

View File

@@ -176,7 +176,7 @@ struct node_alloc_holder
BOOST_CATCH(...){
valueptr->first.~first_type();
static_cast<hook_type*>(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<hook_type*>(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;

View File

@@ -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); }
//! <b>Effects</b>: Copy constructs a list.
//!
@@ -804,7 +804,7 @@ class slist
//! <b>Complexity</b>: 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
//! <b>Complexity</b>: 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 <class InIter>
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

View File

@@ -1684,7 +1684,7 @@ class basic_string
for (; constructed--; ++dest_init){
this->destroy(dest_init);
}
BOOST_RETHROW;
BOOST_RETHROW
}
BOOST_CATCH_END
return (constructed);

View File

@@ -731,7 +731,7 @@ class vector : private detail::vector_alloc_holder<A>
//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<pointer, bool> ret =
this->allocation_command
(allocate_new | expand_fwd | expand_bwd,

View File

@@ -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;

View File

@@ -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<boost::uint32_t*>(region.get_address());
boost::uint32_t *patomic_word = 0; //avoid gcc warning
patomic_word = static_cast<boost::uint32_t*>(region.get_address());
boost::uint32_t previous = detail::atomic_cas32(patomic_word, InitializingSegment, UninitializedSegment);
if(previous == UninitializedSegment){

View File

@@ -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
}

View File

@@ -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;

View File

@@ -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));

View File

@@ -394,6 +394,7 @@ void simple_seq_fit_impl<MutexFamily, VoidPointer>::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);

View File

@@ -1138,6 +1138,7 @@ bool rbtree_best_fit<MutexFamily, VoidPointer, MemAlignment>::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<MutexFamily, VoidPointer, MemAlignment>::block_ctrl *
assert(first_segment_block->m_prev_allocated);
block_ctrl *end_block = reinterpret_cast<block_ctrl *>
(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;

View File

@@ -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<CharT *>(hdr->template name<CharT>());
@@ -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<CharT *>(hdr->template name<CharT>());

View File

@@ -92,7 +92,7 @@ class shared_count
}
BOOST_CATCH (...){
d(p); // delete p
throw;
BOOST_RETHROW
}
BOOST_CATCH_END
}

View File

@@ -9,15 +9,15 @@
//////////////////////////////////////////////////////////////////////////////
#include <boost/interprocess/detail/config_begin.hpp>
#include <ios> // for std::streamoff
#include <fstream>
#include <ios> //std::streamoff
#include <fstream> //std::ofstream, std::ifstream
#include <iostream>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <memory>
#include <cstdio>
#include <string>
#include <memory> //std::auto_ptr
#include <stdexcept> //std::exception
#include <cstdio> //std::remove
#include <cstddef> //std::size_t
#include "get_process_id_name.hpp"
using namespace boost::interprocess;

View File

@@ -12,9 +12,8 @@
#define BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
#include <boost/config.hpp>
#include <string>
#include <algorithm>
#include <sstream>
#include <string> //std::string
#include <sstream> //std::stringstream
#include <boost/interprocess/detail/os_thread_functions.hpp>
namespace boost{

View File

@@ -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<false>
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<IntType>());
stdlist->sort(std::greater<int>());
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<IntType>());
stdlist->sort(std::greater<int>());
if(!CheckEqualContainers(shmlist, stdlist)) return 1;
if(!CheckEqualContainers(shmlist, stdlist))
return 1;
othershmlist.sort(std::greater<IntType>());
otherstdlist.sort(std::greater<int>());
if(!CheckEqualContainers(&othershmlist, &otherstdlist)) return 1;
if(!CheckEqualContainers(&othershmlist, &otherstdlist))
return 1;
shmlist->merge(othershmlist, std::greater<IntType>());
stdlist->merge(otherstdlist, std::greater<int>());
if(!CheckEqualContainers(shmlist, stdlist)) return 1;
if(!CheckEqualContainers(shmlist, stdlist))
return 1;
}
}