From 58ee4a8839ba36b527460fc214916bb9c5759e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 28 Jun 2017 14:05:50 +0200 Subject: [PATCH] Use a thread local allocator instead of processAllocator in HashMap. This is required since processAllocator returns an ISharedAlloactor since 2.075.0. Because HashMap is operating only thread-local, this should generally be safe. --- source/vibe/internal/allocator.d | 9 +++++++++ source/vibe/internal/hashmap.d | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/source/vibe/internal/allocator.d b/source/vibe/internal/allocator.d index b8c181c..596b88f 100644 --- a/source/vibe/internal/allocator.d +++ b/source/vibe/internal/allocator.d @@ -7,3 +7,12 @@ public import std.experimental.allocator.building_blocks.region; public import std.experimental.allocator.building_blocks.stats_collector; public import std.experimental.allocator.gc_allocator; public import std.experimental.allocator.mallocator; + +// NOTE: this needs to be used instead of theAllocator due to Phobos issue 17564 +@property IAllocator vibeThreadAllocator() +@safe nothrow @nogc { + static IAllocator s_threadAllocator; + if (!s_threadAllocator) + s_threadAllocator = () @trusted { return allocatorObject(GCAllocator.instance); } (); + return s_threadAllocator; +} diff --git a/source/vibe/internal/hashmap.d b/source/vibe/internal/hashmap.d index 79ab093..dfabe46 100644 --- a/source/vibe/internal/hashmap.d +++ b/source/vibe/internal/hashmap.d @@ -219,7 +219,7 @@ struct HashMap(TKey, TValue, Traits = DefaultHashMapTraits!TKey) scope(exit) m_resizing = false; if (!m_allocator) { - try m_allocator = processAllocator(); + try m_allocator = vibeThreadAllocator(); catch (Exception e) assert(false, e.msg); }