From 48205b2fc92292329adb561cf439412b76ca462f Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 14 Jan 2017 21:48:21 +0100 Subject: [PATCH] MmapPool: Add invariant Add invariant to ensure blocks are linked correctly since this error appeared several times. --- source/tanya/memory/mmappool.d | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/tanya/memory/mmappool.d b/source/tanya/memory/mmappool.d index 804954b..2bc3cfe 100644 --- a/source/tanya/memory/mmappool.d +++ b/source/tanya/memory/mmappool.d @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** - * Copyright: Eugene Wissner 2016. + * Copyright: Eugene Wissner 2016-2017. * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * Mozilla Public License, v. 2.0). * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) @@ -50,6 +50,21 @@ else version (Windows) */ final class MmapPool : Allocator { + invariant + { + for (auto r = &head; *r !is null; r = &((*r).next)) + { + auto block = cast(Block) (cast(void*) *r + RegionEntry.sizeof); + do + { + assert(block.prev is null || block.prev.next is block); + assert(block.next is null || block.next.prev is block); + assert(block.region is *r); + } + while ((block = block.next) !is null); + } + } + /** * Allocates $(D_PARAM size) bytes of memory. *