Skip to content

Commit

Permalink
Revert unit tests to use automatic allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
glenfe committed Aug 30, 2016
1 parent 8b8cae7 commit f0ed3a3
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 79 deletions.
4 changes: 2 additions & 2 deletions include/boost/align/aligned_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ class aligned_allocator {
if (size > 0) {
p = aligned_alloc(min_align, sizeof(T) * size);
if (!p) {
::boost::throw_exception(std::bad_alloc());
boost::throw_exception(std::bad_alloc());
}
}
return static_cast<T*>(p);
}

void deallocate(pointer ptr, size_type) {
::boost::alignment::aligned_free(ptr);
boost::alignment::aligned_free(ptr);
}

BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT {
Expand Down
10 changes: 4 additions & 6 deletions include/boost/align/aligned_allocator_adaptor.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) 2014-2015 Glen Joseph Fernandes
(c) 2014-2016 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
Expand Down Expand Up @@ -123,8 +123,7 @@ class aligned_allocator_adaptor
char_ptr p = a.allocate(sizeof p + n);
void* r = detail::addressof(*p) + sizeof p;
(void)align(min_align, s, r, n);
::new(static_cast<void*>(static_cast<char_ptr*>(r) -
1)) char_ptr(p);
::new((void*)(static_cast<char_ptr*>(r) - 1)) char_ptr(p);
return static_cast<pointer>(r);
}

Expand All @@ -143,13 +142,12 @@ class aligned_allocator_adaptor
#endif
void* r = detail::addressof(*p) + sizeof p;
(void)align(min_align, s, r, n);
::new(static_cast<void*>(static_cast<char_ptr*>(r) -
1)) char_ptr(p);
::new((void*)(static_cast<char_ptr*>(r) - 1)) char_ptr(p);
return static_cast<pointer>(r);
}

void deallocate(pointer ptr, size_type size) {
char_ptr* p = reinterpret_cast<char_ptr*>(ptr) - 1;
char_ptr* p = (char_ptr*)ptr - 1;
char_ptr r = *p;
p->~char_ptr();
char_alloc a(base());
Expand Down
2 changes: 1 addition & 1 deletion include/boost/align/aligned_delete.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct aligned_delete {
BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(ptr->~T())) {
if (ptr) {
ptr->~T();
::boost::alignment::aligned_free(ptr);
boost::alignment::aligned_free(ptr);
}
}
};
Expand Down
5 changes: 2 additions & 3 deletions include/boost/align/alignment_of.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) 2014-2015 Glen Joseph Fernandes
(c) 2014-2016 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
Expand Down Expand Up @@ -39,8 +39,7 @@ namespace alignment {

template<class T>
struct alignment_of
: detail::alignment_of<typename
detail::element_type<T>::type>::type { };
: detail::alignment_of<typename detail::element_type<T>::type> { };

#if !defined(BOOST_NO_CXX14_VARIABLE_TEMPLATES)
template<class T>
Expand Down
12 changes: 6 additions & 6 deletions include/boost/align/detail/align.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) 2014 Glen Joseph Fernandes
(c) 2014-2016 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
Expand All @@ -20,12 +20,12 @@ inline void* align(std::size_t alignment, std::size_t size,
{
BOOST_ASSERT(detail::is_alignment(alignment));
if (size <= space) {
char* p = reinterpret_cast<char*>((reinterpret_cast<std::
size_t>(ptr) + alignment - 1) & ~(alignment - 1));
std::ptrdiff_t n = p - static_cast<char*>(ptr);
if (size <= space - n) {
char* p = (char*)(((std::size_t)ptr + alignment - 1) &
~(alignment - 1));
std::size_t n = space - (p - static_cast<char*>(ptr));
if (size <= n) {
ptr = p;
space -= n;
space = n;
return p;
}
}
Expand Down
3 changes: 1 addition & 2 deletions include/boost/align/detail/align_down.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ namespace alignment {
inline void* align_down(void* ptr, std::size_t alignment) BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
return reinterpret_cast<void*>(align_down(reinterpret_cast<std::
size_t>(ptr), alignment));
return (void*)(align_down((std::size_t)ptr, alignment));
}

} /* .alignment */
Expand Down
3 changes: 1 addition & 2 deletions include/boost/align/detail/align_up.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ namespace alignment {
inline void* align_up(void* ptr, std::size_t alignment) BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
return reinterpret_cast<void*>(align_up(reinterpret_cast<std::
size_t>(ptr), alignment));
return (void*)(align_up((std::size_t)ptr, alignment));
}

} /* .alignment */
Expand Down
3 changes: 1 addition & 2 deletions include/boost/align/detail/alignment_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ struct alignof_helper {

template<class T>
struct alignment_of
: min_size<sizeof(T),
sizeof(alignof_helper<T>) - sizeof(T)>::type { };
: min_size<sizeof(T), sizeof(alignof_helper<T>) - sizeof(T)> { };

} /* .detail */
} /* .alignment */
Expand Down
2 changes: 1 addition & 1 deletion include/boost/align/detail/alignment_of_msvc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct alignof_helper {
template<class T>
struct alignment_of
: min_size<sizeof(T),
sizeof(alignof_helper<T>) - (sizeof(T) << 1)>::type { };
sizeof(alignof_helper<T>) - (sizeof(T) << 1)> { };

} /* .detail */
} /* .alignment */
Expand Down
2 changes: 1 addition & 1 deletion include/boost/align/detail/assume_aligned_clang.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ License, Version 1.0.

