From fbbb83218706509fc4ea2d2a1ad3f5c245b67edf Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Sun, 19 Dec 2010 13:02:09 +0300 Subject: [PATCH] Added suppport for custom allocators for structs. --- gen/toir.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gen/toir.cpp b/gen/toir.cpp index 193f8872..8938fb0f 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1690,7 +1690,21 @@ DValue* NewExp::toElem(IRState* p) { Logger::println("new struct on heap: %s\n", newtype->toChars()); // allocate - LLValue* mem = DtoNew(newtype); + LLValue* mem = 0; +#if DMDV2 + if (allocator) + { + // custom allocator + allocator->codegen(Type::sir); + DFuncValue dfn(allocator, allocator->ir.irFunc->func); + DValue* res = DtoCallFunction(loc, NULL, &dfn, newargs); + mem = DtoBitCast(res->getRVal(), DtoType(ntype->pointerTo()), ".newstruct_custom"); + } else +#endif + { + // default allocator + mem = DtoNew(newtype); + } // init TypeStruct* ts = (TypeStruct*)ntype; if (ts->isZeroInit(ts->sym->loc)) {