Skip to content

Commit

Permalink
Finish release 0.6-1
Browse files Browse the repository at this point in the history
  • Loading branch information
foonathan committed Oct 31, 2017
2 parents 9a7bb61 + d5136bf commit d5a03e0
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 65 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 0.6-1

* fix CMake configuration error
* fix double free error in `segregator`
* add `static_assert()` when default constructing a stateful `std_allocator`
* fix various compiler warnings

---

# 0.6

## Tool
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ project(FOONATHAN_MEMORY)

set(FOONATHAN_MEMORY_VERSION_MAJOR 0 CACHE STRING "major version of memory" FORCE)
set(FOONATHAN_MEMORY_VERSION_MINOR 6 CACHE STRING "minor version of memory" FORCE)
set(FOONATHAN_MEMORY_VERSION "${FOONATHAN_MEMORY_VERSION_MAJOR}.${FOONATHAN_MEMORY_VERSION_MINOR}"
set(FOONATHAN_MEMORY_VERSION_PATCH 1 CACHE STRING "patch version of memory" FORCE)
set(FOONATHAN_MEMORY_VERSION "${FOONATHAN_MEMORY_VERSION_MAJOR}.${FOONATHAN_MEMORY_VERSION_MINOR}.${FOONATHAN_MEMORY_VERSION_PATCH}"
CACHE STRING "version of memory" FORCE)

include(cmake/compatibility.cmake)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# memory

[![Build Status](https://travis-ci.org/foonathan/memory.svg?branch=master)](https://travis-ci.org/foonathan/memory) [![Build status](https://ci.appveyor.com/api/projects/status/ef654yqyoqgvl472/branch/master?svg=true)](https://ci.appveyor.com/project/foonathan/memory/branch/master)
[![Build Status](https://travis-ci.org/foonathan/memory.svg?branch=master)](https://travis-ci.org/foonathan/memory) [![Build status](https://ci.appveyor.com/api/projects/status/ef654yqyoqgvl472/branch/master?svg=true)](https://ci.appveyor.com/project/foonathan/memory/branch/master) [![License: Zlib](https://img.shields.io/badge/License-Zlib-lightgrey.svg)](https://opensource.org/licenses/Zlib)

The C++ STL allocator model has various flaws. For example, they are fixed to a certain type, because they are almost necessarily required to be templates. So you can't easily share a single allocator for multiple types. In addition, you can only get a copy from the containers and not the original allocator object. At least with C++11 they are allowed to be stateful and so can be made object not instance based. But still, the model has many flaws.
Over the course of the years many solutions have been proposed. for example [EASTL]. This library is another. But instead of trying to change the STL, it works with the current implementation.
Expand Down
2 changes: 1 addition & 1 deletion cmake/comp
Submodule comp updated 1 files
+233 −81 comp_base.cmake
11 changes: 5 additions & 6 deletions include/foonathan/memory/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,22 @@ namespace foonathan
const void* allocator;

/// \effects Creates it by giving it the name of the allocator and a pointer.
FOONATHAN_CONSTEXPR allocator_info(const char *name,
const void *allocator) FOONATHAN_NOEXCEPT
: name(name),
allocator(allocator)
FOONATHAN_CONSTEXPR_FNC allocator_info(const char* n, const void* alloc) FOONATHAN_NOEXCEPT
: name(n),
allocator(alloc)
{
}

/// @{
/// \effects Compares two \ref allocator_info objects, they are equal, if the \ref allocator is the same.
/// \returns The result of the comparision.
friend FOONATHAN_CONSTEXPR bool operator==(const allocator_info& a,
friend FOONATHAN_CONSTEXPR_FNC bool operator==(const allocator_info& a,
const allocator_info& b) FOONATHAN_NOEXCEPT
{
return a.allocator == b.allocator;
}

friend FOONATHAN_CONSTEXPR bool operator!=(const allocator_info& a,
friend FOONATHAN_CONSTEXPR_FNC bool operator!=(const allocator_info& a,
const allocator_info& b) FOONATHAN_NOEXCEPT
{
return a.allocator != b.allocator;
Expand Down
4 changes: 2 additions & 2 deletions include/foonathan/memory/joint_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace foonathan
/// \ingroup memory allocator
class joint
{
joint(std::size_t capacity) FOONATHAN_NOEXCEPT : capacity(capacity)
joint(std::size_t cap) FOONATHAN_NOEXCEPT : capacity(cap)
{
}

Expand All @@ -122,7 +122,7 @@ namespace foonathan
{
std::size_t size;

explicit joint_size(std::size_t size) FOONATHAN_NOEXCEPT : size(size)
explicit joint_size(std::size_t s) FOONATHAN_NOEXCEPT : size(s)
{
}
};
Expand Down
5 changes: 2 additions & 3 deletions include/foonathan/memory/memory_arena.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace foonathan
}

/// \effects Creates a memory block from a given starting address and size.
memory_block(void* mem, std::size_t size) FOONATHAN_NOEXCEPT : memory(mem), size(size)
memory_block(void* mem, std::size_t s) FOONATHAN_NOEXCEPT : memory(mem), size(s)
{
}

Expand Down Expand Up @@ -169,8 +169,7 @@ namespace foonathan
node* prev;
std::size_t usable_size;

node(node* prev, std::size_t size) FOONATHAN_NOEXCEPT : prev(prev),
usable_size(size)
node(node* p, std::size_t size) FOONATHAN_NOEXCEPT : prev(p), usable_size(size)
{
}

Expand Down
6 changes: 3 additions & 3 deletions include/foonathan/memory/memory_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ namespace foonathan
const char* end;

stack_marker(std::size_t i, const detail::fixed_memory_stack& s,
const char* end) FOONATHAN_NOEXCEPT : index(i),
top(s.top()),
end(end)
const char* e) FOONATHAN_NOEXCEPT : index(i),
top(s.top()),
end(e)
{
}

Expand Down
22 changes: 14 additions & 8 deletions include/foonathan/memory/segregator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ namespace foonathan
/// \ingroup memory adapter
template <class Segregatable, class RawAllocator>
class binary_segregator
: FOONATHAN_EBO(
detail::ebo_storage<1, typename allocator_traits<RawAllocator>::allocator_type>)
: FOONATHAN_EBO(
detail::ebo_storage<1, typename allocator_traits<RawAllocator>::allocator_type>)
{
using segregatable_traits = allocator_traits<typename Segregatable::allocator_type>;
using fallback_traits = allocator_traits<RawAllocator>;
Expand All @@ -152,7 +152,9 @@ namespace foonathan
if (get_segregatable().use_allocate_node(size, alignment))
return segregatable_traits::allocate_node(get_segregatable_allocator(), size,
alignment);
return fallback_traits::allocate_node(get_fallback_allocator(), size, alignment);
else
return fallback_traits::allocate_node(get_fallback_allocator(), size,
alignment);
}

void deallocate_node(void* ptr, std::size_t size,
Expand All @@ -161,16 +163,19 @@ namespace foonathan
if (get_segregatable().use_allocate_node(size, alignment))
segregatable_traits::deallocate_node(get_segregatable_allocator(), ptr, size,
alignment);
fallback_traits::deallocate_node(get_fallback_allocator(), ptr, size, alignment);
else
fallback_traits::deallocate_node(get_fallback_allocator(), ptr, size,
alignment);
}

void* allocate_array(std::size_t count, std::size_t size, std::size_t alignment)
{
if (get_segregatable().use_allocate_array(count, size, alignment))
return segregatable_traits::allocate_array(get_segregatable_allocator(), count,
size, alignment);
return fallback_traits::allocate_array(get_fallback_allocator(), count, size,
alignment);
else
return fallback_traits::allocate_array(get_fallback_allocator(), count, size,
alignment);
}

void deallocate_array(void* array, std::size_t count, std::size_t size,
Expand All @@ -179,8 +184,9 @@ namespace foonathan
if (get_segregatable().use_allocate_array(count, size, alignment))
segregatable_traits::deallocate_array(get_segregatable_allocator(), array,
count, size, alignment);
fallback_traits::deallocate_array(get_fallback_allocator(), array, count, size,
alignment);
else
fallback_traits::deallocate_array(get_fallback_allocator(), array, count, size,
alignment);
}
/// @}

Expand Down
32 changes: 20 additions & 12 deletions include/foonathan/memory/std_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ namespace foonathan
/// \requires The \c RawAllocator type is stateless, otherwise the body of this function will not compile.
std_allocator() FOONATHAN_NOEXCEPT : alloc_reference(allocator_type{})
{
#if !defined(__GNUC__) || (defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI != 0)
// std::string requires default constructor for the small string optimization when using gcc's old ABI
// so don't assert then to allow joint allocator
static_assert(!alloc_reference::is_stateful::value,
"default constructor must not be used for stateful allocators");
#endif
}

/// \effects Creates it from a reference to a \c RawAllocator.
Expand All @@ -121,13 +127,14 @@ namespace foonathan
/// If the requirement is not fulfilled this function does not participate in overload resolution.
/// \note The caller has to ensure that the lifetime of the \c RawAllocator is at least as long as the lifetime
/// of this \ref std_allocator object.
template <class RawAlloc,
// MSVC seems to ignore access rights in decltype SFINAE below
// use this to prevent this constructor being chosen instead of move/copy for types inheriting from it
FOONATHAN_REQUIRES((!std::is_base_of<std_allocator, RawAlloc>::value))>
template <
class RawAlloc,
// MSVC seems to ignore access rights in decltype SFINAE below
// use this to prevent this constructor being chosen instead of move/copy for types inheriting from it
FOONATHAN_REQUIRES((!std::is_base_of<std_allocator, RawAlloc>::value))>
std_allocator(RawAlloc& alloc,
FOONATHAN_SFINAE(alloc_reference(alloc))) FOONATHAN_NOEXCEPT
: alloc_reference(alloc)
: alloc_reference(alloc)
{
}

Expand All @@ -136,13 +143,14 @@ namespace foonathan
/// \requires The \c RawAllocator is stateless
/// and the expression <tt>allocator_reference<RawAllocator, Mutex>(alloc)</tt> is well-formed as above,
/// otherwise this function does not participate in overload resolution.
template <class RawAlloc,
// MSVC seems to ignore access rights in decltype SFINAE below
// use this to prevent this constructor being chosen instead of move/copy for types inheriting from it
FOONATHAN_REQUIRES((!std::is_base_of<std_allocator, RawAlloc>::value))>
template <
class RawAlloc,
// MSVC seems to ignore access rights in decltype SFINAE below
// use this to prevent this constructor being chosen instead of move/copy for types inheriting from it
FOONATHAN_REQUIRES((!std::is_base_of<std_allocator, RawAlloc>::value))>
std_allocator(const RawAlloc& alloc,
FOONATHAN_SFINAE(alloc_reference(alloc))) FOONATHAN_NOEXCEPT
: alloc_reference(alloc)
: alloc_reference(alloc)
{
}

Expand All @@ -161,13 +169,13 @@ namespace foonathan
/// This is required by the \c Allcoator concept and simply takes the same \ref allocator_reference.
template <typename U>
std_allocator(const std_allocator<U, RawAllocator, Mutex>& alloc) FOONATHAN_NOEXCEPT
: alloc_reference(alloc.get_allocator())
: alloc_reference(alloc.get_allocator())
{
}

template <typename U>
std_allocator(std_allocator<U, RawAllocator, Mutex>& alloc) FOONATHAN_NOEXCEPT
: alloc_reference(alloc.get_allocator())
: alloc_reference(alloc.get_allocator())
{
}
/// @}
Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(detail_header
${header_path}/detail/assert.hpp
${header_path}/detail/container_node_sizes.hpp
${header_path}/detail/debug_helpers.hpp
${header_path}/detail/ebo_storage.hpp
${header_path}/detail/free_list.hpp
${header_path}/detail/free_list_array.hpp
${header_path}/detail/lowlevel_allocator.hpp
Expand Down Expand Up @@ -88,6 +89,7 @@ endif()

add_library(foonathan_memory ${detail_header} ${header} ${src})
_foonathan_use_comp(foonathan_memory)
comp_target_features(foonathan_memory PRIVATE CPP11)
target_include_directories(foonathan_memory PUBLIC $<BUILD_INTERFACE:${FOONATHAN_MEMORY_SOURCE_DIR}/include/> # for client in subdirectory
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> # for generated files in build mode
$<INSTALL_INTERFACE:${include_dest}> # for client in install mode
Expand All @@ -96,7 +98,8 @@ target_include_directories(foonathan_memory PUBLIC $<BUILD_INTERFACE:${FOONATHAN
target_compile_definitions(foonathan_memory PUBLIC
FOONATHAN_MEMORY=1
FOONATHAN_MEMORY_VERSION_MAJOR=${FOONATHAN_MEMORY_VERSION_MAJOR}
FOONATHAN_MEMORY_VERSION_MINOR=${FOONATHAN_MEMORY_VERSION_MINOR})
FOONATHAN_MEMORY_VERSION_MINOR=${FOONATHAN_MEMORY_VERSION_MINOR}
FOONATHAN_MEMORY_VERSION_PATCH=${FOONATHAN_MEMORY_VERSION_PATCH})

# installation
install(TARGETS foonathan_memory EXPORT foonathan_memory DESTINATION ${lib_dest})
Expand Down
8 changes: 4 additions & 4 deletions src/detail/small_free_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ chunk* small_free_memory_list::find_chunk_impl(std::size_t n) FOONATHAN_NOEXCEPT
{
if (auto c = make_chunk(alloc_chunk_, n))
return c;
else if (auto c = make_chunk(dealloc_chunk_, n))
else if ((c = make_chunk(dealloc_chunk_, n)) != nullptr)
return c;

auto cur_forward = alloc_chunk_->next;
Expand All @@ -358,7 +358,7 @@ chunk* small_free_memory_list::find_chunk_impl(std::size_t n) FOONATHAN_NOEXCEPT
{
if (auto c = make_chunk(cur_forward, n))
return c;
else if (auto c = make_chunk(cur_backward, n))
else if ((c = make_chunk(cur_backward, n)) != nullptr)
return c;

cur_forward = cur_forward->next;
Expand All @@ -379,7 +379,7 @@ chunk* small_free_memory_list::find_chunk_impl(unsigned char* node, chunk_base*
{
if (auto c = from_chunk(first, node, actual_size))
return c;
else if (auto c = from_chunk(last, node, actual_size))
else if ((c = from_chunk(last, node, actual_size)) != nullptr)
return c;

first = first->next;
Expand All @@ -394,7 +394,7 @@ chunk* small_free_memory_list::find_chunk_impl(unsigned char* node) FOONATHAN_NO

if (auto c = from_chunk(dealloc_chunk_, node, actual_size))
return c;
else if (auto c = from_chunk(alloc_chunk_, node, actual_size))
else if ((c = from_chunk(alloc_chunk_, node, actual_size)) != nullptr)
return c;
else if (less(dealloc_chunk_, node))
{
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ set(tests
segregator.cpp)

add_executable(foonathan_memory_test ${tests})
comp_target_features(foonathan_memory_test PUBLIC CPP11)
target_link_libraries(foonathan_memory_test foonathan_memory)
target_include_directories(foonathan_memory_test PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
Expand Down
16 changes: 8 additions & 8 deletions test/default_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ void check_default_allocator(Allocator& alloc, std::size_t def_alignment = detai

for (std::size_t i = 0u; i != 10u; ++i)
{
auto ptr = alloc.allocate_node(i, 1);
REQUIRE(detail::is_aligned(ptr, def_alignment));
alloc.deallocate_node(ptr, i, 1);
auto node = alloc.allocate_node(i, 1);
REQUIRE(detail::is_aligned(node, def_alignment));
alloc.deallocate_node(node, i, 1);
}

std::vector<void*> ptrs;
std::vector<void*> nodes;
for (std::size_t i = 0u; i != 10u; ++i)
{
auto ptr = alloc.allocate_node(i, 1);
REQUIRE(detail::is_aligned(ptr, def_alignment));
ptrs.push_back(ptr);
auto node = alloc.allocate_node(i, 1);
REQUIRE(detail::is_aligned(node, def_alignment));
nodes.push_back(node);
}

for (std::size_t i = 0u; i != 10u; ++i)
alloc.deallocate_node(ptrs[i], i, 1);
alloc.deallocate_node(nodes[i], i, 1);
}

TEST_CASE("heap_allocator", "[default_allocator]")
Expand Down
Loading

0 comments on commit d5a03e0

Please sign in to comment.