Commit 49febe03 authored by John van Groningen's avatar John van Groningen
Browse files

use ConvertAlloc instead of CompAlloc, because using CompAlloc causes the compiler to crash

parent 93a24b20
......@@ -66,3 +66,138 @@ fatal_backend_error (char *s)
#endif
Debugger ();
}
#if 1
/*
Memory management
=================
*/
static enum {kMemoryInitClear, kMemoryInitSet} gMemoryInit = kMemoryInitSet;
# define kDefaultConvertBufferSize (32 * 1024)
typedef struct convert_buffer ConvertBufferS, *ConvertBufferP;
struct convert_buffer
{
ConvertBufferP cb_next;
int cb_size;
char cb_memory [kDefaultConvertBufferSize]; /* or more bytes */
};
static void
InvalidateMemory (void *memory, size_t size)
{
char value, *p;
int i;
switch (gMemoryInit)
{
case kMemoryInitClear:
value = 0;
break;
case kMemoryInitSet:
value = ~0;
break;
default:
Assert (False);
break;
}
p = memory;
for (i = 0; i < size; i++)
*p++ = value;
} /* InvalidateMemory */
static ConvertBufferP gFirstBuffer = NULL, gCurrentBuffer = NULL;
static char *gMemory;
static long gBytesLeft = 0;
static void
AllocConvertBuffer (int min_size)
{
ConvertBufferP newBuffer;
int new_convert_buffer_size;
new_convert_buffer_size=sizeof (ConvertBufferS);
while (min_size>new_convert_buffer_size)
new_convert_buffer_size+=kDefaultConvertBufferSize;
newBuffer = (ConvertBufferP) malloc (new_convert_buffer_size);
if (newBuffer == NULL)
FatalCompError ("backendsupport.c", "AllocConvertBuffer", "out of memory");
new_convert_buffer_size -= sizeof (ConvertBufferS)-kDefaultConvertBufferSize;
newBuffer->cb_size=new_convert_buffer_size;
if (gFirstBuffer == NULL)
gCurrentBuffer = gFirstBuffer = newBuffer;
else
gCurrentBuffer = gCurrentBuffer->cb_next = newBuffer;
gCurrentBuffer->cb_next = NULL;
gBytesLeft = new_convert_buffer_size;
gMemory = gCurrentBuffer->cb_memory;
InvalidateMemory (gMemory, new_convert_buffer_size);
if (gFirstBuffer == NULL)
gFirstBuffer = gCurrentBuffer;
} /* AllocConvertBuffer */
void
FreeConvertBuffers (void)
{
ConvertBufferP buffer;
buffer = gFirstBuffer;
while (buffer != NULL)
{
ConvertBufferP nextBuffer;
nextBuffer = buffer->cb_next;
InvalidateMemory (buffer,buffer->cb_size);
free (buffer);
buffer = nextBuffer;
}
gFirstBuffer = NULL;
gCurrentBuffer = NULL;
gBytesLeft = NULL;
} /* FreeConvertBuffers */
void *
ConvertAlloc (SizeT size)
{
void *memory;
size = (size+3) & ~3;
if (size > gBytesLeft){
AllocConvertBuffer (size);
if (size>gBytesLeft){
static char s[100];
sprintf (s,"ConvertAlloc: size = %d, gBytesLeft = %d",size,gBytesLeft);
fatal_backend_error (s);
}
}
Assert (size <= gBytesLeft);
memory = gMemory;
gBytesLeft -= size;
gMemory += size;
return ((void *) memory);
} /* ConvertAlloc */
#endif
\ No newline at end of file
......@@ -18,7 +18,12 @@ extern void fatal_backend_error (char *s);
Memory management
=================
*/
#if 1
extern void FreeConvertBuffers (void);
extern void *ConvertAlloc (SizeT size);
#else
# define FreeConvertBuffers()
# define ConvertAlloc(size) CompAlloc (size)
#endif
# define ConvertAllocType(t) ((t*) ConvertAlloc (SizeOf (t)))
# define ArraySize(array) ((unsigned) (sizeof (array) / sizeof (array[0])))
\ No newline at end of file
# define ArraySize(array) ((unsigned) (sizeof (array) / sizeof (array[0])))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment