Skip to content

Commit

Permalink
[EASTL 3.16.07]
Browse files Browse the repository at this point in the history
EASTL: fixing spelling mistake in eastl::basic_string

Fix for insertion_sort() doing a --(BiDirectionalIterator) which is an illegal operation and causes crashes on containers such as eastl::deque.

eastl::optional_storage - remove unneeded union and trivial type initialization since we use eastl::aligned_storage_t, remove unreferenced internal member function

EASTL: resolving 32-bit eastl_size_t compiler error

EASTL: EASTL_ALIGN_OF porting to C++11 alignof keyword.

EASTL_EMPTY_REFERENCE_ASSERT_ENABLED when enabled would not assert when taking a reference to an empty container.
Example, eastl::vector[0] would not assert that a null reference was being taken if the vector was empty.

EASTL: fixing shared_ptr compiler error when passing nullptr with a custom deleter lambda
  • Loading branch information
MaxEWinkler committed Jun 9, 2020
1 parent d84b9c6 commit b2d923a
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 366 deletions.
32 changes: 16 additions & 16 deletions include/EASTL/bonus/list_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,11 @@ namespace eastl
inline typename list_map<Key, T, Compare, Allocator>::reference
list_map<Key, T, Compare, Allocator>::front()
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(static_cast<internal_value_type*>(mNode.mpNext) == &mNode))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(static_cast<internal_value_type*>(mNode.mpNext) == &mNode))
EASTL_FAIL_MSG("list_map::front -- empty container");
#else
// We allow the user to reference an empty container.
#endif

return static_cast<internal_value_type*>(mNode.mpNext)->mValue;
Expand All @@ -614,11 +614,11 @@ namespace eastl
inline typename list_map<Key, T, Compare, Allocator>::const_reference
list_map<Key, T, Compare, Allocator>::front() const
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(static_cast<internal_value_type*>(mNode.mpNext) == &mNode))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(static_cast<internal_value_type*>(mNode.mpNext) == &mNode))
EASTL_FAIL_MSG("list_map::front -- empty container");
#else
// We allow the user to reference an empty container.
#endif

return static_cast<internal_value_type*>(mNode.mpNext)->mValue;
Expand All @@ -628,11 +628,11 @@ namespace eastl
inline typename list_map<Key, T, Compare, Allocator>::reference
list_map<Key, T, Compare, Allocator>::back()
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(static_cast<internal_value_type*>(mNode.mpNext) == &mNode))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(static_cast<internal_value_type*>(mNode.mpNext) == &mNode))
EASTL_FAIL_MSG("list_map::back -- empty container");
#else
// We allow the user to reference an empty container.
#endif

return static_cast<internal_value_type*>(mNode.mpPrev)->mValue;
Expand All @@ -642,11 +642,11 @@ namespace eastl
inline typename list_map<Key, T, Compare, Allocator>::const_reference
list_map<Key, T, Compare, Allocator>::back() const
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(static_cast<internal_value_type*>(mNode.mpNext) == &mNode))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(static_cast<internal_value_type*>(mNode.mpNext) == &mNode))
EASTL_FAIL_MSG("list_map::back -- empty container");
#else
// We allow the user to reference an empty container.
#endif

return static_cast<internal_value_type*>(mNode.mpPrev)->mValue;
Expand Down
52 changes: 28 additions & 24 deletions include/EASTL/bonus/tuple_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,45 +1131,49 @@ class TupleVecImpl<Allocator, index_sequence<Indices...>, Ts...> : public TupleV

reference_tuple front()
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if (EASTL_UNLIKELY(mNumElements == 0)) // We don't allow the user to reference an empty container.
EASTL_FAIL_MSG("tuple_vector::front -- empty vector");
#endif
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(mNumElements == 0)) // We don't allow the user to reference an empty container.
EASTL_FAIL_MSG("tuple_vector::front -- empty vector");
#else
// We allow the user to reference an empty container.
#endif

return at(0);
}

const_reference_tuple front() const
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if (EASTL_UNLIKELY(mNumElements == 0)) // We don't allow the user to reference an empty container.
EASTL_FAIL_MSG("tuple_vector::front -- empty vector");
#endif
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(mNumElements == 0)) // We don't allow the user to reference an empty container.
EASTL_FAIL_MSG("tuple_vector::front -- empty vector");
#else
// We allow the user to reference an empty container.
#endif

return at(0);
}

