Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55024 - in branches/release/boost: interprocess interprocess/allocators/detail interprocess/containers/container interprocess/detail interprocess/streams interprocess/sync interprocess/sync/emulation interprocess/sync/posix intrusive intrusive/detail
From: igaztanaga_at_[hidden]
Date: 2009-07-18 20:11:35


Author: igaztanaga
Date: 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
New Revision: 55024
URL: http://svn.boost.org/trac/boost/changeset/55024

Log:
Boost 1.40 merge from trunk
Text files modified:
   branches/release/boost/interprocess/allocators/detail/node_pool.hpp | 4
   branches/release/boost/interprocess/containers/container/stable_vector.hpp | 11 +
   branches/release/boost/interprocess/containers/container/vector.hpp | 40 ++++--
   branches/release/boost/interprocess/detail/atomic.hpp | 92 ++++++++++++++
   branches/release/boost/interprocess/detail/os_file_functions.hpp | 8
   branches/release/boost/interprocess/detail/os_thread_functions.hpp | 4
   branches/release/boost/interprocess/detail/tmp_dir_helpers.hpp | 34 +++--
   branches/release/boost/interprocess/detail/win32_api.hpp | 250 ++++++++++++++++++++++++---------------
   branches/release/boost/interprocess/detail/workaround.hpp | 12 +
   branches/release/boost/interprocess/errors.hpp | 6
   branches/release/boost/interprocess/interprocess_fwd.hpp | 2
   branches/release/boost/interprocess/mapped_region.hpp | 9 +
   branches/release/boost/interprocess/shared_memory_object.hpp | 4
   branches/release/boost/interprocess/streams/vectorstream.hpp | 193 ++++++++++++++++--------------
   branches/release/boost/interprocess/sync/emulation/interprocess_semaphore.hpp | 8
   branches/release/boost/interprocess/sync/interprocess_semaphore.hpp | 2
   branches/release/boost/interprocess/sync/named_semaphore.hpp | 12
   branches/release/boost/interprocess/sync/posix/interprocess_semaphore.hpp | 2
   branches/release/boost/interprocess/sync/posix/semaphore_wrapper.hpp | 4
   branches/release/boost/intrusive/avltree_algorithms.hpp | 204 +++++++-------------------------
   branches/release/boost/intrusive/detail/tree_algorithms.hpp | 84 +++++++------
   21 files changed, 541 insertions(+), 444 deletions(-)

Modified: branches/release/boost/interprocess/allocators/detail/node_pool.hpp
==============================================================================
--- branches/release/boost/interprocess/allocators/detail/node_pool.hpp (original)
+++ branches/release/boost/interprocess/allocators/detail/node_pool.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -315,13 +315,13 @@
 
    private:
    //!Returns a reference to the block hook placed in the end of the block
- static inline node_t & get_block_hook (void *block, std::size_t blocksize)
+ static node_t & get_block_hook (void *block, std::size_t blocksize)
    {
       return *reinterpret_cast<node_t*>(reinterpret_cast<char*>(block) + blocksize);
    }
 
    //!Returns the starting address of the block reference to the block hook placed in the end of the block
- inline void *get_block_from_hook (node_t *hook, std::size_t blocksize)
+ void *get_block_from_hook (node_t *hook, std::size_t blocksize)
    {
       return (reinterpret_cast<char*>(hook) - blocksize);
    }

Modified: branches/release/boost/interprocess/containers/container/stable_vector.hpp
==============================================================================
--- branches/release/boost/interprocess/containers/container/stable_vector.hpp (original)
+++ branches/release/boost/interprocess/containers/container/stable_vector.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -90,6 +90,8 @@
    }
 
    private:
+ clear_on_destroy(const clear_on_destroy &);
+ clear_on_destroy &operator=(const clear_on_destroy &);
    C &c_;
    bool do_clear_;
 };
@@ -530,6 +532,15 @@
       STABLE_VECTOR_CHECK_INVARIANT;
    }
 
