From 2217723db4eb03c11f55dba9d29d1511c47ce784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 9 Feb 2024 09:54:43 +0100 Subject: [PATCH] Deprecate vibe.internal.utilallocator and forward to vibe.container's version. --- data/vibe/data/bson.d | 2 +- http/vibe/http/client.d | 6 +- http/vibe/http/common.d | 2 +- http/vibe/http/server.d | 4 +- inet/vibe/inet/message.d | 2 +- redis/vibe/db/redis/redis.d | 2 +- stream/vibe/stream/memory.d | 2 +- stream/vibe/stream/operations.d | 2 +- tls/vibe/stream/openssl.d | 2 +- utils/dub.sdl | 2 +- utils/vibe/internal/memory_legacy.d | 2 +- utils/vibe/internal/utilallocator.d | 183 +--------------------------- utils/vibe/utils/array.d | 2 +- utils/vibe/utils/string.d | 2 +- 14 files changed, 18 insertions(+), 197 deletions(-) diff --git a/data/vibe/data/bson.d b/data/vibe/data/bson.d index 7499beb825..243f794f3e 100644 --- a/data/vibe/data/bson.d +++ b/data/vibe/data/bson.d @@ -1601,7 +1601,7 @@ struct BsonSerializer { this(ubyte[] buffer) @safe { - import vibe.internal.utilallocator; + import vibe.container.internal.utilallocator; m_dst = () @trusted { return AllocAppender!(ubyte[])(vibeThreadAllocator(), buffer); } (); } diff --git a/http/vibe/http/client.d b/http/vibe/http/client.d index 5a0062c6eb..72941b173f 100644 --- a/http/vibe/http/client.d +++ b/http/vibe/http/client.d @@ -24,7 +24,7 @@ import vibe.stream.wrapper : createConnectionProxyStream; import vibe.stream.zlib; import vibe.utils.array; import vibe.utils.dictionarylist; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import vibe.internal.freelistref; import vibe.internal.interfaceproxy : InterfaceProxy, interfaceProxy; @@ -468,7 +468,7 @@ final class HTTPClient { private void doProxyRequest(T, U)(ref T res, U requester, ref bool close_conn, ref bool has_body) @trusted { // scope new import std.conv : to; - import vibe.internal.utilallocator: RegionListAllocator; + import vibe.container.internal.utilallocator: RegionListAllocator; version (VibeManualMemoryManagement) scope request_allocator = new RegionListAllocator!(shared(Mallocator), false)(1024, Mallocator.instance); else @@ -542,7 +542,7 @@ final class HTTPClient { */ void request(scope void delegate(scope HTTPClientRequest req) requester, scope void delegate(scope HTTPClientResponse) responder) @trusted { // scope new - import vibe.internal.utilallocator: RegionListAllocator; + import vibe.container.internal.utilallocator: RegionListAllocator; version (VibeManualMemoryManagement) scope request_allocator = new RegionListAllocator!(shared(Mallocator), false)(1024, Mallocator.instance); else diff --git a/http/vibe/http/common.d b/http/vibe/http/common.d index e9d368eb58..037a15b3d0 100644 --- a/http/vibe/http/common.d +++ b/http/vibe/http/common.d @@ -16,7 +16,7 @@ import vibe.stream.operations; import vibe.textfilter.urlencode : urlEncode, urlDecode; import vibe.utils.array; import vibe.utils.dictionarylist; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import vibe.internal.freelistref; import vibe.internal.interfaceproxy : InterfaceProxy, interfaceProxy; import vibe.utils.string; diff --git a/http/vibe/http/server.d b/http/vibe/http/server.d index 3a1482aeee..f911904111 100644 --- a/http/vibe/http/server.d +++ b/http/vibe/http/server.d @@ -27,7 +27,7 @@ import vibe.stream.wrapper : ConnectionProxyStream, createConnectionProxyStream, import vibe.stream.zlib; import vibe.textfilter.urlencode; import vibe.utils.array; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import vibe.internal.freelistref; import vibe.utils.string; @@ -243,7 +243,7 @@ void handleHTTPConnection(TCPConnection connection, HTTPServerContext context) } () @trusted { - import vibe.internal.utilallocator: RegionListAllocator; + import vibe.container.internal.utilallocator: RegionListAllocator; version (VibeManualMemoryManagement) scope request_allocator = new RegionListAllocator!(shared(Mallocator), false)(1024, Mallocator.instance); diff --git a/inet/vibe/inet/message.d b/inet/vibe/inet/message.d index c9bd6a29f9..842d3a5d29 100644 --- a/inet/vibe/inet/message.d +++ b/inet/vibe/inet/message.d @@ -11,7 +11,7 @@ import vibe.core.log; import vibe.core.stream; import vibe.stream.operations; import vibe.utils.array; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import vibe.utils.string; import vibe.utils.dictionarylist; diff --git a/redis/vibe/db/redis/redis.d b/redis/vibe/db/redis/redis.d index 5a6045e8a8..a1f977d48c 100644 --- a/redis/vibe/db/redis/redis.d +++ b/redis/vibe/db/redis/redis.d @@ -13,7 +13,7 @@ import vibe.core.connectionpool; import vibe.core.core; import vibe.core.log; import vibe.inet.url; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import vibe.internal.freelistref; import vibe.stream.operations; import std.conv; diff --git a/stream/vibe/stream/memory.d b/stream/vibe/stream/memory.d index 3a61d23954..4f4463ab2e 100644 --- a/stream/vibe/stream/memory.d +++ b/stream/vibe/stream/memory.d @@ -9,7 +9,7 @@ module vibe.stream.memory; import vibe.core.stream; import vibe.utils.array; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import std.algorithm; import std.array; diff --git a/stream/vibe/stream/operations.d b/stream/vibe/stream/operations.d index cb72dc88db..9982a8ece4 100644 --- a/stream/vibe/stream/operations.d +++ b/stream/vibe/stream/operations.d @@ -11,7 +11,7 @@ public import vibe.core.stream; import vibe.core.log; import vibe.utils.array : AllocAppender; -import vibe.internal.allocator; +import vibe.container.internal.utilallocator; import vibe.internal.freelistref; import vibe.stream.wrapper : ProxyStream; diff --git a/tls/vibe/stream/openssl.d b/tls/vibe/stream/openssl.d index 8fb57616f3..2d2f6dcdcc 100644 --- a/tls/vibe/stream/openssl.d +++ b/tls/vibe/stream/openssl.d @@ -623,7 +623,7 @@ final class OpenSSLStream : TLSStream { private void setClientALPN(string[] alpn_list) { logDebug("SetClientALPN: ", alpn_list); - import vibe.internal.allocator : dispose, makeArray, vibeThreadAllocator; + import vibe.container.internal.utilallocator : dispose, makeArray, vibeThreadAllocator; ubyte[] alpn; size_t len; foreach (string alpn_val; alpn_list) diff --git a/utils/dub.sdl b/utils/dub.sdl index ebf11349df..fb48a9d7fd 100644 --- a/utils/dub.sdl +++ b/utils/dub.sdl @@ -3,4 +3,4 @@ description "Low level utility functionality" targetType "library" sourcePaths "." importPaths "." -dependency "vibe-container" version="~>1.0" +dependency "vibe-container" version=">=1.0.2 <2.0.0-0" diff --git a/utils/vibe/internal/memory_legacy.d b/utils/vibe/internal/memory_legacy.d index 782db683c1..348d775962 100644 --- a/utils/vibe/internal/memory_legacy.d +++ b/utils/vibe/internal/memory_legacy.d @@ -181,7 +181,7 @@ final class DebugAllocator : Allocator { this(Allocator base_allocator) nothrow @safe { - import vibe.internal.utilallocator : Mallocator, allocatorObject; + import vibe.container.internal.utilallocator : Mallocator, allocatorObject; m_baseAlloc = base_allocator; m_blocks = HashMap!(void*, size_t)(() @trusted { return Mallocator.instance.allocatorObject; } ()); } diff --git a/utils/vibe/internal/utilallocator.d b/utils/vibe/internal/utilallocator.d index 4d804356ae..b8e5ca5e80 100644 --- a/utils/vibe/internal/utilallocator.d +++ b/utils/vibe/internal/utilallocator.d @@ -1,183 +1,4 @@ +deprecated("Import vibe.container.internal.utilallocator instead") module vibe.internal.utilallocator; -public import stdx.allocator : allocatorObject, CAllocatorImpl, dispose, - expandArray, IAllocator, make, makeArray, shrinkArray, theAllocator; -public import stdx.allocator.mallocator; -public import stdx.allocator.building_blocks.affix_allocator; - -// NOTE: this needs to be used instead of theAllocator due to Phobos issue 17564 -@property IAllocator vibeThreadAllocator() -@safe nothrow @nogc { - import stdx.allocator.gc_allocator; - static IAllocator s_threadAllocator; - if (!s_threadAllocator) - s_threadAllocator = () @trusted { return allocatorObject(GCAllocator.instance); } (); - return s_threadAllocator; -} - -final class RegionListAllocator(Allocator, bool leak = false) : IAllocator { - import vibe.internal.memory_legacy : AllocSize, alignedSize; - import std.algorithm.comparison : min, max; - import std.conv : emplace; - - import std.typecons : Ternary; - - static struct Pool { Pool* next; void[] data; void[] remaining; } - private { - Allocator m_baseAllocator; - Pool* m_freePools; - Pool* m_fullPools; - size_t m_poolSize; - } - - this(size_t pool_size, Allocator base) @safe nothrow - { - m_poolSize = pool_size; - m_baseAllocator = base; - } - - ~this() - { - deallocateAll(); - } - - override @property uint alignment() const { return 0x10; } - - @property size_t totalSize() - @safe nothrow @nogc { - size_t amt = 0; - for (auto p = m_fullPools; p; p = p.next) - amt += p.data.length; - for (auto p = m_freePools; p; p = p.next) - amt += p.data.length; - return amt; - } - - @property size_t allocatedSize() - @safe nothrow @nogc { - size_t amt = 0; - for (auto p = m_fullPools; p; p = p.next) - amt += p.data.length; - for (auto p = m_freePools; p; p = p.next) - amt += p.data.length - p.remaining.length; - return amt; - } - - override void[] allocate(size_t sz, TypeInfo ti = null) - { - auto aligned_sz = alignedSize(sz); - - Pool* pprev = null; - Pool* p = cast(Pool*)m_freePools; - while( p && p.remaining.length < aligned_sz ){ - pprev = p; - p = p.next; - } - - if( !p ){ - auto pmem = m_baseAllocator.allocate(AllocSize!Pool); - - p = emplace!Pool(cast(Pool*)pmem.ptr); - p.data = m_baseAllocator.allocate(max(aligned_sz, m_poolSize)); - p.remaining = p.data; - p.next = cast(Pool*)m_freePools; - m_freePools = p; - pprev = null; - } - - auto ret = p.remaining[0 .. aligned_sz]; - p.remaining = p.remaining[aligned_sz .. $]; - if( !p.remaining.length ){ - if( pprev ){ - pprev.next = p.next; - } else { - m_freePools = p.next; - } - p.next = cast(Pool*)m_fullPools; - m_fullPools = p; - } - - return ret[0 .. sz]; - } - - override void[] alignedAllocate(size_t n, uint a) { return null; } - override bool alignedReallocate(ref void[] b, size_t size, uint alignment) { return false; } - override void[] allocateAll() { return null; } - override @property Ternary empty() const { return m_fullPools !is null ? Ternary.no : Ternary.yes; } - override size_t goodAllocSize(size_t s) { return alignedSize(s); } - - import std.traits : Parameters; - static if (is(Parameters!(IAllocator.resolveInternalPointer)[0] == const(void*))) { - override Ternary resolveInternalPointer(const void* p, ref void[] result) { return Ternary.unknown; } - } else { - override Ternary resolveInternalPointer(void* p, ref void[] result) { return Ternary.unknown; } - } - static if (is(Parameters!(IAllocator.owns)[0] == const(void[]))) { - override Ternary owns(const void[] b) { return Ternary.unknown; } - } else { - override Ternary owns(void[] b) { return Ternary.unknown; } - } - - - override bool reallocate(ref void[] arr, size_t newsize) - { - return expand(arr, newsize); - } - - override bool expand(ref void[] arr, size_t newsize) - { - auto aligned_sz = alignedSize(arr.length); - auto aligned_newsz = alignedSize(newsize); - - if (aligned_newsz <= aligned_sz) { - arr = arr[0 .. newsize]; // TODO: back up remaining - return true; - } - - auto pool = m_freePools; - bool last_in_pool = pool && arr.ptr+aligned_sz == pool.remaining.ptr; - if (last_in_pool && pool.remaining.length+aligned_sz >= aligned_newsz) { - pool.remaining = pool.remaining[aligned_newsz-aligned_sz .. $]; - arr = arr.ptr[0 .. aligned_newsz]; - assert(arr.ptr+arr.length == pool.remaining.ptr, "Last block does not align with the remaining space!?"); - arr = arr[0 .. newsize]; - } else { - auto ret = allocate(newsize); - assert(ret.ptr >= arr.ptr+aligned_sz || ret.ptr+ret.length <= arr.ptr, "New block overlaps old one!?"); - ret[0 .. min(arr.length, newsize)] = arr[0 .. min(arr.length, newsize)]; - arr = ret; - } - return true; - } - - override bool deallocate(void[] mem) - { - return false; - } - - override bool deallocateAll() - { - // put all full Pools into the free pools list - for (Pool* p = cast(Pool*)m_fullPools, pnext; p; p = pnext) { - pnext = p.next; - p.next = cast(Pool*)m_freePools; - m_freePools = cast(Pool*)p; - } - - // free up all pools - for (Pool* p = cast(Pool*)m_freePools; p; p = p.next) - p.remaining = p.data; - - Pool* pnext; - for (auto p = cast(Pool*)m_freePools; p; p = pnext) { - pnext = p.next; - static if (!leak) { - m_baseAllocator.deallocate(p.data); - m_baseAllocator.deallocate((cast(void*)p)[0 .. AllocSize!Pool]); - } - } - m_freePools = null; - - return true; - } -} +public import vibe.container.internal.utilallocator; diff --git a/utils/vibe/utils/array.d b/utils/vibe/utils/array.d index 34d6e7b235..999abbaadb 100644 --- a/utils/vibe/utils/array.d +++ b/utils/vibe/utils/array.d @@ -7,7 +7,7 @@ */ module vibe.utils.array; -import vibe.internal.utilallocator; +import vibe.container.internal.utilallocator; import std.algorithm; import std.range : isInputRange, isOutputRange; diff --git a/utils/vibe/utils/string.d b/utils/vibe/utils/string.d index aaf0de3713..482673bd74 100644 --- a/utils/vibe/utils/string.d +++ b/utils/vibe/utils/string.d @@ -10,7 +10,7 @@ module vibe.utils.string; public import std.string; import vibe.utils.array; -import vibe.internal.utilallocator; +import vibe.container.internal.utilallocator; import std.algorithm; import std.array;