Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions compiler/src/dmd/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -709,33 +709,25 @@ extern (C++) final class SymbolDeclaration : Declaration
}

/***********************************************************
* Generate Identifier for TypeInfo corresponding to `t`
* Params:
* t = type to generate TypeInfo identifier for
* Returns:
* the identifier
*/
private Identifier getTypeInfoIdent(Type t)
{
import dmd.mangle;
import core.stdc.stdlib;
import dmd.root.rmem;
// _init_10TypeInfo_%s
OutBuffer buf;
buf.reserve(32);
import dmd.mangle;
mangleToBuffer(t, buf);

const slice = buf[];

// Allocate buffer on stack, fail over to using malloc()
char[128] namebuf;
const namelen = 19 + size_t.sizeof * 3 + slice.length + 1;
auto name = namelen <= namebuf.length ? namebuf.ptr : cast(char*)Mem.check(malloc(namelen));

const length = snprintf(name, namelen, "_D%lluTypeInfo_%.*s6__initZ",
cast(ulong)(9 + slice.length), cast(int)slice.length, slice.ptr);
//printf("%p %s, deco = %s, name = %s\n", this, toChars(), deco, name);
assert(0 < length && length < namelen); // don't overflow the buffer

auto id = Identifier.idPool(name[0 .. length]);
OutBuffer buf2;
buf2.reserve(19 + size_t.sizeof * 3 + buf.length + 1);
buf2.printf("_D%zuTypeInfo_%.*s6__initZ", 9+buf.length, cast(int)buf.length, buf[].ptr);

if (name != namebuf.ptr)
free(name);
auto id = Identifier.idPool(buf2[]);
return id;
}

Expand Down
Loading