Skip to content

Commit 41bf8dd

Browse files
committed
Make AffixAllocator take into account RCISharedAllocator
1 parent 9021bd3 commit 41bf8dd

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

std/experimental/allocator/building_blocks/affix_allocator.d

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
2424
{
2525
import std.algorithm.comparison : min;
2626
import std.conv : emplace;
27-
import std.experimental.allocator : RCIAllocator, theAllocator;
27+
import std.experimental.allocator : RCIAllocator, RCISharedAllocator,
28+
theAllocator, processAllocator;
2829
import std.experimental.allocator.common : stateSize, forwardToMember,
2930
roundUpToMultipleOf, alignedAt, alignDownTo, roundUpToMultipleOf,
3031
hasStaticallyKnownAlignment;
@@ -69,11 +70,21 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
6970
static if (stateSize!Allocator)
7071
{
7172
Allocator _parent;
72-
static if (is(Allocator == RCIAllocator))
73+
static if (is(Allocator == RCIAllocator) || is(Allocator == RCISharedAllocator))
7374
{
7475
Allocator parent()
7576
{
76-
if (_parent.isNull) _parent = theAllocator;
77+
if (_parent.isNull)
78+
{
79+
static if (is(Allocator == RCIAllocator))
80+
{
81+
_parent = theAllocator;
82+
}
83+
else
84+
{
85+
_parent = processAllocator;
86+
}
87+
}
7788
assert(alignment <= _parent.alignment);
7889
return _parent;
7990
}
@@ -499,3 +510,12 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
499510
assert(b.length == 100);
500511
assert((() nothrow @nogc => a.deallocate(b))());
501512
}
513+
514+
@system unittest
515+
{
516+
import std.experimental.allocator : RCISharedAllocator, processAllocator;
517+
518+
AffixAllocator!(RCISharedAllocator, uint) a;
519+
auto buf = a.allocate(42);
520+
assert(buf.length == 42);
521+
}

0 commit comments

Comments
 (0)