Bug 16507 – std.experimental.allocator: FreeTree clears too eagerly
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-09-18T22:14:00Z
Last change time
2016-10-01T11:47:17Z
Keywords
pull
Assigned to
ag0aep6g
Creator
ag0aep6g
Comments
Comment #0 by ag0aep6g — 2016-09-18T22:14:10Z
Documentatinon [1] says: "If allocation from the parent succeeds, the allocated block is returned. Otherwise, [...] FreeTree releases all of its contents and tries again."
----
import std.experimental.allocator.building_blocks: FreeTree;
struct MyAllocator
{
byte dummy;
static bool alive = true;
void[] allocate(size_t s) { return new byte[](s); }
bool deallocate(void[] ) { if (alive) assert(false); return true; }
enum alignment = size_t.sizeof;
}
void main()
{
FreeTree!MyAllocator ft;
void[] x = ft.allocate(1);
ft.deallocate(x);
ft.allocate(1000);
MyAllocator.alive = false;
}
----
The assert is hit. It shouldn't be. For the second allocation, ft should allocate from the parent allocator without deallocating the free block.
Pull request incoming.
[1] http://dlang.org/phobos/std_experimental_allocator_building_blocks_free_tree.html#.FreeTree.allocate