Bug 18847 – std.allocator: Region uses .parent before it can be set
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-05-10T10:48:06Z
Last change time
2018-06-07T21:01:46Z
Keywords
pull
Assigned to
Vladimir Panteleev
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2018-05-10T10:48:06Z
Here is one constructor of std.experimental.allocator.building_blocks.region.Region:
static if (!is(ParentAllocator == NullAllocator))
this(size_t n)
{
this(cast(ubyte[])(parent.allocate(n.roundUpToAlignment(alignment))));
}
If parent has state, then there is no way to set it before it is used in the constructor.
There is a workaround: copy the contents of the constructor of the invoking code, then use the constructor taking a buffer, and only then initialize the parent. This is sub-ideal.
The constructor(s) should probably accept a parent argument as needed, or the object should support deferred initialization.
Comment #1 by dlang-bugzilla — 2018-05-15T03:39:07Z
Some goes for BitmappedBlock and KKRegion.
ContiguousFreeList seems to have gotten this right (though with the end result of having 8 constructor declarations).
Comment #2 by dlang-bugzilla — 2018-05-15T23:02:26Z