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