www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18259] New: allocatorObject's CAllocatorImpl should store the

https://issues.dlang.org/show_bug.cgi?id=18259

          Issue ID: 18259
           Summary: allocatorObject's CAllocatorImpl should store the
                    passed allocator within
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: edi33416 gmail.com

allocatorObject uses the passed allocator to allocate the memory chunk that
will store the CAllocatorImpl instance, and thus, the allocator stored within
the newly created instance should be the one that was passed to the function.

This being said, the unittest below should pass.

unittest
{
    import std.conv;
    import std.experimental.allocator.mallocator;
    import std.experimental.allocator.building_blocks.stats_collector;

    alias SCAlloc = StatsCollector!(Mallocator, Options.bytesUsed);
    SCAlloc statsCollectorAlloc;
    assert(statsCollectorAlloc.bytesUsed == 0);

    auto _allocator = allocatorObject(statsCollectorAlloc);
    // Ensure that the allocator was passed through in CAllocatorImpl
    // This allocator was used to allocate the chunk that holds the
    // CAllocatorImpl object; which is it's own wrapper
    assert(_allocator.impl.bytesUsed == stateSize!(CAllocatorImpl!(SCAlloc)));
    _allocator.allocate(1);
    assert(_allocator.impl.bytesUsed == stateSize!(CAllocatorImpl!(SCAlloc)) +
1);
}

--
Jan 17 2018