From 51072bd6bf79ef2bc6a922079bff57c31c1effbc Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 23 Jul 2016 20:47:26 +0000 Subject: Vendor import of libc++ release_39 branch r276489: https://llvm.org/svn/llvm-project/libcxx/branches/release_39@276489 --- test/support/min_allocator.h | 58 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'test/support/min_allocator.h') diff --git a/test/support/min_allocator.h b/test/support/min_allocator.h index 5e3ae5d2a136b..701159e0481a2 100644 --- a/test/support/min_allocator.h +++ b/test/support/min_allocator.h @@ -11,6 +11,9 @@ #define MIN_ALLOCATOR_H #include +#include +#include +#include #include "test_macros.h" @@ -39,8 +42,59 @@ public: friend bool operator!=(bare_allocator x, bare_allocator y) {return !(x == y);} }; +struct malloc_allocator_base { + static size_t alloc_count; + static size_t dealloc_count; + static bool disable_default_constructor; + + static size_t outstanding_alloc() { + assert(alloc_count >= dealloc_count); + return (alloc_count - dealloc_count); + } + + static void reset() { + assert(outstanding_alloc() == 0); + disable_default_constructor = false; + alloc_count = 0; + dealloc_count = 0; + } +}; + + +size_t malloc_allocator_base::alloc_count = 0; +size_t malloc_allocator_base::dealloc_count = 0; +bool malloc_allocator_base::disable_default_constructor = false; + + +template +class malloc_allocator : public malloc_allocator_base +{ +public: + typedef T value_type; + + malloc_allocator() TEST_NOEXCEPT { assert(!disable_default_constructor); } + + template + malloc_allocator(malloc_allocator) TEST_NOEXCEPT {} + + T* allocate(std::size_t n) + { + ++alloc_count; + return static_cast(std::malloc(n*sizeof(T))); + } + + void deallocate(T* p, std::size_t) + { + ++dealloc_count; + std::free(static_cast(p)); + } + + friend bool operator==(malloc_allocator, malloc_allocator) {return true;} + friend bool operator!=(malloc_allocator x, malloc_allocator y) {return !(x == y);} +}; + -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 #include @@ -286,6 +340,6 @@ public: friend bool operator!=(min_allocator x, min_allocator y) {return !(x == y);} }; -#endif // __cplusplus >= 201103L +#endif // TEST_STD_VER >= 11 #endif // MIN_ALLOCATOR_H -- cgit v1.2.3