#if __has_builtin(__builtin_assume_aligned)
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
(p) = static_cast<__typeof__(p)>(__builtin_assume_aligned((p), (n)))
(p) = (__typeof__(p))(__builtin_assume_aligned((p), (n)))
#else
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n)
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/boost/align/detail/assume_aligned_gcc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ License, Version 1.0.
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_GCC_HPP

#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
(p) = static_cast<__typeof__(p)>(__builtin_assume_aligned((p), (n)))
(p) = (__typeof__(p))(__builtin_assume_aligned((p), (n)))

#endif
2 changes: 1 addition & 1 deletion include/boost/align/detail/assume_aligned_msvc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ License, Version 1.0.
#include <cstddef>

#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
__assume((reinterpret_cast<std::size_t>(p) & ((n) - 1)) == 0)
__assume(((std::size_t)(p) & ((n) - 1)) == 0)

#endif
39 changes: 13 additions & 26 deletions include/boost/align/detail/element_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ namespace alignment {
namespace detail {

#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
template<class T>
struct element_type {
typedef typename
std::remove_cv<typename
std::remove_all_extents<typename
std::remove_reference<T>::
type>::type>::type type;
};
using std::remove_reference;
using std::remove_all_extents;
using std::remove_cv;
#else
template<class T>
struct remove_reference {
Expand All @@ -54,14 +49,12 @@ struct remove_all_extents {
};

template<class T>
struct remove_all_extents<T[]> {
typedef typename remove_all_extents<T>::type type;
};
struct remove_all_extents<T[]>
: remove_all_extents<T> { };

template<class T, std::size_t N>
struct remove_all_extents<T[N]> {
typedef typename remove_all_extents<T>::type type;
};
struct remove_all_extents<T[N]>
: remove_all_extents<T> { };

template<class T>
struct remove_const {
Expand All @@ -84,20 +77,14 @@ struct remove_volatile<volatile T> {
};

template<class T>
struct remove_cv {
typedef typename remove_volatile<typename
remove_const<T>::type>::type type;
};
struct remove_cv
: remove_volatile<typename remove_const<T>::type> { };
#endif

template<class T>
struct element_type {
typedef typename
remove_cv<typename
remove_all_extents<typename
remove_reference<T>::
type>::type>::type type;
};
#endif
struct element_type
: remove_cv<typename remove_all_extents<typename
remove_reference<T>::type>::type> { };

} /* .detail */
} /* .alignment */
Expand Down
8 changes: 6 additions & 2 deletions include/boost/align/detail/integral_constant.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) 2014-2015 Glen Joseph Fernandes
(c) 2014-2016 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
Expand Down Expand Up @@ -27,7 +27,11 @@ struct integral_constant {
typedef T value_type;
typedef integral_constant type;

BOOST_CONSTEXPR operator value_type() const {
BOOST_CONSTEXPR operator value_type() const BOOST_NOEXCEPT {
return Value;
}

BOOST_CONSTEXPR value_type operator()() const BOOST_NOEXCEPT {
return Value;
}

Expand Down
4 changes: 2 additions & 2 deletions include/boost/align/detail/is_aligned.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ inline bool is_aligned(const void* ptr, std::size_t alignment)
BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
return is_aligned(reinterpret_cast<std::size_t>(ptr), alignment);
return is_aligned((std::size_t)ptr, alignment);
}

inline bool is_aligned(std::size_t alignment, const void* ptr)
BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
return is_aligned(reinterpret_cast<std::size_t>(ptr), alignment);
return is_aligned((std::size_t)ptr, alignment);
}

} /* .alignment */
Expand Down
3 changes: 1 addition & 2 deletions include/boost/align/detail/max_align.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ namespace detail {

template<class A, class B>
struct max_align
: max_size<alignment_of<A>::value,
alignment_of<B>::value>::type { };
: max_size<alignment_of<A>::value, alignment_of<B>::value> { };

} /* .detail */
} /* .alignment */
Expand Down
2 changes: 1 addition & 1 deletion test/aligned_delete_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ T* aligned_new()
if (p) {
return ::new(p) T();
} else {
throw std::bad_alloc();
return 0;
}
}

Expand Down
30 changes: 12 additions & 18 deletions test/is_aligned_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,24 @@ License, Version 1.0.
template<std::size_t N>
struct A { };

template<class T>
struct P {
P()
: p(new T) { }
~P() {
delete p;
}
T* p;
};

template<std::size_t N>
void test(char* p, A<N>)
template<class T, std::size_t N>
void test(T* p, A<N>)
{
BOOST_TEST(boost::alignment::is_aligned(p, N));
BOOST_TEST(!boost::alignment::is_aligned(&p[1], N));
BOOST_TEST(!boost::alignment::is_aligned((char*)p + 1, N));
}

void test(char* p, A<1>)
template<class T>
void test(T* p, A<1>)
{
BOOST_TEST(boost::alignment::is_aligned(p, 1));
}

template<class T>
void test()
{
P<T> o;
test(reinterpret_cast<char*>(o.p),
A<boost::alignment::alignment_of<T>::value>());
T o;
test(&o, A<boost::alignment::alignment_of<T>::value>());
}

class X;
Expand All @@ -60,19 +50,23 @@ int main()
test<short>();
test<int>();
test<long>();
#if !defined(BOOST_NO_LONG_LONG)
#if !defined(BOOST_NO_LONG_LONG) && !defined(_MSC_VER)
test<long long>();
#endif
test<float>();
#if !defined(_MSC_VER)
test<double>();
test<long double>();
#endif
test<void*>();
test<char*>();
test<int*>();
test<X*>();
test<void(*)()>();
#if !defined(_MSC_VER)
test<int X::*>();
test<int(X::*)()>();
#endif

return boost::report_errors();
}

0 comments on commit f0ed3a3

Please sign in to comment.