Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add safety on internal, cyclicbuffer and dynamicarray #130

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added emsi_containers.lib
Binary file not shown.
42 changes: 21 additions & 21 deletions src/containers/cyclicbuffer.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
}
}

~this()
~this() @trusted
{
clear();
static if (useGC)
Expand All @@ -62,7 +62,7 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
/**
* Removes all contents from the buffer.
*/
void clear()
void clear() @safe
{
if (!empty)
{
Expand All @@ -87,7 +87,7 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
/**
* Ensures capacity is at least as large as specified.
*/
size_t reserve(size_t newCapacity)
size_t reserve(size_t newCapacity) @trusted
{
immutable oldCapacity = capacity;
if (newCapacity <= oldCapacity)
Expand Down Expand Up @@ -156,7 +156,7 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
/**
* Inserts the given item into the start of the buffer.
*/
void insertFront(U)(U value) if (isImplicitlyConvertible!(U, T))
void insertFront(U)(U value) @safe if (isImplicitlyConvertible!(U, T))
{
if (empty)
reserve(4);
Expand All @@ -170,7 +170,7 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
/**
* Inserts the given item into the end of the buffer.
*/
void insertBack(U)(U value) if (isImplicitlyConvertible!(U, T))
void insertBack(U)(U value) @safe if (isImplicitlyConvertible!(U, T))
{
if (empty)
reserve(4);
Expand All @@ -193,7 +193,7 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
/**
* Removes the item at the start of the buffer.
*/
void removeFront()
void removeFront() @safe
{
version (assert) if (empty) onRangeError();
size_t pos = start;
Expand All @@ -209,7 +209,7 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
/**
* Removes the item at the end of the buffer.
*/
void removeBack()
void removeBack() @safe
{
version (assert) if (empty) onRangeError();
size_t pos = end;
Expand Down Expand Up @@ -457,7 +457,7 @@ version(emsi_containers_unittest) private
{
int* a;

~this()
~this() @safe
{
(*a)++;
}
Expand All @@ -467,19 +467,19 @@ version(emsi_containers_unittest) private
{
int* a;

this(int* a)
this(int* a) @safe
{
this.a = a;
}

~this()
~this() @safe
{
(*a)++;
}
}
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
static void test(int size)
{
Expand Down Expand Up @@ -599,7 +599,7 @@ version(emsi_containers_unittest) unittest
assert(*a == 0 || *a == 1);
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
CyclicBuffer!int b;
b.insertFront(10);
Expand All @@ -620,7 +620,7 @@ version(emsi_containers_unittest) unittest
assert(b[3] == 7);
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
import std.range : isInputRange, isForwardRange, isBidirectionalRange, isRandomAccessRange;
CyclicBuffer!int b;
Expand All @@ -630,7 +630,7 @@ version(emsi_containers_unittest) unittest
static assert(isRandomAccessRange!(typeof(b[])));
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
CyclicBuffer!int b;
assert(b[].empty);
Expand All @@ -645,7 +645,7 @@ version(emsi_containers_unittest) unittest
auto b3 = CyclicBuffer!(int, GCAllocator)();
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
static void testConst(const ref CyclicBuffer!int b, int x)
{
Expand Down Expand Up @@ -700,7 +700,7 @@ version(emsi_containers_unittest) unittest
assert(a == 10);
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
CyclicBuffer!int b;
foreach (i; 0 .. 4)
Expand All @@ -714,7 +714,7 @@ version(emsi_containers_unittest) unittest
assert(equal(b[], [2, 3, 4, 5]));
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
CyclicBuffer!int b;
foreach (i; 0 .. 4)
Expand All @@ -730,7 +730,7 @@ version(emsi_containers_unittest) unittest
assert(equal(b[], [3, 4, 5, 6]));
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
static void test(ref CyclicBuffer!int b)
{
Expand Down Expand Up @@ -784,7 +784,7 @@ version(emsi_containers_unittest) unittest
}
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
CyclicBuffer!int b;
foreach (i; 0 .. 10)
Expand All @@ -794,7 +794,7 @@ version(emsi_containers_unittest) unittest
assert(b.capacity >= 12);
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
CyclicBuffer!int b;
foreach (i; 0 .. 6)
Expand All @@ -806,7 +806,7 @@ version(emsi_containers_unittest) unittest
assert(equal(b[], [7, 6, 0, 1, 2, 3, 4, 5]));
}

version(emsi_containers_unittest) unittest
version(emsi_containers_unittest) @safe unittest
{
static class Foo
{
Expand Down
Loading