reference_tuple back()
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if (EASTL_UNLIKELY(mNumElements == 0)) // We don't allow the user to reference an empty container.
EASTL_FAIL_MSG("tuple_vector::back -- empty vector");
#endif
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(mNumElements == 0)) // We don't allow the user to reference an empty container.
EASTL_FAIL_MSG("tuple_vector::back -- empty vector");
#else
// We allow the user to reference an empty container.
#endif

return at(size() - 1);
}

const_reference_tuple back() const
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if (EASTL_UNLIKELY(mNumElements == 0)) // We don't allow the user to reference an empty container.
EASTL_FAIL_MSG("tuple_vector::back -- empty vector");
#endif
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(mNumElements == 0)) // We don't allow the user to reference an empty container.
EASTL_FAIL_MSG("tuple_vector::back -- empty vector");
#else
// We allow the user to reference an empty container.
#endif

return at(size() - 1);
}

Expand Down
46 changes: 24 additions & 22 deletions include/EASTL/deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -1514,11 +1514,12 @@ namespace eastl
typename deque<T, Allocator, kDequeSubarraySize>::reference
deque<T, Allocator, kDequeSubarraySize>::operator[](size_type n)
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED // We allow the user to use a reference to v[0] of an empty container.
if(EASTL_UNLIKELY((n != 0) && n >= (size_type)(mItEnd - mItBegin)))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(n >= (size_type)(mItEnd - mItBegin)))
EASTL_FAIL_MSG("deque::operator[] -- out of range");
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(n >= (size_type)(mItEnd - mItBegin)))
// We allow taking a reference to deque[0]
if (EASTL_UNLIKELY((n != 0) && n >= (size_type)(mItEnd - mItBegin)))
EASTL_FAIL_MSG("deque::operator[] -- out of range");
#endif

Expand All @@ -1536,11 +1537,12 @@ namespace eastl
typename deque<T, Allocator, kDequeSubarraySize>::const_reference
deque<T, Allocator, kDequeSubarraySize>::operator[](size_type n) const
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED // We allow the user to use a reference to v[0] of an empty container.
if(EASTL_UNLIKELY((n != 0) && n >= (size_type)(mItEnd - mItBegin)))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(n >= (size_type)(mItEnd - mItBegin)))
EASTL_FAIL_MSG("deque::operator[] -- out of range");
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(n >= (size_type)(mItEnd - mItBegin)))
// We allow the user to use a reference to deque[0] of an empty container.
if (EASTL_UNLIKELY((n != 0) && n >= (size_type)(mItEnd - mItBegin)))
EASTL_FAIL_MSG("deque::operator[] -- out of range");
#endif

Expand Down Expand Up @@ -1588,11 +1590,11 @@ namespace eastl
typename deque<T, Allocator, kDequeSubarraySize>::reference
deque<T, Allocator, kDequeSubarraySize>::front()
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY((size_type)(mItEnd == mItBegin)))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY((size_type)(mItEnd == mItBegin)))
EASTL_FAIL_MSG("deque::front -- empty deque");
#else
// We allow the user to reference an empty container.
#endif

return *mItBegin;
Expand All @@ -1603,11 +1605,11 @@ namespace eastl
typename deque<T, Allocator, kDequeSubarraySize>::const_reference
deque<T, Allocator, kDequeSubarraySize>::front() const
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY((size_type)(mItEnd == mItBegin)))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY((size_type)(mItEnd == mItBegin)))
EASTL_FAIL_MSG("deque::front -- empty deque");
#else
// We allow the user to reference an empty container.
#endif

return *mItBegin;
Expand All @@ -1618,11 +1620,11 @@ namespace eastl
typename deque<T, Allocator, kDequeSubarraySize>::reference
deque<T, Allocator, kDequeSubarraySize>::back()
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY((size_type)(mItEnd == mItBegin)))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY((size_type)(mItEnd == mItBegin)))
EASTL_FAIL_MSG("deque::back -- empty deque");
#else
// We allow the user to reference an empty container.
#endif

return *iterator(mItEnd, typename iterator::Decrement());
Expand All @@ -1633,11 +1635,11 @@ namespace eastl
typename deque<T, Allocator, kDequeSubarraySize>::const_reference
deque<T, Allocator, kDequeSubarraySize>::back() const
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY((size_type)(mItEnd == mItBegin)))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY((size_type)(mItEnd == mItBegin)))
EASTL_FAIL_MSG("deque::back -- empty deque");
#else
// We allow the user to reference an empty container.
#endif

