Allow building with GDC 10.3

This commit is contained in:
2021-05-26 10:29:03 +02:00
parent 938a1bb5b4
commit 4f48544297
10 changed files with 213 additions and 66 deletions

View File

@ -101,7 +101,11 @@ mixin template DefaultAllocator()
* Precondition: $(D_INLINECODE allocator_ !is null)
*/
this(shared Allocator allocator) @nogc nothrow pure @safe
in (allocator !is null)
in
{
assert(allocator !is null);
}
do
{
this.allocator_ = allocator;
}
@ -115,7 +119,11 @@ mixin template DefaultAllocator()
* Postcondition: $(D_INLINECODE allocator !is null)
*/
@property shared(Allocator) allocator() @nogc nothrow pure @safe
out (allocator; allocator !is null)
out (allocator)
{
assert(allocator !is null);
}
do
{
if (allocator_ is null)
{
@ -126,7 +134,11 @@ mixin template DefaultAllocator()
/// ditto
@property shared(Allocator) allocator() const @nogc nothrow pure @trusted
out (allocator; allocator !is null)
out (allocator)
{
assert(allocator !is null);
}
do
{
if (allocator_ is null)
{
@ -162,7 +174,11 @@ private shared(Allocator) getAllocatorInstance() @nogc nothrow
* Postcondition: $(D_INLINECODE allocator !is null).
*/
@property shared(Allocator) defaultAllocator() @nogc nothrow pure @trusted
out (allocator; allocator !is null)
out (allocator)
{
assert(allocator !is null);
}
do
{
return (cast(GetPureInstance!Allocator) &getAllocatorInstance)();
}
@ -176,7 +192,11 @@ out (allocator; allocator !is null)
* Precondition: $(D_INLINECODE allocator !is null).
*/
@property void defaultAllocator(shared(Allocator) allocator) @nogc nothrow @safe
in (allocator !is null)
in
{
assert(allocator !is null);
}
do
{
.allocator = allocator;
}
@ -258,7 +278,11 @@ void dispose(T)(shared Allocator allocator, auto ref T p)
*/
T make(T, A...)(shared Allocator allocator, auto ref A args)
if (is(T == class))
in (allocator !is null)
in
{
assert(allocator !is null);
}
do
{
auto mem = (() @trusted => allocator.allocate(stateSize!T))();
if (mem is null)
@ -290,7 +314,11 @@ in (allocator !is null)
*/
T* make(T, A...)(shared Allocator allocator, auto ref A args)
if (!isPolymorphicType!T && !isAssociativeArray!T && !isArray!T)
in (allocator !is null)
in
{
assert(allocator !is null);
}
do
{
auto mem = (() @trusted => allocator.allocate(stateSize!T))();
if (mem is null)
@ -327,8 +355,12 @@ in (allocator !is null)
* && n <= size_t.max / E.sizeof)
*/
T make(T : E[], E)(shared Allocator allocator, size_t n)
in (allocator !is null)
in (n <= size_t.max / E.sizeof)
in
{
assert(allocator !is null);
assert(n <= size_t.max / E.sizeof);
}
do
{
auto ret = allocator.resize!E(null, n);

View File

@ -61,8 +61,15 @@ package(tanya) void destroyAllImpl(R, E)(R p)
*/
T emplace(T, U, Args...)(void[] memory, U outer, auto ref Args args)
if (!isAbstractClass!T && isInnerClass!T && is(typeof(T.outer) == U))
in (memory.length >= stateSize!T)
out (result; memory.ptr is (() @trusted => cast(void*) result)())
in
{
assert(memory.length >= stateSize!T);
}
out (result)
{
assert(memory.ptr is (() @trusted => cast(void*) result)());
}
do
{
import tanya.memory.op : copy;
@ -82,8 +89,15 @@ out (result; memory.ptr is (() @trusted => cast(void*) result)())
/// ditto
T emplace(T, Args...)(void[] memory, auto ref Args args)
if (is(T == class) && !isAbstractClass!T && !isInnerClass!T)
in (memory.length == stateSize!T)
out (result; memory.ptr is (() @trusted => cast(void*) result)())
in
{
assert(memory.length == stateSize!T);
}
out (result)
{
assert(memory.ptr is (() @trusted => cast(void*) result)());
}
do
{
import tanya.memory.op : copy;
@ -128,8 +142,15 @@ out (result; memory.ptr is (() @trusted => cast(void*) result)())
/// ditto
T* emplace(T, Args...)(void[] memory, auto ref Args args)
if (!isAggregateType!T && (Args.length <= 1))
in (memory.length >= T.sizeof)
out (result; memory.ptr is result)
in
{
assert(memory.length >= T.sizeof);
}
out (result)
{
assert(memory.ptr is result);
}
do
{
auto result = (() @trusted => cast(T*) memory.ptr)();
static if (Args.length == 1)
@ -166,8 +187,15 @@ private void initializeOne(T)(ref void[] memory, ref T* result) @trusted
/// ditto
T* emplace(T, Args...)(void[] memory, auto ref Args args)
if (!isPolymorphicType!T && isAggregateType!T)
in (memory.length >= T.sizeof)
out (result; memory.ptr is result)
in
{
assert(memory.length >= T.sizeof);
}
out (result)
{
assert(memory.ptr is result);
}
do
{
auto result = (() @trusted => cast(T*) memory.ptr)();
@ -291,7 +319,11 @@ private void deinitialize(bool zero, T)(ref T value)
* Precondition: `&source !is &target`.
*/
void moveEmplace(T)(ref T source, ref T target) @system
in (&source !is &target, "Source and target must be different")
in
{
assert(&source !is &target, "Source and target must be different");
}
do
{
static if (is(T == struct) || isStaticArray!T)
{

View File

@ -36,9 +36,13 @@ private enum alignMask = size_t.sizeof - 1;
* Precondition: $(D_INLINECODE source.length <= target.length).
*/
void copy(const void[] source, void[] target) @nogc nothrow pure @trusted
in (source.length <= target.length)
in (source.length == 0 || source.ptr !is null)
in (target.length == 0 || target.ptr !is null)
in
{
assert(source.length <= target.length);
assert(source.length == 0 || source.ptr !is null);
assert(target.length == 0 || target.ptr !is null);
}
do
{
memcpy(target.ptr, source.ptr, source.length);
}
@ -75,7 +79,11 @@ private template filledBytes(ubyte Byte, ubyte I = 0)
* memory = Memory block.
*/
void fill(ubyte c = 0)(void[] memory) @trusted
in (memory.length == 0 || memory.ptr !is null)
in
{
assert(memory.length == 0 || memory.ptr !is null);
}
do
{
memset(memory.ptr, c, memory.length);
}
@ -114,9 +122,13 @@ in (memory.length == 0 || memory.ptr !is null)
* Precondition: $(D_INLINECODE source.length <= target.length).
*/
void copyBackward(const void[] source, void[] target) @nogc nothrow pure @trusted
in (source.length <= target.length)
in (source.length == 0 || source.ptr !is null)
in (target.length == 0 || target.ptr !is null)
in
{
assert(source.length <= target.length);
assert(source.length == 0 || source.ptr !is null);
assert(target.length == 0 || target.ptr !is null);
}
do
{
memmove(target.ptr, source.ptr, source.length);
}
@ -145,7 +157,11 @@ in (target.length == 0 || target.ptr !is null)
*/
inout(void[]) find(return inout void[] haystack, ubyte needle)
@nogc nothrow pure @trusted
in (haystack.length == 0 || haystack.ptr !is null)
in
{
assert(haystack.length == 0 || haystack.ptr !is null);
}
do
{
auto length = haystack.length;
const size_t needleWord = size_t.max * needle;
@ -223,7 +239,11 @@ in (haystack.length == 0 || haystack.ptr !is null)
*/
inout(char[]) findNullTerminated(return inout char[] haystack)
@nogc nothrow pure @trusted
in (haystack.length == 0 || haystack.ptr !is null)
in
{
assert(haystack.length == 0 || haystack.ptr !is null);
}
do
{
auto length = haystack.length;
enum size_t highBits = filledBytes!(0x01, 0);
@ -290,8 +310,12 @@ in (haystack.length == 0 || haystack.ptr !is null)
* $(D_KEYWORD false) otherwise.
*/
bool equal(const void[] r1, const void[] r2) @nogc nothrow pure @trusted
in (r1.length == 0 || r1.ptr !is null)
in (r2.length == 0 || r2.ptr !is null)
in
{
assert(r1.length == 0 || r1.ptr !is null);
assert(r2.length == 0 || r2.ptr !is null);
}
do
{
return r1.length == r2.length && memcmp(r1.ptr, r2.ptr, r1.length) == 0;
}

View File

@ -46,7 +46,11 @@ private final class RefCountedStore(T)
size_t opUnary(string op)()
if (op == "--" || op == "++")
in (this.counter > 0)
in
{
assert(this.counter > 0);
}
do
{
mixin("return " ~ op ~ "counter;");
}
@ -127,7 +131,11 @@ struct RefCounted(T)
/// ditto
this(shared Allocator allocator)
in (allocator !is null)
in
{
assert(allocator !is null);
}
do
{
this.allocator_ = allocator;
}
@ -231,7 +239,11 @@ struct RefCounted(T)
* Precondition: $(D_INLINECODE cound > 0).
*/
inout(Payload!T) get() inout
in (count > 0, "Attempted to access an uninitialized reference")
in
{
assert(count > 0, "Attempted to access an uninitialized reference");
}
do
{
return this.storage.payload;
}
@ -321,7 +333,11 @@ struct RefCounted(T)
RefCounted!T refCounted(T, A...)(shared Allocator allocator, auto ref A args)
if (!is(T == interface) && !isAbstractClass!T
&& !isAssociativeArray!T && !isArray!T)
in (allocator !is null)
in
{
assert(allocator !is null);
}
do
{
auto rc = typeof(return)(allocator);
@ -361,8 +377,12 @@ in (allocator !is null)
*/
RefCounted!T refCounted(T : E[], E)(shared Allocator allocator, size_t size)
@trusted
in (allocator !is null)
in (size <= size_t.max / E.sizeof)
in
{
assert(allocator !is null);
assert(size <= size_t.max / E.sizeof);
}
do
{
return RefCounted!T(allocator.make!T(size), allocator);
}
@ -423,7 +443,11 @@ struct Unique(T)
/// ditto
this(shared Allocator allocator)
in (allocator !is null)
in
{
assert(allocator !is null);
}
do
{
this.allocator_ = allocator;
}
@ -604,7 +628,11 @@ struct Unique(T)
Unique!T unique(T, A...)(shared Allocator allocator, auto ref A args)
if (!is(T == interface) && !isAbstractClass!T
&& !isAssociativeArray!T && !isArray!T)
in (allocator !is null)
in
{
assert(allocator !is null);
}
do
{
auto payload = allocator.make!(T, A)(args);
return Unique!T(payload, allocator);
@ -627,8 +655,12 @@ in (allocator !is null)
*/
Unique!T unique(T : E[], E)(shared Allocator allocator, size_t size)
@trusted
in (allocator !is null)
in (size <= size_t.max / E.sizeof)
in
{
assert(allocator !is null);
assert(size <= size_t.max / E.sizeof);
}
do
{
auto payload = allocator.resize!E(null, size);
return Unique!T(payload, allocator);