From 14401bcb38e28152c521eb9a17acd47d5dc3e490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Wed, 11 Apr 2012 06:25:04 +0000 Subject: [PATCH] Error correction for Visual and Clang [SVN r77909] --- test/heap_allocator_v1.hpp | 10 +++++++--- test/named_semaphore_test.cpp | 25 +++++++++++++++++++++++++ test/vectorstream_test.cpp | 7 ++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/test/heap_allocator_v1.hpp b/test/heap_allocator_v1.hpp index 8e6371b..c3f7b2e 100644 --- a/test/heap_allocator_v1.hpp +++ b/test/heap_allocator_v1.hpp @@ -90,7 +90,7 @@ class heap_allocator_v1 //!Returns the segment manager. Never throws segment_manager* get_segment_manager()const { return ipcdetail::to_raw_pointer(mp_mngr); } -/* + //!Returns address of mutable object. Never throws pointer address(reference value) const { return pointer(addressof(value)); } @@ -98,7 +98,7 @@ class heap_allocator_v1 //!Returns address of non mutable object. Never throws const_pointer address(const_reference value) const { return const_pointer(addressof(value)); } -*/ + //!Constructor from the segment manager. Never throws heap_allocator_v1(segment_manager *segment_mngr) : mp_mngr(segment_mngr) { } @@ -115,7 +115,11 @@ class heap_allocator_v1 //!Allocates memory for an array of count elements. //!Throws boost::interprocess::bad_alloc if there is no enough memory pointer allocate(size_type count, cvoid_ptr hint = 0) - { (void)hint; return ::new value_type[count]; } + { + (void)hint; + char *raw_mem = ::new char[sizeof(value_type)*count]; + return boost::intrusive::pointer_traits::pointer_to(reinterpret_cast(*raw_mem)); + } //!Deallocates memory previously allocated. Never throws void deallocate(const pointer &ptr, size_type) diff --git a/test/named_semaphore_test.cpp b/test/named_semaphore_test.cpp index 94bbdfd..1c226c6 100644 --- a/test/named_semaphore_test.cpp +++ b/test/named_semaphore_test.cpp @@ -97,6 +97,30 @@ class recursive_named_semaphore_test_wrapper int recursive_named_semaphore_test_wrapper::count_ = 0; +bool test_named_semaphore_specific() +{ + //Test persistance + { + named_semaphore sem(create_only, SemName, 3); + } + { + named_semaphore sem(open_only, SemName); + BOOST_INTERPROCES_CHECK(sem.try_wait() == true); + BOOST_INTERPROCES_CHECK(sem.try_wait() == true); + BOOST_INTERPROCES_CHECK(sem.try_wait() == true); + BOOST_INTERPROCES_CHECK(sem.try_wait() == false); + sem.post(); + } + { + named_semaphore sem(open_only, SemName); + BOOST_INTERPROCES_CHECK(sem.try_wait() == true); + BOOST_INTERPROCES_CHECK(sem.try_wait() == false); + } + + named_semaphore::remove(SemName); + return true; +} + int main () { try{ @@ -105,6 +129,7 @@ int main () test::test_all_lock(); test::test_all_recursive_lock(); test::test_all_mutex(); + test_named_semaphore_specific(); } catch(std::exception &ex){ named_semaphore::remove(SemName); diff --git a/test/vectorstream_test.cpp b/test/vectorstream_test.cpp index ca72452..6a5fbe2 100644 --- a/test/vectorstream_test.cpp +++ b/test/vectorstream_test.cpp @@ -20,7 +20,8 @@ #include #include -using namespace boost::interprocess; +namespace boost { +namespace interprocess { //Force instantiations to catch compile-time errors typedef basic_string my_string; @@ -30,6 +31,10 @@ typedef basic_vectorstream my_vectorstream_t; template class basic_vectorstream; template class basic_vectorstream >; +}} + +using namespace boost::interprocess; + static int vectorstream_test() { { //Test high watermarking initialization