Skip to content

Commit d5a03e0

Browse files
committed
Finish release 0.6-1
2 parents 9a7bb61 + d5136bf commit d5a03e0

21 files changed

Lines changed: 123 additions & 65 deletions

CHANGELOG.MD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 0.6-1
2+
3+
* fix CMake configuration error
4+
* fix double free error in `segregator`
5+
* add `static_assert()` when default constructing a stateful `std_allocator`
6+
* fix various compiler warnings
7+
8+
---
9+
110
# 0.6
211

312
## Tool

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ project(FOONATHAN_MEMORY)
99

1010
set(FOONATHAN_MEMORY_VERSION_MAJOR 0 CACHE STRING "major version of memory" FORCE)
1111
set(FOONATHAN_MEMORY_VERSION_MINOR 6 CACHE STRING "minor version of memory" FORCE)
12-
set(FOONATHAN_MEMORY_VERSION "${FOONATHAN_MEMORY_VERSION_MAJOR}.${FOONATHAN_MEMORY_VERSION_MINOR}"
12+
set(FOONATHAN_MEMORY_VERSION_PATCH 1 CACHE STRING "patch version of memory" FORCE)
13+
set(FOONATHAN_MEMORY_VERSION "${FOONATHAN_MEMORY_VERSION_MAJOR}.${FOONATHAN_MEMORY_VERSION_MINOR}.${FOONATHAN_MEMORY_VERSION_PATCH}"
1314
CACHE STRING "version of memory" FORCE)
1415

1516
include(cmake/compatibility.cmake)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# memory
22

3-
[![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)
3+
[![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)
44

55
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.
66
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.

cmake/comp

include/foonathan/memory/error.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,22 @@ namespace foonathan
3535
const void* allocator;
3636

3737
/// \effects Creates it by giving it the name of the allocator and a pointer.
38-
FOONATHAN_CONSTEXPR allocator_info(const char *name,
39-
const void *allocator) FOONATHAN_NOEXCEPT
40-
: name(name),
41-
allocator(allocator)
38+
FOONATHAN_CONSTEXPR_FNC allocator_info(const char* n, const void* alloc) FOONATHAN_NOEXCEPT
39+
: name(n),
40+
allocator(alloc)
4241
{
4342
}
4443

4544
/// @{
4645
/// \effects Compares two \ref allocator_info objects, they are equal, if the \ref allocator is the same.
4746
/// \returns The result of the comparision.
48-
friend FOONATHAN_CONSTEXPR bool operator==(const allocator_info& a,
47+
friend FOONATHAN_CONSTEXPR_FNC bool operator==(const allocator_info& a,
4948
const allocator_info& b) FOONATHAN_NOEXCEPT
5049
{
5150
return a.allocator == b.allocator;
5251
}
5352

54-
friend FOONATHAN_CONSTEXPR bool operator!=(const allocator_info& a,
53+
friend FOONATHAN_CONSTEXPR_FNC bool operator!=(const allocator_info& a,
5554
const allocator_info& b) FOONATHAN_NOEXCEPT
5655
{
5756
return a.allocator != b.allocator;

include/foonathan/memory/joint_allocator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace foonathan
102102
/// \ingroup memory allocator
103103
class joint
104104
{
105-
joint(std::size_t capacity) FOONATHAN_NOEXCEPT : capacity(capacity)
105+
joint(std::size_t cap) FOONATHAN_NOEXCEPT : capacity(cap)
106106
{
107107
}
108108

@@ -122,7 +122,7 @@ namespace foonathan
122122
{
123123
std::size_t size;
124124

125-
explicit joint_size(std::size_t size) FOONATHAN_NOEXCEPT : size(size)
125+
explicit joint_size(std::size_t s) FOONATHAN_NOEXCEPT : size(s)
126126
{
127127
}
128128
};

include/foonathan/memory/memory_arena.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace foonathan
3838
}
3939

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

@@ -169,8 +169,7 @@ namespace foonathan
169169
node* prev;
170170
std::size_t usable_size;
171171

172-
node(node* prev, std::size_t size) FOONATHAN_NOEXCEPT : prev(prev),
173-
usable_size(size)
172+
node(node* p, std::size_t size) FOONATHAN_NOEXCEPT : prev(p), usable_size(size)
174173
{
175174
}
176175

include/foonathan/memory/memory_stack.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ namespace foonathan
3535
const char* end;
3636

3737
stack_marker(std::size_t i, const detail::fixed_memory_stack& s,
38-
const char* end) FOONATHAN_NOEXCEPT : index(i),
39-
top(s.top()),
40-
end(end)
38+
const char* e) FOONATHAN_NOEXCEPT : index(i),
39+
top(s.top()),
40+
end(e)
4141
{
4242
}
4343

include/foonathan/memory/segregator.hpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ namespace foonathan
124124
/// \ingroup memory adapter
125125
template <class Segregatable, class RawAllocator>
126126
class binary_segregator
127-
: FOONATHAN_EBO(
128-
detail::ebo_storage<1, typename allocator_traits<RawAllocator>::allocator_type>)
127+
: FOONATHAN_EBO(
128+
detail::ebo_storage<1, typename allocator_traits<RawAllocator>::allocator_type>)
129129
{
130130
using segregatable_traits = allocator_traits<typename Segregatable::allocator_type>;
131131
using fallback_traits = allocator_traits<RawAllocator>;
@@ -152,7 +152,9 @@ namespace foonathan
152152
if (get_segregatable().use_allocate_node(size, alignment))
153153
return segregatable_traits::allocate_node(get_segregatable_allocator(), size,
154154
alignment);
155-
return fallback_traits::allocate_node(get_fallback_allocator(), size, alignment);
155+
else
156+
return fallback_traits::allocate_node(get_fallback_allocator(), size,
157+
alignment);
156158
}
157159

158160
void deallocate_node(void* ptr, std::size_t size,
@@ -161,16 +163,19 @@ namespace foonathan
161163
if (get_segregatable().use_allocate_node(size, alignment))
162164
segregatable_traits::deallocate_node(get_segregatable_allocator(), ptr, size,
163165
alignment);
164-
fallback_traits::deallocate_node(get_fallback_allocator(), ptr, size, alignment);
166+
else
167+
fallback_traits::deallocate_node(get_fallback_allocator(), ptr, size,
168+
alignment);
165169
}
166170

167171
void* allocate_array(std::size_t count, std::size_t size, std::size_t alignment)
168172
{
169173
if (get_segregatable().use_allocate_array(count, size, alignment))
170174
return segregatable_traits::allocate_array(get_segregatable_allocator(), count,
171175
size, alignment);
172-
return fallback_traits::allocate_array(get_fallback_allocator(), count, size,
173-
alignment);
176+
else
177+
return fallback_traits::allocate_array(get_fallback_allocator(), count, size,
178+
alignment);
174179
}
175180

176181
void deallocate_array(void* array, std::size_t count, std::size_t size,
@@ -179,8 +184,9 @@ namespace foonathan
179184
if (get_segregatable().use_allocate_array(count, size, alignment))
180185
segregatable_traits::deallocate_array(get_segregatable_allocator(), array,
181186
count, size, alignment);
182-
fallback_traits::deallocate_array(get_fallback_allocator(), array, count, size,
183-
alignment);
187+
else
188+
fallback_traits::deallocate_array(get_fallback_allocator(), array, count, size,
189+
alignment);
184190
}
185191
/// @}
186192

include/foonathan/memory/std_allocator.hpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ namespace foonathan
112112
/// \requires The \c RawAllocator type is stateless, otherwise the body of this function will not compile.
113113
std_allocator() FOONATHAN_NOEXCEPT : alloc_reference(allocator_type{})
114114
{
115+
#if !defined(__GNUC__) || (defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI != 0)
116+
// std::string requires default constructor for the small string optimization when using gcc's old ABI
117+
// so don't assert then to allow joint allocator
118+
static_assert(!alloc_reference::is_stateful::value,
119+
"default constructor must not be used for stateful allocators");
120+
#endif
115121
}
116122

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

@@ -136,13 +143,14 @@ namespace foonathan
136143
/// \requires The \c RawAllocator is stateless
137144
/// and the expression <tt>allocator_reference<RawAllocator, Mutex>(alloc)</tt> is well-formed as above,
138145
/// otherwise this function does not participate in overload resolution.
139-
template <class RawAlloc,
140-
// MSVC seems to ignore access rights in decltype SFINAE below
141-
// use this to prevent this constructor being chosen instead of move/copy for types inheriting from it
142-
FOONATHAN_REQUIRES((!std::is_base_of<std_allocator, RawAlloc>::value))>
146+
template <
147+
class RawAlloc,
148+
// MSVC seems to ignore access rights in decltype SFINAE below
149+
// use this to prevent this constructor being chosen instead of move/copy for types inheriting from it
150+
FOONATHAN_REQUIRES((!std::is_base_of<std_allocator, RawAlloc>::value))>
143151
std_allocator(const RawAlloc& alloc,
144152
FOONATHAN_SFINAE(alloc_reference(alloc))) FOONATHAN_NOEXCEPT
145-
: alloc_reference(alloc)
153+
: alloc_reference(alloc)
146154
{
147155
}
148156

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

168176
template <typename U>
169177
std_allocator(std_allocator<U, RawAllocator, Mutex>& alloc) FOONATHAN_NOEXCEPT
170-
: alloc_reference(alloc.get_allocator())
178+
: alloc_reference(alloc.get_allocator())
171179
{
172180
}
173181
/// @}

0 commit comments

Comments
 (0)