Skip to content

Commit

Permalink
Add compatibility fixes for DMD < 2.074.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed May 8, 2017
1 parent 15232db commit 515d43b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions utils/vibe/utils/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,21 @@ struct ArraySet(Key)
import std.experimental.allocator.building_blocks.affix_allocator : AffixAllocator;

private {
static if (__VERSION__ < 2074) {
struct AW { // work around AffixAllocator limitations
IAllocator alloc;
alias alloc this;
enum alignment = max(Key.alignof, int.alignof);
void[] resolveInternalPointer(void* p) { void[] ret; alloc.resolveInternalPointer(p, ret); return ret; }
}
alias AllocatorType = AffixAllocator!(AW, int);
} else {
alias AW = IAllocator;
alias AllocatorType = AffixAllocator!(IAllocator, int);
}
Key[4] m_staticEntries;
Key[] m_entries;
AffixAllocator!(IAllocator, int) m_allocator;
AllocatorType m_allocator;
}

~this()
Expand Down Expand Up @@ -620,7 +632,7 @@ struct ArraySet(Key)
void setAllocator(IAllocator allocator)
in { assert(m_entries.ptr is null, "Cannot set allocator after elements have been inserted."); }
body {
m_allocator = AffixAllocator!(IAllocator, int)(allocator);
m_allocator = AllocatorType(AW(allocator));
}

bool opBinaryRight(string op)(Key key) if (op == "in") { return contains(key); }
Expand Down Expand Up @@ -690,9 +702,11 @@ struct ArraySet(Key)
ref allocator()
nothrow @trusted {
try {
if (!m_allocator._parent) {
static if (__VERSION__ < 2074) auto palloc = m_allocator.parent;
else auto palloc = m_allocator._parent;
if (!palloc) {
assert(processAllocator !is null, "No theAllocator set!?");
m_allocator = AffixAllocator!(IAllocator, int)(processAllocator);
m_allocator = AllocatorType(AW(processAllocator));
}
} catch (Exception e) assert(false, e.msg); // should never throw
return m_allocator;
Expand Down

0 comments on commit 515d43b

Please sign in to comment.