Skip to content

Commit

Permalink
remove alloca()
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Feb 3, 2013
1 parent 144a52d commit bca7e93
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/mtype.c
Expand Up @@ -11,12 +11,7 @@
#define __C99FEATURES__ 1 // Needed on Solaris for NaN and more
#define __USE_ISOC99 1 // so signbit() gets defined

#if defined (__sun)
#include <alloca.h>
#endif

#include <math.h>

#include <stdio.h>
#include <assert.h>
#include <float.h>
Expand Down Expand Up @@ -2184,9 +2179,6 @@ Identifier *Type::getTypeInfoIdent(int internal)
{
// _init_10TypeInfo_%s
OutBuffer buf;
Identifier *id;
char *name;
size_t len;

if (internal)
{ buf.writeByte(mangleChar[ty]);
Expand All @@ -2195,19 +2187,27 @@ Identifier *Type::getTypeInfoIdent(int internal)
}
else
toDecoBuffer(&buf);
len = buf.offset;
name = (char *)alloca(19 + sizeof(len) * 3 + len + 1);

size_t len = buf.offset;
buf.writeByte(0);
#if TARGET_OSX
// The LINKc will prepend the _
sprintf(name, "D%dTypeInfo_%s6__initZ", 9 + len, buf.data);
#else

// Allocate buffer on stack, fail over to using malloc()
char namebuf[40];
size_t namelen = 19 + sizeof(len) * 3 + len + 1;
char *name = namelen <= sizeof(namebuf) ? namebuf : (char *)malloc(namelen);
assert(name);

sprintf(name, "_D%dTypeInfo_%s6__initZ", 9 + len, buf.data);
#endif
if (global.params.isWindows && !global.params.is64bit)
name++; // C mangling will add it back in
//printf("name = %s\n", name);
id = Lexer::idPool(name);
assert(strlen(name) < namelen); // don't overflow the buffer

size_t off = 0;
if (global.params.isOSX || global.params.isWindows && !global.params.is64bit)
++off; // C mangling will add '_' back in
Identifier *id = Lexer::idPool(name + off);

if (name != namebuf)
free(name);
return id;
}

Expand Down Expand Up @@ -5354,7 +5354,7 @@ void TypeFunction::toDecoBuffer(OutBuffer *buf, int flag)
Parameter::argsToDecoBuffer(buf, parameters);
//if (buf->data[buf->offset - 1] == '@') halt();
buf->writeByte('Z' - varargs); // mark end of arg list
if (next != NULL)
if(next != NULL)
next->toDecoBuffer(buf);
inuse--;
}
Expand Down

0 comments on commit bca7e93

Please sign in to comment.