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
Comment #1 by ag0aep6g — 2016-09-18T22:20:17Z
Comment #2 by github-bugzilla — 2016-09-24T19:45:47Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/46599a63ed899276bff5053970e468bce645e3fc fix issue 16507 - std.experimental.allocator: FreeTree clears too eagerly Try parent allocator without clearing first. Documentation says so. https://github.com/dlang/phobos/commit/25418edb0611ca6de06c6a8d7281407cd4c9a2e6 Merge pull request #4798 from aG0aep6G/FreeTree std.experimental.allocator: fix FreeTree issues 16506 and 16507
Comment #3 by github-bugzilla — 2016-10-01T11:47:17Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/46599a63ed899276bff5053970e468bce645e3fc fix issue 16507 - std.experimental.allocator: FreeTree clears too eagerly https://github.com/dlang/phobos/commit/25418edb0611ca6de06c6a8d7281407cd4c9a2e6 Merge pull request #4798 from aG0aep6G/FreeTree