+ explicit stable_vector(size_type n)
+ : internal_data(Allocator()),impl(Allocator())
+ {
+ stable_vector_detail::clear_on_destroy<stable_vector> cod(*this);
+ this->resize(n);
+ STABLE_VECTOR_CHECK_INVARIANT;
+ cod.release();
+ }
+
    stable_vector(size_type n,const T& t=T(),const Allocator& al=Allocator())
    : internal_data(al),impl(al)
    {

Modified: branches/release/boost/interprocess/containers/container/vector.hpp
==============================================================================
--- branches/release/boost/interprocess/containers/container/vector.hpp (original)
+++ branches/release/boost/interprocess/containers/container/vector.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -477,7 +477,7 @@
    //! throws or T's default or copy constructor throws.
    //!
    //! <b>Complexity</b>: Linear to n.
- vector(size_type n)
+ explicit vector(size_type n)
       : base_t(allocator_type())
    { this->resize(n); }
 
@@ -1336,6 +1336,8 @@
 
    void priv_range_insert_expand_forward(T* pos, size_type n, advanced_insert_aux_int_t &interf)
    {
+ //n can't be 0, because there is nothing to do in that case
+ if(!n) return;
       //There is enough memory
       T* old_finish = containers_detail::get_pointer(this->members_.m_start) + this->members_.m_size;
       const size_type elems_after = old_finish - pos;
@@ -1367,7 +1369,8 @@
    void priv_range_insert_new_allocation
       (T* new_start, size_type new_cap, T* pos, size_type n, advanced_insert_aux_int_t &interf)
    {
- T* new_finish = new_start;
+ //n can be zero, if we want to reallocate!
+ T *new_finish = new_start;
       T *old_finish;
       //Anti-exception rollbacks
       typename value_traits::UCopiedArrayDeallocator scoped_alloc(new_start, this->alloc(), new_cap);
@@ -1375,36 +1378,40 @@
 
       //Initialize with [begin(), pos) old buffer
       //the start of the new buffer
- new_finish = boost::interprocess::uninitialized_move
- (containers_detail::get_pointer(this->members_.m_start), pos, old_finish = new_finish);
- constructed_values_destroyer.increment_size(new_finish - old_finish);
+ T *old_buffer = containers_detail::get_pointer(this->members_.m_start);
+ if(old_buffer){
+ new_finish = boost::interprocess::uninitialized_move
+ (containers_detail::get_pointer(this->members_.m_start), pos, old_finish = new_finish);
+ constructed_values_destroyer.increment_size(new_finish - old_finish);
+ }
       //Initialize new objects, starting from previous point
       interf.uninitialized_copy_all_to(old_finish = new_finish);
       new_finish += n;
       constructed_values_destroyer.increment_size(new_finish - old_finish);
       //Initialize from the rest of the old buffer,
       //starting from previous point
- new_finish = boost::interprocess::uninitialized_move
- ( pos, containers_detail::get_pointer(this->members_.m_start) + this->members_.m_size, new_finish);
- //All construction successful, disable rollbacks
- constructed_values_destroyer.release();
- scoped_alloc.release();
- //Destroy and deallocate old elements
- //If there is allocated memory, destroy and deallocate
- if(this->members_.m_start != 0){
+ if(old_buffer){
+ new_finish = boost::interprocess::uninitialized_move
+ (pos, old_buffer + this->members_.m_size, new_finish);
+ //Destroy and deallocate old elements
+ //If there is allocated memory, destroy and deallocate
          if(!value_traits::trivial_dctr_after_move)
- this->destroy_n(containers_detail::get_pointer(this->members_.m_start), this->members_.m_size);
+ this->destroy_n(old_buffer, this->members_.m_size);
          this->alloc().deallocate(this->members_.m_start, this->members_.m_capacity);
       }
       this->members_.m_start = new_start;
       this->members_.m_size = new_finish - new_start;
       this->members_.m_capacity = new_cap;
+ //All construction successful, disable rollbacks
+ constructed_values_destroyer.release();
+ scoped_alloc.release();
    }
 
    void priv_range_insert_expand_backwards
          (T* new_start, size_type new_capacity,
           T* pos, const size_type n, advanced_insert_aux_int_t &interf)
    {
+ //n can be zero to just expand capacity
       //Backup old data
       T* old_start = containers_detail::get_pointer(this->members_.m_start);
       T* old_finish = old_start + this->members_.m_size;
@@ -1723,6 +1730,10 @@
    void priv_assign_aux(FwdIt first, FwdIt last, std::forward_iterator_tag)
    {
       size_type n = std::distance(first, last);
+ if(!n){
+ this->prot_destroy_all();
+ return;
+ }
       //Check if we have enough memory or try to expand current memory
       size_type remaining = this->members_.m_capacity - this->members_.m_size;
       bool same_buffer_start;
@@ -1749,7 +1760,6 @@
          if (this->size() >= n){
             //There is memory, but there are more old elements than new ones
             //Overwrite old elements with new ones
- // iG std::copy(first, last, start);
             std::copy(first, last, start);
             //Destroy remaining old elements
             this->destroy_n(start + n, this->members_.m_size - n);

Modified: branches/release/boost/interprocess/detail/atomic.hpp
==============================================================================
--- branches/release/boost/interprocess/detail/atomic.hpp (original)
+++ branches/release/boost/interprocess/detail/atomic.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -461,6 +461,98 @@
 } //namespace interprocess{
 } //namespace boost{
 
+#elif defined(__IBMCPP__) && (__IBMCPP__ >= 800) && defined(_AIX)
+
+#include <builtins.h>
+
+namespace boost {
+namespace interprocess {
+namespace detail{
+
+//first define boost::uint32_t versions of __lwarx and __stwcx to avoid poluting
+//all the functions with casts
+
+//! From XLC documenation :
+//! This function can be used with a subsequent stwcxu call to implement a
+//! read-modify-write on a specified memory location. The two functions work
+//! together to ensure that if the store is successfully performed, no other
+//! processor or mechanism can modify the target doubleword between the time
+//! lwarxu function is executed and the time the stwcxu functio ncompletes.
+//! "mem" : pointer to the object
+//! Returns the value at pointed to by mem
+inline boost::uint32_t lwarxu(volatile boost::uint32_t *mem)
+{
+ return static_cast<boost::uint32_t>(__lwarx(reinterpret_cast<volatile int*>(mem)));
+}
+
+//! "mem" : pointer to the object
+//! "val" : the value to store
+//! Returns true if the update of mem is successful and false if it is
+//!unsuccessful
+inline bool stwcxu(volatile boost::uint32_t* mem, boost::uint32_t val)
+{
+ return (__stwcx(reinterpret_cast<volatile int*>(mem), static_cast<int>(val)) != 0);
+}
+
+//! "mem": pointer to the object
+//! "val": amount to add
+//! Returns the old value pointed to by mem
+inline boost::uint32_t atomic_add32
+ (volatile boost::uint32_t *mem, boost::uint32_t val)
+{
+ boost::uint32_t oldValue;
+ do
+ {
+ oldValue = lwarxu(mem);
+ }while (!stwcxu(mem, oldValue+val));
+ return oldValue;
+}
+
+//! Atomically increment an apr_uint32_t by 1
+//! "mem": pointer to the object
+//! Returns the old value pointed to by mem
+inline boost::uint32_t atomic_inc32(volatile boost::uint32_t *mem)
+{ return atomic_add32(mem, 1); }
+
+//! Atomically decrement an boost::uint32_t by 1
+//! "mem": pointer to the atomic value
+//! Returns the old value pointed to by mem
+inline boost::uint32_t atomic_dec32(volatile boost::uint32_t *mem)
+{ return atomic_add32(mem, (boost::uint32_t)-1); }
+
+//! Atomically read an boost::uint32_t from memory
+inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem)
+{ return *mem; }
+
+//! Compare an boost::uint32_t's value with "cmp".
+//! If they are the same swap the value with "with"
+//! "mem": pointer to the value
+//! "with" what to swap it with
+//! "cmp": the value to compare it to
+//! Returns the old value of *mem
+inline boost::uint32_t atomic_cas32
+ (volatile boost::uint32_t *mem, boost::uint32_t with, boost::uint32_t cmp)
+{
+ boost::uint32_t oldValue;
+ boost::uint32_t valueToStore;
+ do
+ {
+ oldValue = lwarxu(mem);
+ } while (!stwcxu(mem, (oldValue == with) ? cmp : oldValue));
+
+ return oldValue;
+}
+
+//! Atomically set an boost::uint32_t in memory
+//! "mem": pointer to the object
+//! "param": val value that the object will assume
+inline void atomic_write32(volatile boost::uint32_t *mem, boost::uint32_t val)
+{ *mem = val; }
+
+} //namespace detail
+} //namespace interprocess
+} //namespace boost
+
 #else
 
 #error No atomic operations implemented for this platform, sorry!

Modified: branches/release/boost/interprocess/detail/os_file_functions.hpp
==============================================================================
--- branches/release/boost/interprocess/detail/os_file_functions.hpp (original)
+++ branches/release/boost/interprocess/detail/os_file_functions.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -84,6 +84,7 @@
 inline const char *get_temporary_path()
 { return std::getenv("TMP"); }
 
+
 inline file_handle_t create_new_file
    (const char *name, mode_t mode = read_write, bool temporary = false)
 {
@@ -311,12 +312,13 @@
 
 inline const char *get_temporary_path()
 {
+ struct stat data;
    const char *dir = std::getenv("TMPDIR");
- if(!dir){
+ if(!dir || ::stat(dir, &data) != 0){
       dir = std::getenv("TMP");
- if(!dir){
+ if(!dir || ::stat(dir, &data) != 0){
          dir = std::getenv("TEMP");
- if(!dir){
+ if(!dir || ::stat(dir, &data) != 0){
             dir = "/tmp";
          }
       }

Modified: branches/release/boost/interprocess/detail/os_thread_functions.hpp
==============================================================================
--- branches/release/boost/interprocess/detail/os_thread_functions.hpp (original)
+++ branches/release/boost/interprocess/detail/os_thread_functions.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -139,7 +139,7 @@
 }
 
 inline bool equal_thread_id(OS_thread_id_t id1, OS_thread_id_t id2)
-{ return 0 != ::pthread_equal(id1, id2); }
+{ return 0 != pthread_equal(id1, id2); }
 
 inline void thread_yield()
 { ::sched_yield(); }
@@ -152,7 +152,7 @@
 
 inline bool equal_systemwide_thread_id(const OS_systemwide_thread_id_t &id1, const OS_systemwide_thread_id_t &id2)
 {
- return (0 != ::pthread_equal(id1.tid, id2.tid)) && (id1.pid == id2.pid);
+ return (0 != pthread_equal(id1.tid, id2.tid)) && (id1.pid == id2.pid);
 }
 
 inline OS_systemwide_thread_id_t get_invalid_systemwide_thread_id()

Modified: branches/release/boost/interprocess/detail/tmp_dir_helpers.hpp
==============================================================================
--- branches/release/boost/interprocess/detail/tmp_dir_helpers.hpp (original)
+++ branches/release/boost/interprocess/detail/tmp_dir_helpers.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -84,18 +84,30 @@
 }
 #endif
 
-
-inline void tmp_filename(const char *filename, std::string &tmp_name)
+inline void get_tmp_base_dir(std::string &tmp_name)
 {
- const char *tmp_dir = get_temporary_path();
- if(!tmp_dir){
+ #if defined (BOOST_INTERPROCESS_WINDOWS)
+ winapi::get_shared_documents_folder(tmp_name);
+ if(tmp_name.empty()){
+ tmp_name = get_temporary_path();
+ }
+ #else
+ tmp_name = get_temporary_path();
+ #endif
+ if(tmp_name.empty()){
       error_info err = system_error_code();
       throw interprocess_exception(err);
    }
- tmp_name = tmp_dir;
+ //Remove final null.
+ tmp_name += "/boost_interprocess";
+}
+
 
+inline void tmp_filename(const char *filename, std::string &tmp_name)
+{
+ get_tmp_base_dir(tmp_name);
    //Remove final null.
- tmp_name += "/boost_interprocess/";
+ tmp_name += "/";
    #ifdef BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
    get_bootstamp(tmp_name, true);
    tmp_name += '/';
@@ -106,15 +118,7 @@
 inline void create_tmp_dir_and_get_filename(const char *filename, std::string &tmp_name)
 {
    //First get the temp directory
- const char *tmp_path = get_temporary_path();
- if(!tmp_path){
- error_info err = system_error_code();
- throw interprocess_exception(err);
- }
-
- //Create Boost.Interprocess dir
- tmp_name = tmp_path;
- tmp_name += "/boost_interprocess";
+ get_tmp_base_dir(tmp_name);
 
    //If fails, check that it's because already exists
    if(!create_directory(tmp_name.c_str())){

Modified: branches/release/boost/interprocess/detail/win32_api.hpp
==============================================================================
--- branches/release/boost/interprocess/detail/win32_api.hpp (original)
+++ branches/release/boost/interprocess/detail/win32_api.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -15,6 +15,7 @@
 #include <boost/interprocess/detail/workaround.hpp>
 #include <cstddef>
 #include <cstring>
+#include <string>
 #include <memory>
 
 #if (defined _MSC_VER) && (_MSC_VER >= 1200)
@@ -145,6 +146,9 @@
 static const long BootstampLength = 8;
 static const unsigned long MaxPath = 260;
 
+//Keys
+static void * const hkey_local_machine = (void*)(unsigned long*)(long)(0x80000002);
+static unsigned long key_query_value = 0x0001;
 
 } //namespace winapi {
 } //namespace interprocess {
@@ -440,6 +444,12 @@
 typedef long (__stdcall * NtQuerySystemInformation_t)(int, void*, unsigned long, unsigned long *);
 typedef long (__stdcall * NtQueryObject_t)(void*, object_information_class, void *, unsigned long, unsigned long *);
 typedef unsigned long (__stdcall * GetMappedFileName_t)(void *, void *, wchar_t *, unsigned long);
+typedef unsigned long (__stdcall * GetMappedFileName_t)(void *, void *, wchar_t *, unsigned long);
+typedef long (__stdcall * RegOpenKey_t)(void *, const char *, void **);
+typedef long (__stdcall * RegOpenKeyEx_t)(void *, const char *, unsigned long, unsigned long, void **);
+typedef long (__stdcall * RegQueryValue_t)(void *, const char *, char *, long*);
+typedef long (__stdcall * RegQueryValueEx_t)(void *, const char *, unsigned long*, unsigned long*, unsigned char *, unsigned long*);
+typedef long (__stdcall * RegCloseKey_t)(void *);
 
 } //namespace winapi {
 } //namespace interprocess {
@@ -453,7 +463,7 @@
 namespace interprocess {
 namespace winapi {
 
-static inline unsigned long format_message
+inline unsigned long format_message
    (unsigned long dwFlags, const void *lpSource,
     unsigned long dwMessageId, unsigned long dwLanguageId,
     char *lpBuffer, unsigned long nSize, std::va_list *Arguments)
@@ -463,34 +473,34 @@
 }
 
 //And now, wrapper functions
-static inline void * local_free(void *hmem)
+inline void * local_free(void *hmem)
 { return LocalFree(hmem); }
 
-static inline unsigned long make_lang_id(unsigned long p, unsigned long s)
+inline unsigned long make_lang_id(unsigned long p, unsigned long s)
 { return ((((unsigned short)(s)) << 10) | (unsigned short)(p)); }
 
-static inline void sched_yield()
+inline void sched_yield()
 { Sleep(1); }
 
-static inline unsigned long get_current_thread_id()
+inline unsigned long get_current_thread_id()
 { return GetCurrentThreadId(); }
 
-static inline unsigned long get_current_process_id()
+inline unsigned long get_current_process_id()
 { return GetCurrentProcessId(); }
 
-static inline unsigned int close_handle(void* handle)
+inline unsigned int close_handle(void* handle)
 { return CloseHandle(handle); }
 
-static inline void * find_first_file(const char *lpFileName, win32_find_data_t *lpFindFileData)
+inline void * find_first_file(const char *lpFileName, win32_find_data_t *lpFindFileData)
 { return FindFirstFileA(lpFileName, lpFindFileData); }
 
-static inline bool find_next_file(void *hFindFile, win32_find_data_t *lpFindFileData)
+inline bool find_next_file(void *hFindFile, win32_find_data_t *lpFindFileData)
 { return FindNextFileA(hFindFile, lpFindFileData) != 0; }
 
-static inline bool find_close(void *handle)
+inline bool find_close(void *handle)
 { return FindClose(handle) != 0; }
 
-static inline bool duplicate_current_process_handle
+inline bool duplicate_current_process_handle
    (void *hSourceHandle, void **lpTargetHandle)
 {
    return 0 != DuplicateHandle
@@ -499,41 +509,41 @@
       , duplicate_same_access);
 }
 
-static inline unsigned long get_last_error()
+inline unsigned long get_last_error()
 { return GetLastError(); }
 
-static inline void get_system_time_as_file_time(interprocess_filetime *filetime)
+inline void get_system_time_as_file_time(interprocess_filetime *filetime)
 { GetSystemTimeAsFileTime(filetime); }
 
-static inline bool file_time_to_local_file_time
+inline bool file_time_to_local_file_time
    (const interprocess_filetime *in, const interprocess_filetime *out)
 { return 0 != FileTimeToLocalFileTime(in, out); }
 
-static inline void *create_mutex(const char *name)
+inline void *create_mutex(const char *name)
 { return CreateMutexA(0, 0, name); }
 
-static inline void *open_mutex(const char *name)
+inline void *open_mutex(const char *name)
 { return OpenMutexA(mutex_all_access, 0, name); }
 
-static inline unsigned long wait_for_single_object(void *handle, unsigned long time)
+inline unsigned long wait_for_single_object(void *handle, unsigned long time)
 { return WaitForSingleObject(handle, time); }
 
-static inline int release_mutex(void *handle)
+inline int release_mutex(void *handle)
 { return ReleaseMutex(handle); }
 
-static inline int unmap_view_of_file(void *address)
+inline int unmap_view_of_file(void *address)
 { return UnmapViewOfFile(address); }
 
-static inline void *create_semaphore(long initialCount, const char *name)
+inline void *create_semaphore(long initialCount, const char *name)
 { return CreateSemaphoreA(0, initialCount, (long)(((unsigned long)(-1))>>1), name); }
 
-static inline int release_semaphore(void *handle, long release_count, long *prev_count)
+inline int release_semaphore(void *handle, long release_count, long *prev_count)
 { return ReleaseSemaphore(handle, release_count, prev_count); }
 
-static inline void *open_semaphore(const char *name)
+inline void *open_semaphore(const char *name)
 { return OpenSemaphoreA(semaphore_all_access, 1, name); }
 
-static inline void * create_file_mapping (void * handle, unsigned long access, unsigned long high_size, unsigned long low_size, const char * name)
+inline void * create_file_mapping (void * handle, unsigned long access, unsigned long high_size, unsigned long low_size, const char * name)
 {
    interprocess_security_attributes sa;
    interprocess_security_descriptor sd;
@@ -549,86 +559,86 @@
   //return CreateFileMappingA (handle, 0, access, high_size, low_size, name);
 }
 
-static inline void * open_file_mapping (unsigned long access, const char *name)
+inline void * open_file_mapping (unsigned long access, const char *name)
 { return OpenFileMappingA (access, 0, name); }
 
-static inline void *map_view_of_file_ex(void *handle, unsigned long file_access, unsigned long highoffset, unsigned long lowoffset, std::size_t numbytes, void *base_addr)
+inline void *map_view_of_file_ex(void *handle, unsigned long file_access, unsigned long highoffset, unsigned long lowoffset, std::size_t numbytes, void *base_addr)
 { return MapViewOfFileEx(handle, file_access, highoffset, lowoffset, numbytes, base_addr); }
 
-static inline void *create_file(const char *name, unsigned long access, unsigned long creation_flags, unsigned long attributes = 0)
+inline void *create_file(const char *name, unsigned long access, unsigned long creation_flags, unsigned long attributes = 0)
 { return CreateFileA(name, access, file_share_read | file_share_write | file_share_delete, 0, creation_flags, attributes, 0); }
 
-static inline bool delete_file(const char *name)
+inline bool delete_file(const char *name)
 { return 0 != DeleteFileA(name); }
 
-static inline bool move_file_ex(const char *source_filename, const char *destination_filename, unsigned long flags)
+inline bool move_file_ex(const char *source_filename, const char *destination_filename, unsigned long flags)
 { return 0 != MoveFileExA(source_filename, destination_filename, flags); }
 
-static inline void get_system_info(system_info *info)
+inline void get_system_info(system_info *info)
 { GetSystemInfo(info); }
 
-static inline int flush_view_of_file(void *base_addr, std::size_t numbytes)
+inline int flush_view_of_file(void *base_addr, std::size_t numbytes)
 { return FlushViewOfFile(base_addr, numbytes); }
 
-static inline bool get_file_size(void *handle, __int64 &size)
+inline bool get_file_size(void *handle, __int64 &size)
 { return 0 != GetFileSizeEx(handle, &size); }
 
-static inline bool create_directory(const char *name, interprocess_security_attributes* security)
+inline bool create_directory(const char *name, interprocess_security_attributes* security)
 { return 0 != CreateDirectoryA(name, security); }
 
-static inline bool remove_directory(const char *lpPathName)
+inline bool remove_directory(const char *lpPathName)
 { return 0 != RemoveDirectoryA(lpPathName); }
 
-static inline unsigned long get_temp_path(unsigned long length, char *buffer)
+inline unsigned long get_temp_path(unsigned long length, char *buffer)
 { return GetTempPathA(length, buffer); }
 
-static inline int set_end_of_file(void *handle)
+inline int set_end_of_file(void *handle)
 { return 0 != SetEndOfFile(handle); }
 
-static inline bool set_file_pointer_ex(void *handle, __int64 distance, __int64 *new_file_pointer, unsigned long move_method)
+inline bool set_file_pointer_ex(void *handle, __int64 distance, __int64 *new_file_pointer, unsigned long move_method)
 { return 0 != SetFilePointerEx(handle, distance, new_file_pointer, move_method); }
 
-static inline bool lock_file_ex(void *hnd, unsigned long flags, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped *overlapped)
+inline bool lock_file_ex(void *hnd, unsigned long flags, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped *overlapped)
 { return 0 != LockFileEx(hnd, flags, reserved, size_low, size_high, overlapped); }
 
-static inline bool unlock_file_ex(void *hnd, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped *overlapped)
+inline bool unlock_file_ex(void *hnd, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped *overlapped)
 { return 0 != UnlockFileEx(hnd, reserved, size_low, size_high, overlapped); }
 
-static inline bool write_file(void *hnd, const void *buffer, unsigned long bytes_to_write, unsigned long *bytes_written, interprocess_overlapped* overlapped)
+inline bool write_file(void *hnd, const void *buffer, unsigned long bytes_to_write, unsigned long *bytes_written, interprocess_overlapped* overlapped)
 { return 0 != WriteFile(hnd, buffer, bytes_to_write, bytes_written, overlapped); }
 
-static inline long interlocked_increment(long volatile *addr)
+inline long interlocked_increment(long volatile *addr)
 { return BOOST_INTERLOCKED_INCREMENT(addr); }
 
-static inline long interlocked_decrement(long volatile *addr)
+inline long interlocked_decrement(long volatile *addr)
 { return BOOST_INTERLOCKED_DECREMENT(addr); }
 
-static inline long interlocked_compare_exchange(long volatile *addr, long val1, long val2)
+inline long interlocked_compare_exchange(long volatile *addr, long val1, long val2)
 { return BOOST_INTERLOCKED_COMPARE_EXCHANGE(addr, val1, val2); }
 
-static inline long interlocked_exchange_add(long volatile* addend, long value)
+inline long interlocked_exchange_add(long volatile* addend, long value)
 { return BOOST_INTERLOCKED_EXCHANGE_ADD(const_cast<long*>(addend), value); }
 
-static inline long interlocked_exchange(long volatile* addend, long value)
+inline long interlocked_exchange(long volatile* addend, long value)
 { return BOOST_INTERLOCKED_EXCHANGE(const_cast<long*>(addend), value); }
 
 //Forward functions
-static inline void *load_library(const char *name)
+inline void *load_library(const char *name)
 { return LoadLibraryA(name); }
 
-static inline bool free_library(void *module)
+inline bool free_library(void *module)
 { return 0 != FreeLibrary(module); }
 
-static inline void *get_proc_address(void *module, const char *name)
+inline void *get_proc_address(void *module, const char *name)
 { return GetProcAddress(module, name); }
 
-static inline void *get_current_process()
+inline void *get_current_process()
 { return GetCurrentProcess(); }
 
-static inline void *get_module_handle(const char *name)
+inline void *get_module_handle(const char *name)
 { return GetModuleHandleA(name); }
 
-static inline void initialize_object_attributes
+inline void initialize_object_attributes
 ( object_attributes_t *pobject_attr, unicode_string_t *name
  , unsigned long attr, void *rootdir, void *security_descr)
 
@@ -641,7 +651,7 @@
    pobject_attr->SecurityQualityOfService = 0;
 }
 
-static inline void rtl_init_empty_unicode_string(unicode_string_t *ucStr, wchar_t *buf, unsigned short bufSize)
+inline void rtl_init_empty_unicode_string(unicode_string_t *ucStr, wchar_t *buf, unsigned short bufSize)
 {
    ucStr->Buffer = buf;
    ucStr->Length = 0;
@@ -649,9 +659,15 @@
 }
 
 //Complex winapi based functions...
+struct library_unloader
+{
+ void *lib_;
+ library_unloader(void *module) : lib_(module){}
+ ~library_unloader(){ free_library(lib_); }
+};
 
 //pszFilename must have room for at least MaxPath+1 characters
-static inline bool get_file_name_from_handle_function
+inline bool get_file_name_from_handle_function
    (void * hFile, wchar_t *pszFilename, std::size_t length, std::size_t &out_length)
 {
    if(length <= MaxPath){
@@ -662,14 +678,7 @@
    if (0 == hiPSAPI)
       return 0;
 
- class library_unloader
- {
- void *lib_;
-
- public:
- library_unloader(void *module) : lib_(module){}
- ~library_unloader(){ free_library(lib_); }
- } unloader(hiPSAPI);
+ library_unloader unloader(hiPSAPI);
 
    // Pointer to function getMappedFileName() in PSAPI.DLL
    GetMappedFileName_t pfGMFN =
@@ -700,7 +709,7 @@
    return(bSuccess);
 }
 
-static inline bool get_system_time_of_day_information(system_timeofday_information &info)
+inline bool get_system_time_of_day_information(system_timeofday_information &info)
 {
    NtQuerySystemInformation_t pNtQuerySystemInformation = (NtQuerySystemInformation_t)
       get_proc_address(get_module_handle("ntdll.dll"), "NtQuerySystemInformation");
@@ -712,7 +721,7 @@
    return true;
 }
 
-static inline bool get_boot_time(unsigned char (&bootstamp) [BootstampLength])
+inline bool get_boot_time(unsigned char (&bootstamp) [BootstampLength])
 {
    system_timeofday_information info;
    bool ret = get_system_time_of_day_information(info);
@@ -723,7 +732,7 @@
    return true;
 }
 
-static inline bool get_boot_and_system_time(unsigned char (&bootsystemstamp) [BootAndSystemstampLength])
+inline bool get_boot_and_system_time(unsigned char (&bootsystemstamp) [BootAndSystemstampLength])
 {
    system_timeofday_information info;
    bool ret = get_system_time_of_day_information(info);
@@ -734,7 +743,7 @@
    return true;
 }
 
-static inline bool get_boot_time_str(char *bootstamp_str, std::size_t &s) //will write BootstampLength chars
+inline bool get_boot_time_str(char *bootstamp_str, std::size_t &s) //will write BootstampLength chars
 {
    if(s < (BootstampLength*2))
       return false;
@@ -755,7 +764,7 @@
    return true;
 }
 
-static inline bool get_boot_and_system_time_wstr(wchar_t *bootsystemstamp, std::size_t &s) //will write BootAndSystemstampLength chars
+inline bool get_boot_and_system_time_wstr(wchar_t *bootsystemstamp, std::size_t &s) //will write BootAndSystemstampLength chars
 {
    if(s < (BootAndSystemstampLength*2))
       return false;
@@ -776,7 +785,25 @@
    return true;
 }
 
-static inline bool unlink_file(const char *filename)
+class handle_closer
+{
+ void *handle_;
+ public:
+ handle_closer(void *handle) : handle_(handle){}
+ ~handle_closer(){ close_handle(handle_); }
+};
+
+union ntquery_mem_t
+{
+ object_name_information_t name;
+ struct ren_t
+ {
+ file_rename_information_t info;
+ wchar_t buf[32767];
+ } ren;
+};
+
+inline bool unlink_file(const char *filename)
 {
    try{
       NtSetInformationFile_t pNtSetInformationFile =
@@ -795,44 +822,16 @@
          return false;
       }
 
- class handle_closer
- {
- void *handle_;
- public:
- handle_closer(void *handle) : handle_(handle){}
- ~handle_closer(){ close_handle(handle_); }
- } handle_closer(fh);
-
- const std::size_t CharArraySize = 32767; //Max name length
-
- union mem_t
- {
- object_name_information_t name;
- struct ren_t
- {
- file_rename_information_t info;
- wchar_t buf[CharArraySize];
- } ren;
- };
-
- class auto_ptr
- {
- public:
- explicit auto_ptr(mem_t *ptr) : ptr_(ptr){}
- ~auto_ptr(){ delete ptr_; }
- mem_t *get() const{ return (ptr_); }
- mem_t *operator->() const{ return this->get(); }
- private:
- mem_t *ptr_;
- } pmem(new mem_t);
+ handle_closer h_closer(fh);
 
+ std::auto_ptr<ntquery_mem_t> pmem(new ntquery_mem_t);
       file_rename_information_t *pfri = (file_rename_information_t*)&pmem->ren.info;
       const std::size_t RenMaxNumChars =
          ((char*)pmem.get() - (char*)&pmem->ren.info.FileName[0])/sizeof(wchar_t);
 
       //Obtain file name
       unsigned long size;
- if(pNtQueryObject(fh, object_name_information, pmem.get(), sizeof(mem_t), &size)){
+ if(pNtQueryObject(fh, object_name_information, pmem.get(), sizeof(ntquery_mem_t), &size)){
          return false;
       }
 
@@ -870,7 +869,7 @@
 
       //Final step: change the name of the in-use file:
       io_status_block_t io;
- if(0 != pNtSetInformationFile(fh, &io, pfri, sizeof(mem_t::ren_t), file_rename_information)){
+ if(0 != pNtSetInformationFile(fh, &io, pfri, sizeof(ntquery_mem_t::ren_t), file_rename_information)){
          return false;
       }
       return true;
@@ -880,6 +879,61 @@
    }
 }
 
+struct reg_closer
+{
+ RegCloseKey_t func_;
+ void *key_;
+ reg_closer(RegCloseKey_t func, void *key) : func_(func), key_(key){}
+ ~reg_closer(){ (*func_)(key_); }
+};
+
+inline void get_shared_documents_folder(std::string &s)
+{
+ s.clear();
+ void *hAdvapi = load_library("Advapi32.dll");
+ if (hAdvapi){
+ library_unloader unloader(hAdvapi);
+ // Pointer to function RegOpenKeyA
+ RegOpenKeyEx_t pRegOpenKey =
+ (RegOpenKeyEx_t)get_proc_address(hAdvapi, "RegOpenKeyExA");
+ if (pRegOpenKey){
+ // Pointer to function RegCloseKey
+ RegCloseKey_t pRegCloseKey =
+ (RegCloseKey_t)get_proc_address(hAdvapi, "RegCloseKey");
+ if (pRegCloseKey){
+ // Pointer to function RegQueryValueA
+ RegQueryValueEx_t pRegQueryValue =
+ (RegQueryValueEx_t)get_proc_address(hAdvapi, "RegQueryValueExA");
+ if (pRegQueryValue){
+ //Open the key
+ void *key;
+ if ((*pRegOpenKey)( hkey_local_machine
+ , "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
+ , 0
+ , key_query_value
+ , &key) == 0){
+ reg_closer key_closer(pRegCloseKey, key);
+
+ //Obtain the value
+ unsigned long size;
+ unsigned long type;
+ const char *const reg_value = "Common AppData";
+ long err = (*pRegQueryValue)( key, reg_value, 0, &type, 0, &size);
+ if(!err){
+ //Size includes terminating NULL
+ s.resize(size);
+ err = (*pRegQueryValue)( key, reg_value, 0, &type, (unsigned char*)(&s[0]), &size);
+ if(!err)
+ s.erase(s.end()-1);
+ (void)err;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
 } //namespace winapi
 } //namespace interprocess
 } //namespace boost

Modified: branches/release/boost/interprocess/detail/workaround.hpp
==============================================================================
--- branches/release/boost/interprocess/detail/workaround.hpp (original)
+++ branches/release/boost/interprocess/detail/workaround.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -62,6 +62,11 @@
    #else
    #endif
 
+ //Check for XSI shared memory objects. They are available in nearly all UNIX platforms
+ #if !defined(__QNXNTO__)
+ # define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
+ #endif
+
    #if ((_POSIX_SHARED_MEMORY_OBJECTS - 0) > 0)
    # define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
    #else
@@ -70,13 +75,18 @@
    # if __CRTL_VER >= 70200000
    # define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
    # endif
- # define BOOST_INTERPROCESS_SYSTEM_V_SHARED_MEMORY_OBJECTS
    //Mac OS has some non-conformant features like names limited to SHM_NAME_MAX
    //# elif defined (__APPLE__)
    //# define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
    # endif
    #endif
 
+ //Now check if we have only XSI shared memory
+ #if defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS) &&\
+ !defined(BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS)
+ //# define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS_ONLY
+ #endif
+
    #if ((_POSIX_TIMEOUTS - 0) > 0)
    # define BOOST_INTERPROCESS_POSIX_TIMEOUTS
    #endif

Modified: branches/release/boost/interprocess/errors.hpp
==============================================================================
--- branches/release/boost/interprocess/errors.hpp (original)
+++ branches/release/boost/interprocess/errors.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -50,7 +50,7 @@
 namespace boost {
 namespace interprocess {
 /// @cond
-static inline int system_error_code() // artifact of POSIX and WINDOWS error reporting
+inline int system_error_code() // artifact of POSIX and WINDOWS error reporting
 {
    #if (defined BOOST_INTERPROCESS_WINDOWS)
    return winapi::get_last_error();
@@ -82,7 +82,7 @@
       str.erase( str.size()-1 );
 }
 # else
-static inline void fill_system_message( int system_error, std::string &str)
+inline void fill_system_message( int system_error, std::string &str)
 { str = std::strerror(system_error); }
 # endif
 /// @endcond
@@ -179,7 +179,7 @@
    #endif //#if (defined BOOST_INTERPROCESS_WINDOWS)
 };
 
-static inline error_code_t lookup_error(native_error_t err)
+inline error_code_t lookup_error(native_error_t err)
 {
    const ec_xlate *cur = &ec_table[0],
                   *end = cur + sizeof(ec_table)/sizeof(ec_xlate);

Modified: branches/release/boost/interprocess/interprocess_fwd.hpp
==============================================================================
--- branches/release/boost/interprocess/interprocess_fwd.hpp (original)
+++ branches/release/boost/interprocess/interprocess_fwd.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -254,6 +254,7 @@
 
 #else
 
+#if defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
 template <class CharType
          ,class MemoryAlgorithm
          ,template<class IndexConfig> class IndexType>
@@ -270,6 +271,7 @@
    ,rbtree_best_fit<mutex_family>
    ,iset_index>
 wmanaged_xsi_shared_memory;
+#endif //#if defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
 
 #endif //#if defined (BOOST_INTERPROCESS_WINDOWS)
 

Modified: branches/release/boost/interprocess/mapped_region.hpp
==============================================================================
--- branches/release/boost/interprocess/mapped_region.hpp (original)
+++ branches/release/boost/interprocess/mapped_region.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -31,7 +31,9 @@
 # include <unistd.h>
 # include <sys/stat.h>
 # include <sys/types.h>
+# ifdef BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
 # include <sys/shm.h>
+# endif
 # include <cassert>
 # else
 # error Unknown platform
@@ -397,6 +399,8 @@
 {
    mapping_handle_t map_hnd = mapping.get_mapping_handle();
 
+ //Some systems dont' support XSI shared memory
+ #ifdef BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
    if(map_hnd.is_xsi){
       //Get the size
       ::shmid_ds xsi_ds;
@@ -435,10 +439,9 @@
       m_mode = mode;
       m_extra_offset = 0;
       m_is_xsi = true;
-
       return;
    }
-
+ #endif //ifdef BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
    if(size == 0){
       offset_t filesize = lseek
          (map_hnd.handle, offset, SEEK_END);
@@ -548,12 +551,14 @@
 inline void mapped_region::priv_close()
 {
    if(m_base != MAP_FAILED){
+ #ifdef BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
       if(m_is_xsi){
          int ret = ::shmdt(m_base);
          assert(ret == 0);
          (void)ret;
          return;
       }
+ #endif //#ifdef BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
       munmap(static_cast<char*>(m_base) - m_extra_offset, m_size + m_extra_offset);
       m_base = MAP_FAILED;
    }

Modified: branches/release/boost/interprocess/shared_memory_object.hpp
==============================================================================
--- branches/release/boost/interprocess/shared_memory_object.hpp (original)
+++ branches/release/boost/interprocess/shared_memory_object.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -24,7 +24,7 @@
 #include <string>
 #include <algorithm>
 
-#if defined(BOOST_INTERPROCESS_SYSTEM_V_SHARED_MEMORY_OBJECTS)
+#if defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS_ONLY)
 # include <sys/shm.h> //System V shared memory...
 #elif defined(BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS)
 # include <fcntl.h> //O_CREAT, O_*...
@@ -307,7 +307,7 @@
       #else
       detail::tmp_filename(filename, file_str);
       #endif
- return 0 != shm_unlink(file_str.c_str());
+ return 0 == shm_unlink(file_str.c_str());
    }
    catch(...){
       return false;

Modified: branches/release/boost/interprocess/streams/vectorstream.hpp
==============================================================================
--- branches/release/boost/interprocess/streams/vectorstream.hpp (original)
+++ branches/release/boost/interprocess/streams/vectorstream.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -108,23 +108,12 @@
             //Restore the vector's size if necessary
             mp_high_water = base_t::pptr();
          }
+ //This does not reallocate
          m_vect.resize(mp_high_water - (m_vect.size() ? &m_vect[0] : 0));
-
- //Now swap vector
- m_vect.swap(vect);
-
- //If the stream is writable put the high water mark
- //and maximize the size.
- typename vector_type::size_type old_size = m_vect.size();
- m_vect.resize(m_vect.capacity());
- this->initialize_pointers();
- mp_high_water = old_size ? &m_vect[0] + old_size : 0;
- }
- else{
- //Now swap vector
- m_vect.swap(vect);
- this->initialize_pointers();
       }
+ //Now swap vector
+ m_vect.swap(vect);
+ this->initialize_pointers();
    }
 
    //!Returns a const reference to the internal vector.
@@ -136,8 +125,17 @@
             //Restore the vector's size if necessary
             mp_high_water = base_t::pptr();
          }
- m_vect.resize(mp_high_water - (m_vect.size() ? &m_vect[0] : 0));
- const_cast<basic_vectorbuf * const>(this)->initialize_pointers();
+ //This shouldn't reallocate
+ typedef typename vector_type::size_type size_type;
+ char_type *old_ptr = base_t::pbase();
+ size_type high_pos = size_type(mp_high_water-old_ptr);
+ if(m_vect.size() > high_pos){
+ m_vect.resize(high_pos);
+ //But we must update end write pointer because vector size is now shorter
+ int old_pos = base_t::pptr() - base_t::pbase();
+ const_cast<basic_vectorbuf*>(this)->base_t::setp(old_ptr, old_ptr + high_pos);
+ const_cast<basic_vectorbuf*>(this)->base_t::pbump(old_pos);
+ }
       }
       return m_vect;
    }
@@ -147,25 +145,33 @@
    //!Throws if the internals vector's memory allocation throws.
    void reserve(typename vector_type::size_type size)
    {
- m_vect.reserve(size);
- //Now update pointer data
- typename vector_type::size_type old_size = m_vect.size();
- m_vect.resize(m_vect.capacity());
- this->initialize_pointers();
- mp_high_water = old_size ? &m_vect[0] + old_size : 0;
+ if (this->m_mode & std::ios_base::out && size > m_vect.size()){
+ typename vector_type::difference_type write_pos = base_t::pptr() - base_t::pbase();
+ typename vector_type::difference_type read_pos = base_t::gptr() - base_t::eback();
+ //Now update pointer data
+ m_vect.reserve(size);
+ this->initialize_pointers();
+ base_t::pbump((int)write_pos);
+ if(this->m_mode & std::ios_base::in){
+ base_t::gbump((int)read_pos);
+ }
+ }
    }
 
    //!Calls clear() method of the internal vector.
    //!Resets the stream to the first position.
- void clear()
+ void clear()
    { m_vect.clear(); this->initialize_pointers(); }
 
    /// @cond
    private:
+ //Maximizes high watermark to the initial vector size,
+ //initializes read and write iostream buffers to the capacity
+ //and resets stream positions
    void initialize_pointers()
    {
       // The initial read position is the beginning of the vector.
- if(m_mode & std::ios_base::in){
+ if(!(m_mode & std::ios_base::out)){
          if(m_vect.empty()){
             this->setg(0, 0, 0);
          }
@@ -176,17 +182,29 @@
 
       // The initial write position is the beginning of the vector.
       if(m_mode & std::ios_base::out){
+ //First get real size
+ int real_size = (int)m_vect.size();
+ //Then maximize size for high watermarking
+ m_vect.resize(m_vect.capacity());
+ assert(m_vect.size() == m_vect.capacity());
+ //Set high watermarking with the expanded size
+ mp_high_water = m_vect.size() ? (&m_vect[0] + real_size) : 0;
+ //Now set formatting pointers
          if(m_vect.empty()){
             this->setp(0, 0);
+ if(m_mode & std::ios_base::in)
+ this->setg(0, 0, 0);
          }
          else{
- this->setp(&m_vect[0], &m_vect[0] + m_vect.size());
+ char_type *p = &m_vect[0];
+ this->setp(p, p + m_vect.size());
+ if(m_mode & std::ios_base::in)
+ this->setg(p, p, p + real_size);
+ }
+ if (m_mode & (std::ios_base::app | std::ios_base::ate)){
+ base_t::pbump((int)real_size);
          }
-
- if (m_mode & (std::ios_base::app | std::ios_base::ate))
- base_t::pbump((int)m_vect.size());
       }
- mp_high_water = m_vect.empty() ? 0 : (&m_vect[0] + m_vect.size());
    }
 
    protected:
@@ -194,10 +212,12 @@
    {
       if (base_t::gptr() == 0)
          return CharTraits::eof();
- if (mp_high_water < base_t::pptr())
- mp_high_water = base_t::pptr();
- if (base_t::egptr() < mp_high_water)
- base_t::setg(base_t::eback(), base_t::gptr(), mp_high_water);
+ if(m_mode & std::ios_base::out){
+ if (mp_high_water < base_t::pptr())
+ mp_high_water = base_t::pptr();
+ if (base_t::egptr() < mp_high_water)
+ base_t::setg(base_t::eback(), base_t::gptr(), mp_high_water);
+ }
       if (base_t::gptr() < base_t::egptr())
          return CharTraits::to_int_type(*base_t::gptr());
       return CharTraits::eof();
@@ -232,48 +252,27 @@
    {
       if(m_mode & std::ios_base::out) {
          if(!CharTraits::eq_int_type(c, CharTraits::eof())) {
-// if(!(m_mode & std::ios_base::in)) {
-// if(this->pptr() < this->epptr()) {
-// *this->pptr() = CharTraits::to_char_type(c);
-// this->pbump(1);
-// if (mp_high_water < base_t::pptr())
-// mp_high_water = base_t::pptr();
-// if ((m_mode & std::ios_base::in) && base_t::egptr() < mp_high_water)
-// base_t::setg(base_t::eback(), base_t::gptr(), mp_high_water);
-// return c;
-// }
-// else
-// return CharTraits::eof();
-// }
-// else {
-// try{
- typedef typename vector_type::difference_type dif_t;
- dif_t inpos = base_t::gptr() - base_t::eback();
- //The new output position is the previous one plus one
- //because 'overflow' requires putting 'c' on the buffer
- dif_t new_outpos = base_t::pptr() - base_t::pbase() + 1;
- //Adjust high water if necessary
- dif_t hipos = mp_high_water - base_t::pbase();
- if (hipos < new_outpos)
- hipos = new_outpos;
- //Insert the new data
- m_vect.push_back(CharTraits::to_char_type(c));
- m_vect.resize(m_vect.capacity());
- char_type* p = const_cast<char_type*>(&m_vect[0]);
- //A reallocation has happened, update pointers
- if (m_mode & std::ios_base::in)
- base_t::setg(p, p + inpos, p + hipos);
- base_t::setp(p, p + (dif_t)m_vect.size());
- //Update write position to the old position + 1
- base_t::pbump((int)new_outpos);
- //Update high water pointer, since the buffer has been reallocated
- mp_high_water = base_t::pbase() + hipos;
- return c;
-// }
-// catch(...){
-// return CharTraits::eof();
-// }
-// }
+ typedef typename vector_type::difference_type dif_t;
+ //The new output position is the previous one plus one
+ //because 'overflow' requires putting 'c' on the buffer
+ dif_t new_outpos = base_t::pptr() - base_t::pbase() + 1;
+ //Adjust high water if necessary
+ dif_t hipos = mp_high_water - base_t::pbase();
+ if (hipos < new_outpos)
+ hipos = new_outpos;
+ //Insert the new data
+ m_vect.push_back(CharTraits::to_char_type(c));
+ m_vect.resize(m_vect.capacity());
+ assert(m_vect.size() == m_vect.capacity());
+ char_type* p = const_cast<char_type*>(&m_vect[0]);
+ //A reallocation might have happened, update pointers
+ base_t::setp(p, p + (dif_t)m_vect.size());
+ mp_high_water = p + hipos;
+ if (m_mode & std::ios_base::in)
+ base_t::setg(p, p + (base_t::gptr() - base_t::eback()), mp_high_water);
+ //Update write position to the old position + 1
+ base_t::pbump((int)new_outpos);
+ return c;
          }
          else // c is EOF, so we don't have to do anything
             return CharTraits::not_eof(c);
@@ -286,21 +285,12 @@
                               std::ios_base::openmode mode
                                  = std::ios_base::in | std::ios_base::out)
    {
- bool in = false, out = false;
-
- const std::ios_base::openmode inout =
- std::ios_base::in | std::ios_base::out;
-
- if((mode & inout) == inout) {
- if(dir == std::ios_base::beg || dir == std::ios_base::end)
- in = out = true;
- }
- else if(mode & std::ios_base::in)
- in = true;
- else if(mode & std::ios_base::out)
- out = true;
-
- if(!in && !out)
+ //Get seek mode
+ bool in(0 != (mode & std::ios_base::in)), out(0 != (mode & std::ios_base::out));
+ //Test for logic errors
+ if(!in & !out)
+ return pos_type(off_type(-1));
+ else if((in && out) && (dir == std::ios_base::cur))
          return pos_type(off_type(-1));
       else if((in && (!(m_mode & std::ios_base::in) || this->gptr() == 0)) ||
                (out && (!(m_mode & std::ios_base::out) || this->pptr() == 0)))
@@ -310,8 +300,22 @@
       //Just calculate the end of the stream. If the stream is read-only
       //the limit is the size of the vector. Otherwise, the high water mark
       //will mark the real size.
- off_type limit = static_cast<off_type> (mode & std::ios_base::out ?
- mp_high_water - base_t::pbase() : m_vect.size()/*mp_high_water - base_t::eback()*/);
+ off_type limit;
+ if(m_mode & std::ios_base::out){
+ //Update high water marking because pptr() is going to change and it might
+ //have been updated since last overflow()
+ if(mp_high_water < base_t::pptr())
+ mp_high_water = base_t::pptr();
+ //Update read limits in case high water mark was changed
+ if(m_mode & std::ios_base::in){
+ if (base_t::egptr() < mp_high_water)
+ base_t::setg(base_t::eback(), base_t::gptr(), mp_high_water);
+ }
+ limit = static_cast<off_type>(mp_high_water - base_t::pbase());
+ }
+ else{
+ limit = static_cast<off_type>(m_vect.size());
+ }
 
       switch(dir) {
          case std::ios_base::beg:
@@ -334,6 +338,9 @@
          return pos_type(-1);
       if (m_mode & std::ios_base::app && mode & std::ios_base::out && newoff != limit)
          return pos_type(-1);
+ //This can reassign pointers
+ //if(m_vect.size() != m_vect.capacity())
+ //this->initialize_pointers();
       if (in)
          base_t::setg(base_t::eback(), base_t::eback() + newoff, base_t::egptr());
       if (out){

Modified: branches/release/boost/interprocess/sync/emulation/interprocess_semaphore.hpp
==============================================================================
--- branches/release/boost/interprocess/sync/emulation/interprocess_semaphore.hpp (original)
+++ branches/release/boost/interprocess/sync/emulation/interprocess_semaphore.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -18,9 +18,13 @@
 inline interprocess_semaphore::~interprocess_semaphore()
 {}
 
-inline interprocess_semaphore::interprocess_semaphore(int initialCount)
+inline interprocess_semaphore::interprocess_semaphore(unsigned int initialCount)
    : m_mut(), m_cond(), m_count(initialCount)
-{}
+{
+ if(m_count < 0){
+ throw interprocess_exception(size_error);
+ }
+}
 
 inline void interprocess_semaphore::post()
 {

Modified: branches/release/boost/interprocess/sync/interprocess_semaphore.hpp
==============================================================================
--- branches/release/boost/interprocess/sync/interprocess_semaphore.hpp (original)
+++ branches/release/boost/interprocess/sync/interprocess_semaphore.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -62,7 +62,7 @@
    public:
    //!Creates a interprocess_semaphore with the given initial count.
    //!interprocess_exception if there is an error.*/
- interprocess_semaphore(int initialCount);
+ interprocess_semaphore(unsigned int initialCount);
 
    //!Destroys the interprocess_semaphore.
    //!Does not throw

Modified: branches/release/boost/interprocess/sync/named_semaphore.hpp
==============================================================================
--- branches/release/boost/interprocess/sync/named_semaphore.hpp (original)
+++ branches/release/boost/interprocess/sync/named_semaphore.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -53,7 +53,7 @@
    public:
    //!Creates a global semaphore with a name, and an initial count.
    //!If the semaphore can't be created throws interprocess_exception
- named_semaphore(create_only_t, const char *name, int initialCount);
+ named_semaphore(create_only_t, const char *name, unsigned int initialCount);
 
    //!Opens or creates a global semaphore with a name, and an initial count.
    //!If the semaphore is created, this call is equivalent to
@@ -61,7 +61,7 @@
    //!If the semaphore is already created, this call is equivalent to
    //!named_semaphore(open_only_t, ... )
    //!and initialCount is ignored.
- named_semaphore(open_or_create_t, const char *name, int initialCount);
+ named_semaphore(open_or_create_t, const char *name, unsigned int initialCount);
 
    //!Opens a global semaphore with a name if that semaphore is previously.
    //!created. If it is not previously created this function throws
@@ -124,12 +124,12 @@
 #if defined(BOOST_INTERPROCESS_NAMED_SEMAPHORE_USES_POSIX_SEMAPHORES)
 
 inline named_semaphore::named_semaphore
- (create_only_t, const char *name, int initialCount)
+ (create_only_t, const char *name, unsigned int initialCount)
    : m_sem(detail::DoCreate, name, read_write, initialCount)
 {}
 
 inline named_semaphore::named_semaphore
- (open_or_create_t, const char *name, int initialCount)
+ (open_or_create_t, const char *name, unsigned int initialCount)
    : m_sem(detail::DoOpenOrCreate, name, read_write, initialCount)
 {}
 
@@ -174,7 +174,7 @@
 { detail::interprocess_tester::dont_close_on_destruction(m_shmem); }
 
 inline named_semaphore::named_semaphore
- (create_only_t, const char *name, int initialCount)
+ (create_only_t, const char *name, unsigned int initialCount)
    : m_shmem (create_only
                ,name
                ,sizeof(interprocess_semaphore) +
@@ -186,7 +186,7 @@
 {}
 
 inline named_semaphore::named_semaphore
- (open_or_create_t, const char *name, int initialCount)
+ (open_or_create_t, const char *name, unsigned int initialCount)
    : m_shmem (open_or_create
                ,name
                ,sizeof(interprocess_semaphore) +

Modified: branches/release/boost/interprocess/sync/posix/interprocess_semaphore.hpp
==============================================================================
--- branches/release/boost/interprocess/sync/posix/interprocess_semaphore.hpp (original)
+++ branches/release/boost/interprocess/sync/posix/interprocess_semaphore.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -18,7 +18,7 @@
 inline interprocess_semaphore::~interprocess_semaphore()
 {}
 
-inline interprocess_semaphore::interprocess_semaphore(int initialCount)
+inline interprocess_semaphore::interprocess_semaphore(unsigned int initialCount)
    : m_sem(initialCount)
 {}
 

Modified: branches/release/boost/interprocess/sync/posix/semaphore_wrapper.hpp
==============================================================================
--- branches/release/boost/interprocess/sync/posix/semaphore_wrapper.hpp (original)
+++ branches/release/boost/interprocess/sync/posix/semaphore_wrapper.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -119,7 +119,7 @@
    }
 }
 
-inline void semaphore_init(sem_t *handle, int initialCount)
+inline void semaphore_init(sem_t *handle, unsigned int initialCount)
 {
    int ret = sem_init(handle, 1, initialCount);
    //According to SUSV3 version 2003 edition, the return value of a successful
@@ -243,7 +243,7 @@
    semaphore_wrapper &operator= (const semaphore_wrapper &);
 
    public:
- semaphore_wrapper(int initialCount)
+ semaphore_wrapper(unsigned int initialCount)
    { semaphore_init(&m_sem, initialCount); }
 
    ~semaphore_wrapper()

Modified: branches/release/boost/intrusive/avltree_algorithms.hpp
==============================================================================
--- branches/release/boost/intrusive/avltree_algorithms.hpp (original)
+++ branches/release/boost/intrusive/avltree_algorithms.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -664,8 +664,7 @@
 
    static void rebalance_after_erasure(node_ptr header, node_ptr x, node_ptr x_parent)
    {
- node_ptr root = NodeTraits::get_parent(header);
- while (x != root) {
+ for (node_ptr root = NodeTraits::get_parent(header); x != root; root = NodeTraits::get_parent(header)) {
          const balance x_parent_balance = NodeTraits::get_balance(x_parent);
          if(x_parent_balance == NodeTraits::zero()){
             NodeTraits::set_balance(x_parent,
@@ -686,16 +685,14 @@
                if (NodeTraits::get_balance(a) == NodeTraits::positive()) {
                   // a MUST have a right child
                   BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_right(a));
- rotate_left_right(x_parent, root);
-
+ rotate_left_right(x_parent, header);
                   x = NodeTraits::get_parent(x_parent);
                   x_parent = NodeTraits::get_parent(x);
                }
                else {
- rotate_right(x_parent, root);
+ rotate_right(x_parent, header);
                   x = NodeTraits::get_parent(x_parent);
                   x_parent = NodeTraits::get_parent(x);
-
                }
 
                // if changed from negative to NodeTraits::positive(), no need to check above
@@ -718,15 +715,15 @@
                if (NodeTraits::get_balance(a) == NodeTraits::negative()) {
                   // a MUST have then a left child
                   BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_left(a));
- rotate_right_left(x_parent, root);
+ rotate_right_left(x_parent, header);
 
                   x = NodeTraits::get_parent(x_parent);
                   x_parent = NodeTraits::get_parent(x);
                }
                else {
- rotate_left(x_parent, root);
- x = NodeTraits::get_parent(x_parent);
- x_parent = NodeTraits::get_parent(x);
+ rotate_left(x_parent, header);
+ x = NodeTraits::get_parent(x_parent);
+ x_parent = NodeTraits::get_parent(x);
                }
                // if changed from NodeTraits::positive() to negative, no need to check above
                if (NodeTraits::get_balance(x) == NodeTraits::negative()){
@@ -738,17 +735,14 @@
             BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached
          }
       }
- NodeTraits::set_parent(header, root);
    }
 
-
    static void rebalance_after_insertion(node_ptr header, node_ptr x)
    {
- node_ptr root = NodeTraits::get_parent(header);
       NodeTraits::set_balance(x, NodeTraits::zero());
 
       // Rebalance.
- while (x != root){
+ for(node_ptr root = NodeTraits::get_parent(header); x != root; root = NodeTraits::get_parent(header)){
          const balance x_parent_balance = NodeTraits::get_balance(NodeTraits::get_parent(x));
 
          if(x_parent_balance == NodeTraits::zero()){
@@ -765,9 +759,9 @@
                NodeTraits::set_balance(NodeTraits::get_parent(x), NodeTraits::zero());
             else{ // x is a right child, needs rebalancing
                if (NodeTraits::get_balance(x) == NodeTraits::negative())
- rotate_right_left(NodeTraits::get_parent(x), root);
+ rotate_right_left(NodeTraits::get_parent(x), header);
                else
- rotate_left(NodeTraits::get_parent(x), root);
+ rotate_left(NodeTraits::get_parent(x), header);
             }
             break;
          }
@@ -775,9 +769,9 @@
             // if x is a left child, needs rebalancing
             if (x == NodeTraits::get_left(NodeTraits::get_parent(x))) {
                if (NodeTraits::get_balance(x) == NodeTraits::positive())
- rotate_left_right(NodeTraits::get_parent(x), root);
+ rotate_left_right(NodeTraits::get_parent(x), header);
                else
- rotate_right(NodeTraits::get_parent(x), root);
+ rotate_right(NodeTraits::get_parent(x), header);
             }
             else
                NodeTraits::set_balance(NodeTraits::get_parent(x), NodeTraits::zero());
@@ -787,67 +781,49 @@
             BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached
          }
       }
- NodeTraits::set_parent(header, root);
    }
 
- static void rotate_left_right(node_ptr a, node_ptr &root)
+ static void left_right_balancing(node_ptr a, node_ptr b, node_ptr c)
    {
- // | | //
- // a(-2) c //
- // / \ / \ //
- // / \ ==> / \ //
- // (pos)b [g] b a //
- // / \ / \ / \ //
- // [d] c [d] e f [g] //
- // / \ //
- // e f //
- node_ptr b = NodeTraits::get_left(a), c = NodeTraits::get_right(b);
-
- // switch
- NodeTraits::set_left(a, NodeTraits::get_right(c));
- NodeTraits::set_right(b, NodeTraits::get_left(c));
-
- NodeTraits::set_right(c, a);
- NodeTraits::set_left(c, b);
-
- // set the parents
- NodeTraits::set_parent(c, NodeTraits::get_parent(a));
- NodeTraits::set_parent(a, c);
- NodeTraits::set_parent(b, c);
-
- if (NodeTraits::get_left(a)) // do we have f?
- NodeTraits::set_parent(NodeTraits::get_left(a), a);
- if (NodeTraits::get_right(b)) // do we have e?
- NodeTraits::set_parent(NodeTraits::get_right(b), b);
-
- if (a==root) root = c;
- else // a had a parent, his child is now c
- if (a == NodeTraits::get_left(NodeTraits::get_parent(c)))
- NodeTraits::set_left(NodeTraits::get_parent(c), c);
- else
- NodeTraits::set_right(NodeTraits::get_parent(c), c);
-
       // balancing...
       const balance c_balance = NodeTraits::get_balance(c);
+ const balance zero_balance = NodeTraits::zero();
+ NodeTraits::set_balance(c, zero_balance);
       if(c_balance == NodeTraits::negative()){
          NodeTraits::set_balance(a, NodeTraits::positive());
- NodeTraits::set_balance(b, NodeTraits::zero());
+ NodeTraits::set_balance(b, zero_balance);
       }
- else if(c_balance == NodeTraits::zero()){
- NodeTraits::set_balance(a, NodeTraits::zero());
- NodeTraits::set_balance(b, NodeTraits::zero());
+ else if(c_balance == zero_balance){
+ NodeTraits::set_balance(a, zero_balance);
+ NodeTraits::set_balance(b, zero_balance);
       }
       else if(c_balance == NodeTraits::positive()){
- NodeTraits::set_balance(a, NodeTraits::zero());
+ NodeTraits::set_balance(a, zero_balance);
          NodeTraits::set_balance(b, NodeTraits::negative());
       }
       else{
          BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached
       }
- NodeTraits::set_balance(c, NodeTraits::zero());
    }
 
- static void rotate_right_left(node_ptr a, node_ptr &root)
+ static void rotate_left_right(const node_ptr a, node_ptr hdr)
+ {
+ // | | //
+ // a(-2) c //
+ // / \ / \ //
+ // / \ ==> / \ //
+ // (pos)b [g] b a //
+ // / \ / \ / \ //
+ // [d] c [d] e f [g] //
+ // / \ //
+ // e f //
+ node_ptr b = NodeTraits::get_left(a), c = NodeTraits::get_right(b);
+ tree_algorithms::rotate_left(b, hdr);
+ tree_algorithms::rotate_right(a, hdr);
+ left_right_balancing(a, b, c);
+ }
+
+ static void rotate_right_left(const node_ptr a, node_ptr hdr)
    {
       // | | //
       // a(pos) c //
@@ -859,81 +835,15 @@
       // / \ //
       // e f //
       node_ptr b = NodeTraits::get_right(a), c = NodeTraits::get_left(b);
-
- // switch
- NodeTraits::set_right(a, NodeTraits::get_left(c));
- NodeTraits::set_left(b, NodeTraits::get_right(c));
-
- NodeTraits::set_left(c, a);
- NodeTraits::set_right(c, b);
-
- // set the parents
- NodeTraits::set_parent(c, NodeTraits::get_parent(a));
- NodeTraits::set_parent(a, c);
- NodeTraits::set_parent(b, c);
-
- if (NodeTraits::get_right(a)) // do we have e?
- NodeTraits::set_parent(NodeTraits::get_right(a), a);
- if (NodeTraits::get_left(b)) // do we have f?
- NodeTraits::set_parent(NodeTraits::get_left(b), b);
-
- if (a==root) root = c;
- else // a had a parent, his child is now c
- if (a == NodeTraits::get_left(NodeTraits::get_parent(c)))
- NodeTraits::set_left(NodeTraits::get_parent(c), c);
- else
- NodeTraits::set_right(NodeTraits::get_parent(c), c);
-
- // balancing...
- const balance c_balance = NodeTraits::get_balance(c);
- if(c_balance == NodeTraits::negative()){
- NodeTraits::set_balance(a, NodeTraits::zero());
- NodeTraits::set_balance(b, NodeTraits::positive());
- }
- else if(c_balance == NodeTraits::zero()){
- NodeTraits::set_balance(a, NodeTraits::zero());
- NodeTraits::set_balance(b, NodeTraits::zero());
- }
- else if(c_balance == NodeTraits::positive()){
- NodeTraits::set_balance(a, NodeTraits::negative());
- NodeTraits::set_balance(b, NodeTraits::zero());
- }
- else{
- BOOST_INTRUSIVE_INVARIANT_ASSERT(false);
- }
- NodeTraits::set_balance(c, NodeTraits::zero());
+ tree_algorithms::rotate_right(b, hdr);
+ tree_algorithms::rotate_left(a, hdr);
+ left_right_balancing(b, a, c);
    }
 
- static void rotate_left(node_ptr x, node_ptr & root)
+ static void rotate_left(const node_ptr x, node_ptr hdr)
    {
- // | | //
- // x(2) y(0) //
- // / \ ==> / \ //
- // n[a] y(1)n+2 n+1(0)x [c]n+1 //
- // / \ / \ //
- // n[b] [c]n+1 n[a] [b]n //
- node_ptr y = NodeTraits::get_right(x);
-
- // switch
- NodeTraits::set_right(x, NodeTraits::get_left(y));
- NodeTraits::set_left(y, x);
-
- // rearrange parents
- NodeTraits::set_parent(y, NodeTraits::get_parent(x));
- NodeTraits::set_parent(x, y);
-
- // do we have [b]?
- if (NodeTraits::get_right(x))
- NodeTraits::set_parent(NodeTraits::get_right(x), x);
-
- if (x == root)
- root = y;
- else
- // need to reparent y
- if (NodeTraits::get_left(NodeTraits::get_parent(y)) == x)
- NodeTraits::set_left(NodeTraits::get_parent(y), y);
- else
- NodeTraits::set_right(NodeTraits::get_parent(y), y);
+ const node_ptr y = NodeTraits::get_right(x);
+ tree_algorithms::rotate_left(x, hdr);
 
       // reset the balancing factor
       if (NodeTraits::get_balance(y) == NodeTraits::positive()) {
@@ -946,30 +856,10 @@
       }
    }
 
- static void rotate_right(node_ptr x, node_ptr &root)
+ static void rotate_right(const node_ptr x, node_ptr hdr)
    {
- node_ptr y = NodeTraits::get_left(x);
-
- // switch
- NodeTraits::set_left(x, NodeTraits::get_right(y));
- NodeTraits::set_right(y, x);
-
- // rearrange parents
- NodeTraits::set_parent(y, NodeTraits::get_parent(x));
- NodeTraits::set_parent(x, y);
-
- // do we have [b]?
- if (NodeTraits::get_left(x))
- NodeTraits::set_parent(NodeTraits::get_left(x), x);
-
- if (x == root)
- root = y;
- else
- // need to reparent y
- if (NodeTraits::get_left(NodeTraits::get_parent(y)) == x)
- NodeTraits::set_left(NodeTraits::get_parent(y), y);
- else
- NodeTraits::set_right(NodeTraits::get_parent(y), y);
+ const node_ptr y = NodeTraits::get_left(x);
+ tree_algorithms::rotate_right(x, hdr);
 
       // reset the balancing factor
       if (NodeTraits::get_balance(y) == NodeTraits::negative()) {

Modified: branches/release/boost/intrusive/detail/tree_algorithms.hpp
==============================================================================
--- branches/release/boost/intrusive/detail/tree_algorithms.hpp (original)
+++ branches/release/boost/intrusive/detail/tree_algorithms.hpp 2009-07-18 20:11:33 EDT (Sat, 18 Jul 2009)
@@ -1232,69 +1232,75 @@
    //! <b>Complexity</b>: Constant.
    //!
    //! <b>Throws</b>: Nothing.
- static bool is_right_child (node_ptr p)
+ static bool is_right_child(node_ptr p)
    { return NodeTraits::get_right(NodeTraits::get_parent(p)) == p; }
 
- static void replace_own (node_ptr own, node_ptr x, node_ptr header)
+ //Fix header and own's parent data when replacing x with own, providing own's old data with parent
+ static void replace_own_impl(node_ptr own, node_ptr x, node_ptr header, node_ptr own_parent, bool own_was_left)
    {
       if(NodeTraits::get_parent(header) == own)
          NodeTraits::set_parent(header, x);
- else if(is_left_child(own))
- NodeTraits::set_left(NodeTraits::get_parent(own), x);
+ else if(own_was_left)
+ NodeTraits::set_left(own_parent, x);
       else
- NodeTraits::set_right(NodeTraits::get_parent(own), x);
+ NodeTraits::set_right(own_parent, x);
    }
 
- static void rotate_left(node_ptr p, node_ptr header)
+ //Fix header and own's parent data when replacing x with own, supposing own
+ //links with its parent are still ok
+ static void replace_own(node_ptr own, node_ptr x, node_ptr header)
    {
- node_ptr x = NodeTraits::get_right(p);
- NodeTraits::set_right(p, NodeTraits::get_left(x));
- if(NodeTraits::get_left(x) != 0)
- NodeTraits::set_parent(NodeTraits::get_left(x), p);
- NodeTraits::set_parent(x, NodeTraits::get_parent(p));
- replace_own (p, x, header);
+ node_ptr own_parent(NodeTraits::get_parent(own));
+ bool own_is_left(NodeTraits::get_left(own_parent) == own);
+ replace_own_impl(own, x, header, own_parent, own_is_left);
+ }
+
+ // rotate parent p to left (no header and p's parent fixup)
+ static node_ptr rotate_left(node_ptr p)
+ {
+ node_ptr x(NodeTraits::get_right(p));
+ node_ptr x_left(NodeTraits::get_left(x));
+ NodeTraits::set_right(p, x_left);
+ if(x_left){
+ NodeTraits::set_parent(x_left, p);
+ }
       NodeTraits::set_left(x, p);
       NodeTraits::set_parent(p, x);
+ return x;
    }
 
- static void rotate_right(node_ptr p, node_ptr header)
+ // rotate parent p to left (with header and p's parent fixup)
+ static void rotate_left(node_ptr p, node_ptr header)
+ {
+ bool p_was_left(is_left_child(p));
+ node_ptr p_old_parent(NodeTraits::get_parent(p));
+ node_ptr x(rotate_left(p));
+ NodeTraits::set_parent(x, p_old_parent);
+ replace_own_impl(p, x, header, p_old_parent, p_was_left);
+ }
+
+ // rotate parent p to right (no header and p's parent fixup)
+ static node_ptr rotate_right(node_ptr p)
    {
       node_ptr x(NodeTraits::get_left(p));
       node_ptr x_right(NodeTraits::get_right(x));
       NodeTraits::set_left(p, x_right);
- if(x_right)
+ if(x_right){
          NodeTraits::set_parent(x_right, p);
- NodeTraits::set_parent(x, NodeTraits::get_parent(p));
- replace_own (p, x, header);
+ }
       NodeTraits::set_right(x, p);
       NodeTraits::set_parent(p, x);
- }
-
- // rotate node t with left child | complexity : constant | exception : nothrow
- static node_ptr rotate_left(node_ptr t)
- {
- node_ptr x = NodeTraits::get_right(t);
- NodeTraits::set_right(t, NodeTraits::get_left(x));
-
- if( NodeTraits::get_right(t) != 0 ){
- NodeTraits::set_parent(NodeTraits::get_right(t), t );
- }
- NodeTraits::set_left(x, t);
- NodeTraits::set_parent(t, x);
       return x;
    }
 
- // rotate node t with right child | complexity : constant | exception : nothrow
- static node_ptr rotate_right(node_ptr t)
+ // rotate parent p to right (with header and p's parent fixup)
+ static void rotate_right(node_ptr p, node_ptr header)
    {
- node_ptr x = NodeTraits::get_left(t);
- NodeTraits::set_left(t, NodeTraits::get_right(x));
- if( NodeTraits::get_left(t) != 0 ){
- NodeTraits::set_parent(NodeTraits::get_left(t), t);
- }
- NodeTraits::set_right(x, t);
- NodeTraits::set_parent(t, x);
- return x;
+ bool p_was_left(is_left_child(p));
+ node_ptr p_old_parent(NodeTraits::get_parent(p));
+ node_ptr x(rotate_right(p));
+ NodeTraits::set_parent(x, p_old_parent);
+ replace_own_impl(p, x, header, p_old_parent, p_was_left);
    }
 
    static void link(node_ptr header, node_ptr z, node_ptr par, bool left)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk