Skip to content

Commit

Permalink
Make AffixAllocator take into account RCISharedAllocator
Browse files Browse the repository at this point in the history
  • Loading branch information
edi33416 committed Feb 21, 2018
1 parent 9021bd3 commit 41bf8dd
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions std/experimental/allocator/building_blocks/affix_allocator.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
{
import std.algorithm.comparison : min;
import std.conv : emplace;
import std.experimental.allocator : RCIAllocator, theAllocator;
import std.experimental.allocator : RCIAllocator, RCISharedAllocator,
theAllocator, processAllocator;
import std.experimental.allocator.common : stateSize, forwardToMember,
roundUpToMultipleOf, alignedAt, alignDownTo, roundUpToMultipleOf,
hasStaticallyKnownAlignment;
Expand Down Expand Up @@ -69,11 +70,21 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
static if (stateSize!Allocator)
{
Allocator _parent;
static if (is(Allocator == RCIAllocator))
static if (is(Allocator == RCIAllocator) || is(Allocator == RCISharedAllocator))
{
Allocator parent()
{
if (_parent.isNull) _parent = theAllocator;
if (_parent.isNull)
{
static if (is(Allocator == RCIAllocator))
{
_parent = theAllocator;
}
else
{
_parent = processAllocator;
}
}
assert(alignment <= _parent.alignment);
return _parent;
}
Expand Down Expand Up @@ -499,3 +510,12 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
assert(b.length == 100);
assert((() nothrow @nogc => a.deallocate(b))());
}

@system unittest
{
import std.experimental.allocator : RCISharedAllocator, processAllocator;

AffixAllocator!(RCISharedAllocator, uint) a;
auto buf = a.allocate(42);
assert(buf.length == 42);
}

0 comments on commit 41bf8dd

Please sign in to comment.