diff --git a/dub.sdl b/dub.sdl index 4212ebc..e8c1cfd 100644 --- a/dub.sdl +++ b/dub.sdl @@ -5,7 +5,7 @@ copyright "Copyright © 2016-2020, Sönke Ludwig" license "MIT" dependency "eventcore" version="~>0.9.27" -dependency "vibe-container" version="~>1.0" +dependency "vibe-container" version=">=1.0.2 <2.0.0-0" targetName "vibe_core" diff --git a/source/vibe/core/channel.d b/source/vibe/core/channel.d index d909330..0ee29e4 100644 --- a/source/vibe/core/channel.d +++ b/source/vibe/core/channel.d @@ -155,7 +155,7 @@ struct Channel(T, size_t buffer_size = 100) { private final class ChannelImpl(T, size_t buffer_size) { import vibe.core.concurrency : isWeaklyIsolated; - import vibe.internal.allocator : Mallocator, makeGCSafe, disposeGCSafe; + import vibe.container.internal.utilallocator : Mallocator, makeGCSafe, disposeGCSafe; static assert(isWeaklyIsolated!T, "Channel data type "~T.stringof~" is not safe to pass between threads."); private { diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index 425bf6c..eafaddb 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -850,7 +850,7 @@ struct TCPConnection { if (isInputStream!InputStream) { import std.algorithm.comparison : min; - import vibe.internal.allocator : theAllocator, makeArray, dispose; + import vibe.container.internal.utilallocator : theAllocator, makeArray, dispose; scope buffer = () @trusted { return cast(ubyte[]) theAllocator.allocate(64*1024); }(); scope (exit) () @trusted { theAllocator.dispose(buffer); }(); diff --git a/source/vibe/core/process.d b/source/vibe/core/process.d index 660c46e..8f73dba 100644 --- a/source/vibe/core/process.d +++ b/source/vibe/core/process.d @@ -809,7 +809,7 @@ string collectOutput(InputStream)(InputStream stream, size_t nbytes = size_t.max output.reserve(nbytes); } - import vibe.internal.allocator : theAllocator, dispose; + import vibe.container.internal.utilallocator : theAllocator, dispose; scope buffer = cast(ubyte[]) theAllocator.allocate(64*1024); scope (exit) theAllocator.dispose(buffer); diff --git a/source/vibe/core/stream.d b/source/vibe/core/stream.d index 1e62b42..85c42c5 100644 --- a/source/vibe/core/stream.d +++ b/source/vibe/core/stream.d @@ -48,7 +48,7 @@ ulong pipe(InputStream, OutputStream)(scope InputStream source, scope OutputStre ulong nbytes, PipeConfig config) @blocking @trusted if (isOutputStream!OutputStream && isInputStream!InputStream) { - import vibe.internal.allocator : Mallocator, makeArray, dispose; + import vibe.container.internal.utilallocator : Mallocator, makeArray, dispose; import vibe.core.core : runTask; import vibe.core.sync : LocalManualEvent, createManualEvent; import vibe.core.task : InterruptException; diff --git a/source/vibe/core/sync.d b/source/vibe/core/sync.d index 4b82a8d..55a71f1 100644 --- a/source/vibe/core/sync.d +++ b/source/vibe/core/sync.d @@ -1141,7 +1141,7 @@ struct LocalManualEvent { private void initialize() nothrow { - import vibe.internal.allocator : Mallocator, makeGCSafe; + import vibe.container.internal.utilallocator : Mallocator, makeGCSafe; m_waiter = () @trusted { return Mallocator.instance.makeGCSafe!Waiter; } (); } @@ -1153,7 +1153,7 @@ struct LocalManualEvent { ~this() nothrow { - import vibe.internal.allocator : Mallocator, disposeGCSafe; + import vibe.container.internal.utilallocator : Mallocator, disposeGCSafe; if (m_waiter) { if (!m_waiter.releaseRef()) { static if (__VERSION__ < 2087) scope (failure) assert(false); diff --git a/source/vibe/internal/allocator.d b/source/vibe/internal/allocator.d index 692e8a4..414945b 100644 --- a/source/vibe/internal/allocator.d +++ b/source/vibe/internal/allocator.d @@ -1,63 +1,4 @@ +deprecated("Import `vibe.container.internal.utilallocator` instead.") module vibe.internal.allocator; -public import stdx.allocator; -public import stdx.allocator.building_blocks.allocator_list; -public import stdx.allocator.building_blocks.null_allocator; -public import stdx.allocator.building_blocks.region; -public import stdx.allocator.building_blocks.stats_collector; -public import stdx.allocator.gc_allocator; -public import stdx.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; -} - -auto makeGCSafe(T, Allocator, A...)(Allocator allocator, A args) -{ - import core.memory : GC; - import std.traits : hasIndirections; - - auto ret = allocator.make!T(args); - static if (is (T == class)) enum tsize = __traits(classInstanceSize, T); - else enum tsize = T.sizeof; - static if (hasIndirections!T) - () @trusted { GC.addRange(cast(void*)ret, tsize, typeid(T)); } (); - return ret; -} - -void disposeGCSafe(T, Allocator)(Allocator allocator, T obj) -{ - import core.memory : GC; - import std.traits : hasIndirections; - - static if (hasIndirections!T) - GC.removeRange(cast(void*)obj); - allocator.dispose(obj); -} - -void ensureNotInGC(T)(string info = null) nothrow -{ - import core.exception : InvalidMemoryOperationError; - try - { - import core.memory : GC; - cast(void) GC.malloc(1); - return; - } - catch(InvalidMemoryOperationError e) - { - import core.stdc.stdio : fprintf, stderr; - import core.stdc.stdlib : exit; - fprintf(stderr, - "Error: clean-up of %s incorrectly depends on destructors called by the GC.\n", - T.stringof.ptr); - if (info) - fprintf(stderr, "Info: %s\n", info.ptr); - assert(false); - } -} +public import vibe.container.internal.utilallocator; diff --git a/source/vibe/internal/array.d b/source/vibe/internal/array.d index 92428eb..14e9481 100644 --- a/source/vibe/internal/array.d +++ b/source/vibe/internal/array.d @@ -7,7 +7,7 @@ */ module vibe.internal.array; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import std.algorithm; import std.range : isInputRange, isOutputRange; diff --git a/source/vibe/internal/freelistref.d b/source/vibe/internal/freelistref.d index 1d2c985..09a9fcb 100644 --- a/source/vibe/internal/freelistref.d +++ b/source/vibe/internal/freelistref.d @@ -10,7 +10,7 @@ */ module vibe.internal.freelistref; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import vibe.internal.traits : synchronizedIsNothrow; import core.exception : OutOfMemoryError; diff --git a/source/vibe/internal/interfaceproxy.d b/source/vibe/internal/interfaceproxy.d index 7933743..7425863 100644 --- a/source/vibe/internal/interfaceproxy.d +++ b/source/vibe/internal/interfaceproxy.d @@ -2,7 +2,7 @@ module vibe.internal.interfaceproxy; import vibe.internal.traits; import vibe.internal.freelistref; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import std.algorithm.mutation : move, swap; import std.meta : staticMap; import std.traits : BaseTypeTuple; diff --git a/source/vibe/internal/string.d b/source/vibe/internal/string.d index 7d23aef..9ec6ac5 100644 --- a/source/vibe/internal/string.d +++ b/source/vibe/internal/string.d @@ -10,7 +10,7 @@ module vibe.internal.string; public import std.string; import vibe.internal.array; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import std.algorithm; import std.array;