Merge pull request #136 from Geod24/dip1000
Let malloc infer its attributes
This commit is contained in:
commit
4813cba338
|
@ -18,20 +18,18 @@ void print(ARGS...)(string str, ARGS args)
|
||||||
}
|
}
|
||||||
|
|
||||||
T mallocT(T, ARGS...)(ARGS args)
|
T mallocT(T, ARGS...)(ARGS args)
|
||||||
@trusted @nogc {
|
{
|
||||||
import core.stdc.stdlib : malloc;
|
import core.stdc.stdlib : malloc;
|
||||||
import std.conv : emplace;
|
import std.conv : emplace;
|
||||||
|
|
||||||
enum size = __traits(classInstanceSize, T);
|
T ret = () @trusted {
|
||||||
auto ret = cast(T)malloc(size);
|
enum size = __traits(classInstanceSize, T);
|
||||||
static if (hasIndirections!T)
|
T r = cast(T)malloc(size);
|
||||||
GC.addRange(cast(void*)ret, __traits(classInstanceSize, T));
|
static if (hasIndirections!T)
|
||||||
scope doit = { emplace!T((cast(void*)ret)[0 .. size], args); };
|
GC.addRange(cast(void*)r, size);
|
||||||
static if (__traits(compiles, () nothrow { typeof(doit).init(); })) // NOTE: doing the typeof thing here, because LDC 1.7.0 otherwise thinks doit gets escaped here
|
return r;
|
||||||
(cast(void delegate() @nogc nothrow)doit)();
|
}();
|
||||||
else
|
return emplace!T(ret, args);
|
||||||
(cast(void delegate() @nogc)doit)();
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeT(T)(ref T inst) @nogc
|
void freeT(T)(ref T inst) @nogc
|
||||||
|
|
Loading…
Reference in a new issue