Skip to content

Commit

Permalink
Don't assume allocators can be compared to null (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow authored Apr 27, 2022
1 parent 31be25a commit 8e3fa3f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/containers/cyclicbuffer.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
this(Allocator allocator) nothrow pure @safe @nogc
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
do
{
Expand Down
9 changes: 8 additions & 1 deletion src/containers/dynamicarray.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
this(Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
do
{
Expand Down Expand Up @@ -719,3 +720,9 @@ version(emsi_containers_unittest) unittest
arr[1 .. 4] = [12, 13, 14];
assert(arr[] == [1, 12, 13, 14, 5]);
}

version(emsi_containers_unittest) unittest
{
import std.experimental.allocator : RCIAllocator;
auto a = DynamicArray!(int, RCIAllocator)(RCIAllocator.init);
}
9 changes: 6 additions & 3 deletions src/containers/hashmap.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ struct HashMap(K, V, Allocator = Mallocator, alias hashFunction = generateHash!K
this(Allocator allocator) pure nothrow @nogc @safe
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
do
{
Expand All @@ -55,7 +56,8 @@ struct HashMap(K, V, Allocator = Mallocator, alias hashFunction = generateHash!K
this(size_t bucketCount, Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
assert((bucketCount & (bucketCount - 1)) == 0, "bucketCount must be a power of two");
}
do
Expand All @@ -66,7 +68,8 @@ struct HashMap(K, V, Allocator = Mallocator, alias hashFunction = generateHash!K

invariant
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/containers/hashset.d
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ struct HashSet(T, Allocator = Mallocator, alias hashFunction = generateHash!T,
this(Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
do
{
Expand All @@ -53,7 +54,8 @@ struct HashSet(T, Allocator = Mallocator, alias hashFunction = generateHash!T,
this(size_t bucketCount, Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
assert ((bucketCount & (bucketCount - 1)) == 0, "bucketCount must be a power of two");
}
do
Expand Down
6 changes: 4 additions & 2 deletions src/containers/openhashset.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ struct OpenHashSet(T, Allocator = Mallocator,
this(Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
do
{
Expand All @@ -56,7 +57,8 @@ struct OpenHashSet(T, Allocator = Mallocator,
this(size_t initialCapacity, Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
assert ((initialCapacity & initialCapacity - 1) == 0, "initialCapacity must be a power of 2");
}
do
Expand Down
3 changes: 2 additions & 1 deletion src/containers/simdset.d
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ version (D_InlineAsm_X86_64) struct SimdSet(T, Allocator = Mallocator)
this(Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
do
{
Expand Down
3 changes: 2 additions & 1 deletion src/containers/slist.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct SList(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange!T)
this(Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
do
{
Expand Down
3 changes: 2 additions & 1 deletion src/containers/ttree.d
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ struct TTree(T, Allocator = Mallocator, bool allowDuplicates = false,
this(Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
do
{
Expand Down
3 changes: 2 additions & 1 deletion src/containers/unrolledlist.d
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ struct UnrolledList(T, Allocator = Mallocator,
this(Allocator allocator)
in
{
assert(allocator !is null, "Allocator must not be null");
static if (is(typeof(allocator is null)))
assert(allocator !is null, "Allocator must not be null");
}
do
{
Expand Down

0 comments on commit 8e3fa3f

Please sign in to comment.