diff --git a/test/exception/insert_exception_tests.cpp b/test/exception/insert_exception_tests.cpp index 1d3ee67a..464a0ff5 100644 --- a/test/exception/insert_exception_tests.cpp +++ b/test/exception/insert_exception_tests.cpp @@ -32,7 +32,7 @@ struct insert_test_base : public test::exception_base std::string scope(test::scope); if(scope.find("hash::operator()") == std::string::npos) - strong.test(x, test::exception::detail::tracker.count_allocations); + strong.test(x, test::detail::tracker.count_allocations); test::check_equivalent_keys(x); } }; @@ -49,7 +49,7 @@ struct emplace_test1 : public insert_test_base it = this->values.begin(), end = this->values.end(); it != end; ++it) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.emplace(*it); } } @@ -67,7 +67,7 @@ struct insert_test1 : public insert_test_base it = this->values.begin(), end = this->values.end(); it != end; ++it) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.insert(*it); } } @@ -83,7 +83,7 @@ struct insert_test2 : public insert_test_base it = this->values.begin(), end = this->values.end(); it != end; ++it) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.insert(x.begin(), *it); } } @@ -111,7 +111,7 @@ struct insert_test4 : public insert_test_base it = this->values.begin(), end = this->values.end(); it != end; ++it) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.insert(it, boost::next(it)); } } @@ -150,7 +150,7 @@ struct insert_test_rehash1 : public insert_test_base end = this->values.end(); it != end && count < 10; ++it, ++count) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); pos = x.insert(pos, *it); } @@ -174,7 +174,7 @@ struct insert_test_rehash2 : public insert_test_rehash1 end = this->values.end(); it != end && count < 10; ++it, ++count) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.insert(*it); } diff --git a/test/helpers/allocator.hpp b/test/helpers/allocator.hpp deleted file mode 100644 index 5482baa0..00000000 --- a/test/helpers/allocator.hpp +++ /dev/null @@ -1,84 +0,0 @@ - -// Copyright 2006-2009 Daniel James. -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#if !defined(BOOST_UNORDERED_TEST_MALLOC_ALLOCATOR_HEADER) -#define BOOST_UNORDERED_TEST_MALLOC_ALLOCATOR_HEADER - -#include -#include -#include -#include - -#if defined(BOOST_MSVC) -#pragma warning(push) -#pragma warning(disable:4100) // unreferenced formal parameter -#endif - -namespace test -{ - template - struct malloc_allocator - { - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - typedef T* pointer; - typedef T const* const_pointer; - typedef T& reference; - typedef T const& const_reference; - typedef T value_type; - - template struct rebind { typedef malloc_allocator other; }; - - malloc_allocator() {} - template malloc_allocator(malloc_allocator const&) {} - malloc_allocator(malloc_allocator const&) {} - - pointer address(reference r) { return &r; } - const_pointer address(const_reference r) { return &r; } - - pointer allocate(size_type n) { - using namespace std; - T* ptr = static_cast(malloc(n * sizeof(T))); - if(!ptr) throw std::bad_alloc(); - return ptr; - } - - pointer allocate(size_type n, void const* u) { return allocate(n); } - - void deallocate(pointer p, size_type) { - using namespace std; - free(p); - } - void construct(pointer p, T const& t) { new(p) T(t); } - void destroy(pointer p) { p->~T(); } - - size_type max_size() const { - return (std::numeric_limits::max)(); - } - - bool operator==(malloc_allocator const&) const { return true; } - bool operator!=(malloc_allocator const&) const { return false; } - -#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) - template void deallocate(T* p, size_type) { - using namespace std; - free(p); - } - char* _Charalloc(size_type n) { - using namespace std; - T* ptr = static_cast(malloc(n * sizeof(char))); - if(!ptr) throw std::bad_alloc(); - return (char*) ptr; - } -#endif - }; -} - -#if defined(BOOST_MSVC) -#pragma warning(pop) -#pragma warning(disable:4100) // unreferenced formal parameter -#endif - -#endif diff --git a/test/helpers/invariants.hpp b/test/helpers/invariants.hpp index 3caf1eca..abb8fb1e 100644 --- a/test/helpers/invariants.hpp +++ b/test/helpers/invariants.hpp @@ -13,7 +13,6 @@ #include #include "./metafunctions.hpp" #include "./helpers.hpp" -#include "./allocator.hpp" #if defined(BOOST_MSVC) #pragma warning(push) @@ -29,10 +28,7 @@ namespace test { BOOST_DEDUCED_TYPENAME X::key_equal eq = x1.key_eq(); typedef BOOST_DEDUCED_TYPENAME X::key_type key_type; - // Boost.Test was reporting memory leaks for std::set on g++-3.3. - // So I work around it by using malloc. - std::set, - test::malloc_allocator > found_; + std::set > found_; BOOST_DEDUCED_TYPENAME X::const_iterator it = x1.begin(), end = x1.end(); diff --git a/test/helpers/memory.hpp b/test/helpers/memory.hpp index 05724325..935fd315 100644 --- a/test/helpers/memory.hpp +++ b/test/helpers/memory.hpp @@ -53,30 +53,10 @@ namespace test } }; - template - struct allocator_memory_type_gen { - typedef std::map type; - }; - -#if defined(BOOST_MPL_CFG_MSVC_ETI_BUG) - template <> - struct allocator_memory_type_gen { - typedef std::map - type; - }; -#endif - - template > struct memory_tracker { - typedef BOOST_DEDUCED_TYPENAME - ::boost::unordered::detail::rebind_wrap >::type - allocator_type; - - typedef BOOST_DEDUCED_TYPENAME - allocator_memory_type_gen::type - allocated_memory_type; + typedef std::map > + > allocated_memory_type; allocated_memory_type allocated_memory; unsigned int count_allocators; @@ -139,7 +119,7 @@ namespace test void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag, bool check_tag_ = true) { - BOOST_DEDUCED_TYPENAME allocated_memory_type::iterator pos = + allocated_memory_type::iterator pos = allocated_memory.find( memory_area(ptr, (char*) ptr + n * size)); if(pos == allocated_memory.end()) { @@ -177,7 +157,7 @@ namespace test // // boostinspect:nounnamed namespace { - test::detail::memory_tracker > tracker; + test::detail::memory_tracker tracker; } } diff --git a/test/objects/cxx11_allocator.hpp b/test/objects/cxx11_allocator.hpp index cec9451f..c0bed76c 100644 --- a/test/objects/cxx11_allocator.hpp +++ b/test/objects/cxx11_allocator.hpp @@ -21,7 +21,8 @@ namespace test is_select_on_copy = 0, is_propagate_on_swap = 0, is_propagate_on_assign = 0, - is_propagate_on_move = 0 + is_propagate_on_move = 0, + cxx11_construct = 0 }; }; @@ -31,7 +32,8 @@ namespace test is_select_on_copy = 1, is_propagate_on_swap = 1, is_propagate_on_assign = 1, - is_propagate_on_move = 1 + is_propagate_on_move = 1, + cxx11_construct = 1 }; }; diff --git a/test/objects/exception.hpp b/test/objects/exception.hpp index 3b97723c..9ff13005 100644 --- a/test/objects/exception.hpp +++ b/test/objects/exception.hpp @@ -13,21 +13,12 @@ #include #include #include "../helpers/fwd.hpp" -#include "../helpers/allocator.hpp" #include "../helpers/memory.hpp" namespace test { namespace exception { - namespace detail - { - namespace - { - test::detail::memory_tracker > tracker; - } - } - class object; class hash; class equal_to; @@ -259,7 +250,7 @@ namespace exception UNORDERED_SCOPE(allocator::allocator()) { UNORDERED_EPOINT("Mock allocator default constructor."); } - detail::tracker.allocator_ref(); + test::detail::tracker.allocator_ref(); } template allocator(allocator const& x) : tag_(x.tag_) @@ -267,7 +258,7 @@ namespace exception UNORDERED_SCOPE(allocator::allocator()) { UNORDERED_EPOINT("Mock allocator template copy constructor."); } - detail::tracker.allocator_ref(); + test::detail::tracker.allocator_ref(); } allocator(allocator const& x) : tag_(x.tag_) @@ -275,11 +266,11 @@ namespace exception UNORDERED_SCOPE(allocator::allocator()) { UNORDERED_EPOINT("Mock allocator copy constructor."); } - detail::tracker.allocator_ref(); + test::detail::tracker.allocator_ref(); } ~allocator() { - detail::tracker.allocator_unref(); + test::detail::tracker.allocator_unref(); } allocator& operator=(allocator const& x) { @@ -317,7 +308,7 @@ namespace exception ptr = (T*) malloc(n * sizeof(T)); if(!ptr) throw std::bad_alloc(); } - detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); + test::detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); return pointer(ptr); //return pointer(static_cast(::operator new(n * sizeof(T)))); @@ -333,7 +324,7 @@ namespace exception ptr = (T*) malloc(n * sizeof(T)); if(!ptr) throw std::bad_alloc(); } - detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); + test::detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); return pointer(ptr); //return pointer(static_cast(::operator new(n * sizeof(T)))); @@ -343,7 +334,7 @@ namespace exception { //::operator delete((void*) p); if(p) { - detail::tracker.track_deallocate((void*) p, n, sizeof(T), tag_); + test::detail::tracker.track_deallocate((void*) p, n, sizeof(T), tag_); using namespace std; free(p); } @@ -354,7 +345,7 @@ namespace exception UNORDERED_EPOINT("Mock allocator construct function."); new(p) T(t); } - detail::tracker.track_construct((void*) p, sizeof(T), tag_); + test::detail::tracker.track_construct((void*) p, sizeof(T), tag_); } #if !defined(BOOST_NO_VARIADIC_TEMPLATES) @@ -363,12 +354,12 @@ namespace exception UNORDERED_EPOINT("Mock allocator construct function."); new(p) T(boost::forward(args)...); } - detail::tracker.track_construct((void*) p, sizeof(T), tag_); + test::detail::tracker.track_construct((void*) p, sizeof(T), tag_); } #endif void destroy(T* p) { - detail::tracker.track_destroy((void*) p, sizeof(T), tag_); + test::detail::tracker.track_destroy((void*) p, sizeof(T), tag_); p->~T(); } diff --git a/test/unordered/incomplete_test.cpp b/test/unordered/incomplete_test.cpp index 035dfb6f..4300a8e6 100644 --- a/test/unordered/incomplete_test.cpp +++ b/test/unordered/incomplete_test.cpp @@ -15,26 +15,25 @@ namespace x struct D { boost::unordered_map x; }; } -namespace test +namespace incomplete_test { // Declare, but don't define some types. struct value; struct hash; struct equals; - template - struct malloc_allocator; + template struct allocator; // Declare some instances typedef boost::unordered_map > > map; + allocator > > map; typedef boost::unordered_multimap > > multimap; + allocator > > multimap; typedef boost::unordered_set > set; + allocator > set; typedef boost::unordered_multiset > multiset; + allocator > multiset; // Now define the types which are stored as members, as they are needed for // declaring struct members. @@ -49,12 +48,17 @@ namespace test bool operator()(T const&, T const&) const { return true; } }; -} + // This is a dubious way to implement an allocator, but good enough + // for this test. + template + struct allocator : std::allocator { + allocator() {} -#include "../helpers/allocator.hpp" + template + allocator(const allocator& other) : + std::allocator(other) {} + }; -namespace test -{ // Declare some members of a structs. // // Incomplete hash, equals and allocator aren't here supported at the @@ -62,19 +66,19 @@ namespace test struct struct1 { boost::unordered_map > > x; + allocator > > x; }; struct struct2 { boost::unordered_multimap > > x; + allocator > > x; }; struct struct3 { boost::unordered_set > x; + allocator > x; }; struct struct4 { boost::unordered_multiset > x; + allocator > x; }; // Now define the value type. @@ -83,15 +87,15 @@ namespace test // Create some instances. - test::map m1; - test::multimap m2; - test::set s1; - test::multiset s2; + incomplete_test::map m1; + incomplete_test::multimap m2; + incomplete_test::set s1; + incomplete_test::multiset s2; - test::struct1 c1; - test::struct2 c2; - test::struct3 c3; - test::struct4 c4; + incomplete_test::struct1 c1; + incomplete_test::struct2 c2; + incomplete_test::struct3 c3; + incomplete_test::struct4 c4; // Now declare, but don't define, the operators required for comparing // elements. @@ -113,7 +117,7 @@ namespace test void use_types() { - test::value x; + incomplete_test::value x; m1[x] = x; m2.insert(std::make_pair(x, x)); s1.insert(x); @@ -145,5 +149,5 @@ int main() { // This could just be a compile test, but I like to be able to run these // things. It's probably irrational, but I find it reassuring. - test::use_types(); + incomplete_test::use_types(); }