www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16507] New: std.experimental.allocator: FreeTree clears too


          Issue ID: 16507
           Summary: std.experimental.allocator: FreeTree clears too
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

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);
    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.


Sep 18 2016