diff options
| author | Eugen Wissner <belka@caraus.de> | 2017-01-12 19:31:49 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2017-01-12 19:47:07 +0100 |
| commit | 4c4e65b3739ca30b587eb20d4fcea3abb5e1550b (patch) | |
| tree | 2341b701e05b0946d665cde7678bab7f02ba741c | |
| parent | 7bed7f039fda3ae635e1d4c3a7acd7076887531d (diff) | |
| download | tanya-4c4e65b3739ca30b587eb20d4fcea3abb5e1550b.tar.gz | |
MmapPool: (p[] is null) != (p[].ptr is null)
| -rw-r--r-- | source/tanya/memory/mmappool.d | 2 | ||||
| -rw-r--r-- | source/tanya/memory/package.d | 25 |
2 files changed, 19 insertions, 8 deletions
diff --git a/source/tanya/memory/mmappool.d b/source/tanya/memory/mmappool.d index eac7418..a363219 100644 --- a/source/tanya/memory/mmappool.d +++ b/source/tanya/memory/mmappool.d @@ -156,7 +156,7 @@ final class MmapPool : Allocator */ bool deallocate(void[] p) shared nothrow @nogc { - if (p is null) + if (p.ptr is null) { return true; } diff --git a/source/tanya/memory/package.d b/source/tanya/memory/package.d index 60a45a6..3979fe0 100644 --- a/source/tanya/memory/package.d +++ b/source/tanya/memory/package.d @@ -220,15 +220,26 @@ void dispose(T)(shared Allocator allocator, auto ref T p) } /// Ditto. -void dispose(T)(shared Allocator allocator, auto ref T[] array) +void dispose(T)(shared Allocator allocator, auto ref T[] p) { - static if (hasElaborateDestructor!(typeof(array[0]))) + static if (hasElaborateDestructor!(typeof(p[0]))) { - foreach (ref e; array) - { - destroy(e); + import std.algorithm.iteration; + p.each!(e => destroy(e)); } + () @trusted { allocator.deallocate(p); }(); + p = null; +} + +unittest +{ + struct S + { + ~this() + { + } } - () @trusted { allocator.deallocate(array); }(); - array = null; + auto p = cast(S[]) defaultAllocator.allocate(S.sizeof); + + defaultAllocator.dispose(p); } |