return *iterator(mItEnd, typename iterator::Decrement());
Expand Down
22 changes: 6 additions & 16 deletions include/EASTL/internal/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_VERSION
#define EASTL_VERSION "3.16.05"
#define EASTL_VERSION_N 31605
#define EASTL_VERSION "3.16.07"
#define EASTL_VERSION_N 31607
#endif


Expand Down Expand Up @@ -449,6 +449,8 @@ namespace eastl
// In practice it's often easier and more efficient to do this than to write
// extra code to check if the container is empty.
//
// NOTE: If this is enabled, EASTL_ASSERT_ENABLED must also be enabled
//
// Example usage:
// template <typename T, typename Allocator>
// inline typename vector<T, Allocator>::reference
Expand Down Expand Up @@ -1544,13 +1546,8 @@ namespace eastl
// size_t alignment = EASTL_ALIGN_OF(int);
//
///////////////////////////////////////////////////////////////////////////////

#ifndef EASTL_ALIGN_OF
#if !defined(__GNUC__) || (__GNUC__ >= 3) // GCC 2.x doesn't do __alignof correctly all the time.
#define EASTL_ALIGN_OF __alignof
#else
#define EASTL_ALIGN_OF(type) ((size_t)offsetof(struct{ char c; type m; }, m))
#endif
#define EASTL_ALIGN_OF alignof
#endif


Expand Down Expand Up @@ -1768,6 +1765,7 @@ typedef EASTL_SSIZE_T eastl_ssize_t; // Signed version of eastl_size_t. Concept
#endif
#endif


/// EASTL_TUPLE_ENABLED
/// EASTL tuple implementation depends on variadic template support
#if EASTL_VARIADIC_TEMPLATES_ENABLED && !defined(EA_COMPILER_NO_TEMPLATE_ALIASES)
Expand All @@ -1776,14 +1774,6 @@ typedef EASTL_SSIZE_T eastl_ssize_t; // Signed version of eastl_size_t. Concept
#define EASTL_TUPLE_ENABLED 0
#endif

/// EA_ONCE
///
/// This is a fix for the EA_ONCE define that's broken in EABase versions prior to 2.00.40
///
#ifndef EA_ONCE
#define EA_ONCE()
#endif


/// EASTL_FUNCTION_ENABLED
///
Expand Down
32 changes: 16 additions & 16 deletions include/EASTL/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -995,11 +995,11 @@ namespace eastl
inline typename list<T, Allocator>::reference
list<T, Allocator>::front()
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(static_cast<node_type*>(internalNode().mpNext) == &internalNode()))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(static_cast<node_type*>(internalNode().mpNext) == &internalNode()))
EASTL_FAIL_MSG("list::front -- empty container");
#else
// We allow the user to reference an empty container.
#endif

return static_cast<node_type*>(internalNode().mpNext)->mValue;
Expand All @@ -1010,11 +1010,11 @@ namespace eastl
inline typename list<T, Allocator>::const_reference
list<T, Allocator>::front() const
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(static_cast<node_type*>(internalNode().mpNext) == &internalNode()))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(static_cast<node_type*>(internalNode().mpNext) == &internalNode()))
EASTL_FAIL_MSG("list::front -- empty container");
#else
// We allow the user to reference an empty container.
#endif

return static_cast<node_type*>(internalNode().mpNext)->mValue;
Expand All @@ -1025,11 +1025,11 @@ namespace eastl
inline typename list<T, Allocator>::reference
list<T, Allocator>::back()
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(static_cast<node_type*>(internalNode().mpNext) == &internalNode()))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(static_cast<node_type*>(internalNode().mpNext) == &internalNode()))
EASTL_FAIL_MSG("list::back -- empty container");
#else
// We allow the user to reference an empty container.
#endif

return static_cast<node_type*>(internalNode().mpPrev)->mValue;
Expand All @@ -1040,11 +1040,11 @@ namespace eastl
inline typename list<T, Allocator>::const_reference
list<T, Allocator>::back() const
{
#if EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
// We allow the user to reference an empty container.
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(static_cast<node_type*>(internalNode().mpNext) == &internalNode()))
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(static_cast<node_type*>(internalNode().mpNext) == &internalNode()))
EASTL_FAIL_MSG("list::back -- empty container");
#else
// We allow the user to reference an empty container.
#endif

return static_cast<node_type*>(internalNode().mpPrev)->mValue;
Expand Down
Loading

1 comment on commit b2d923a

@rparolin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. 👍

Please sign in to comment.