Skip to content

Commit 0d627bf

Browse files
committed
Fix issue 17564: Eliminate "static this" for theAllocator
This switches to lazy initialization of theAllocator, so that accessing it form within `shared static this` works as expected.
1 parent e4afaca commit 0d627bf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

std/experimental/allocator/package.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ interface ISharedAllocator
462462
private shared ISharedAllocator _processAllocator;
463463
IAllocator _threadAllocator;
464464

465-
static this()
466-
{
465+
private void setupThreadAllocator()
466+
@safe nothrow @nogc {
467467
/*
468468
Forwards the `_threadAllocator` calls to the `processAllocator`
469469
*/
@@ -538,7 +538,7 @@ static this()
538538
assert(!_threadAllocator);
539539
import std.conv : emplace;
540540
static ulong[stateSize!(ThreadAllocator).divideRoundUp(ulong.sizeof)] _threadAllocatorState;
541-
_threadAllocator = emplace!(ThreadAllocator)(_threadAllocatorState[]);
541+
_threadAllocator = () @trusted { return emplace!(ThreadAllocator)(_threadAllocatorState[]); } ();
542542
}
543543

544544
/**
@@ -550,6 +550,7 @@ in turn uses the garbage collected heap.
550550
*/
551551
nothrow @safe @nogc @property IAllocator theAllocator()
552552
{
553+
if (!_threadAllocator) setupThreadAllocator();
553554
return _threadAllocator;
554555
}
555556

0 commit comments

Comments
 (0)