@@ -111,18 +111,21 @@ struct KRRegion(ParentAllocator = NullAllocator)
111
111
112
112
this (this ) @disable ;
113
113
114
+ pure nothrow @trusted @nogc
114
115
void [] payload () inout
115
116
{
116
117
return (cast (ubyte * ) &this )[0 .. size];
117
118
}
118
119
120
+ pure nothrow @trusted @nogc
119
121
bool adjacent (in Node* right) const
120
122
{
121
123
assert (right);
122
124
auto p = payload;
123
125
return p.ptr < right && right < p.ptr + p.length + Node.sizeof;
124
126
}
125
127
128
+ pure nothrow @trusted @nogc
126
129
bool coalesce (void * memoryEnd = null )
127
130
{
128
131
// Coalesce the last node before the memory end with any possible gap
@@ -139,6 +142,7 @@ struct KRRegion(ParentAllocator = NullAllocator)
139
142
return true ;
140
143
}
141
144
145
+ @safe
142
146
Tuple ! (void [], Node* ) allocateHere(size_t bytes)
143
147
{
144
148
assert (bytes >= Node.sizeof);
@@ -152,7 +156,7 @@ struct KRRegion(ParentAllocator = NullAllocator)
152
156
if (leftover >= Node.sizeof)
153
157
{
154
158
// There's room for another node
155
- auto newNode = cast (Node* ) ((cast (ubyte * ) &this ) + bytes);
159
+ auto newNode = (() @trusted => cast (Node* ) ((cast (ubyte * ) &this ) + bytes))( );
156
160
newNode.size = leftover;
157
161
newNode.next = next == &this ? newNode : next;
158
162
assert (next);
@@ -396,6 +400,7 @@ struct KRRegion(ParentAllocator = NullAllocator)
396
400
397
401
Returns: A word-aligned buffer of `n` bytes, or `null`.
398
402
*/
403
+ @safe
399
404
void [] allocate (size_t n)
400
405
{
401
406
if (! n || ! root) return null ;
@@ -413,7 +418,7 @@ struct KRRegion(ParentAllocator = NullAllocator)
413
418
immutable balance = root.size - actualBytes;
414
419
if (balance >= Node.sizeof)
415
420
{
416
- auto newRoot = cast (Node* ) (result + actualBytes);
421
+ auto newRoot = (() @trusted => cast (Node* ) (result + actualBytes))( );
417
422
newRoot.next = root.next;
418
423
newRoot.size = balance;
419
424
root = newRoot;
@@ -423,7 +428,7 @@ struct KRRegion(ParentAllocator = NullAllocator)
423
428
root = null ;
424
429
switchToFreeList;
425
430
}
426
- return result[0 .. n];
431
+ return (() @trusted => result[0 .. n])() ;
427
432
}
428
433
429
434
// Not enough memory, switch to freelist mode and fall through
@@ -754,7 +759,7 @@ version (StdUnittest)
754
759
n => KRRegion! GCAllocator(max(n * 16 , 1024 * 1024 )))());
755
760
}
756
761
757
- @system unittest
762
+ @safe unittest
758
763
{
759
764
import std.experimental.allocator.gc_allocator : GCAllocator;
760
765
@@ -763,7 +768,7 @@ version (StdUnittest)
763
768
void [][] array;
764
769
foreach (i; 1 .. 4 )
765
770
{
766
- array ~= alloc.allocate(i);
771
+ array ~= (() nothrow @safe => alloc.allocate(i))( );
767
772
assert (array[$ - 1 ].length == i);
768
773
}
769
774
() nothrow @nogc { alloc.deallocate(array[1 ]); }();
@@ -778,7 +783,7 @@ version (StdUnittest)
778
783
import std.typecons : Ternary;
779
784
auto alloc = KRRegion! ()(
780
785
cast (ubyte [])(GCAllocator.instance.allocate(1024 * 1024 )));
781
- const store = alloc.allocate(KRRegion! ().sizeof);
786
+ const store = (() pure nothrow @safe @nogc => alloc.allocate(KRRegion! ().sizeof))( );
782
787
auto p = cast (KRRegion! ()* ) store.ptr;
783
788
import core.lifetime : emplace;
784
789
import core.stdc.string : memcpy;
@@ -791,7 +796,7 @@ version (StdUnittest)
791
796
foreach (i; 0 .. array.length)
792
797
{
793
798
auto length = 100 * i + 1 ;
794
- array[i] = p.allocate(length);
799
+ array[i] = (() pure nothrow @safe @nogc => p.allocate(length))( );
795
800
assert (array[i].length == length, text(array[i].length));
796
801
assert ((() pure nothrow @safe @nogc => p.owns(array[i]))() == Ternary.yes);
797
802
}
@@ -820,7 +825,7 @@ version (StdUnittest)
820
825
assert (p.length == 1024 * 1024 );
821
826
}
822
827
823
- @system unittest
828
+ @safe unittest
824
829
{
825
830
import std.random : randomCover;
826
831
import std.typecons : Ternary;
@@ -846,7 +851,7 @@ version (StdUnittest)
846
851
847
852
foreach (size; sizes)
848
853
{
849
- bufs ~= a.allocate(size);
854
+ bufs ~= (() pure nothrow @safe @nogc => a.allocate(size))( );
850
855
}
851
856
852
857
foreach (b; bufs.randomCover)
@@ -861,7 +866,7 @@ version (StdUnittest)
861
866
test(sizes32);
862
867
}
863
868
864
- @system unittest
869
+ @safe unittest
865
870
{
866
871
import std.typecons : Ternary;
867
872
@@ -886,11 +891,11 @@ version (StdUnittest)
886
891
887
892
foreach (size; sizes)
888
893
{
889
- bufs ~= a.allocate(size);
894
+ bufs ~= (() pure nothrow @safe @nogc => a.allocate(size))( );
890
895
}
891
896
892
897
() nothrow @nogc { a.deallocate(bufs[1 ]); }();
893
- bufs ~= a.allocate(sizes[1 ] - word);
898
+ bufs ~= (() pure nothrow @safe @nogc => a.allocate(sizes[1 ] - word))( );
894
899
895
900
() nothrow @nogc { a.deallocate(bufs[0 ]); }();
896
901
foreach (i; 2 .. bufs.length)
0 commit comments