[Gc] Re: bug? or misunderstanding?

Andrew McKinlay mckinlay at axonsoft.com
Tue Feb 14 13:57:00 PST 2006


Here is a simple test program that fails:

#include "include/gc.h"
#include <stdio.h>
#include <memory.h>

int main(int argc, char** argv)
	{
	const int SIZE = 4104;
	const int N = 1000;
	char* blocks[N];
	const char FILL = 0x15;
	int i, j;
	const int OFFSET = 4000;
	
	for (i = 0; i < N; ++i)
		{
		blocks[i] = (char*) GC_malloc_atomic(SIZE);
		memset(blocks[i], FILL, SIZE);
		}
	
	GC_gcollect();
	for (i = 0; i < N; ++i)
		GC_malloc(i * 5);
	GC_gcollect();
	
	for (i = 0; i < N; ++i)
		for (j = 0; j < SIZE; ++j)
			if (blocks[i][j] != FILL)
				{
				printf("phase 1 - blocks[%d][%d] modified\n", i, j);
				return 1;
				}
			
	for (i = 0; i < N; ++i)
		blocks[i] += OFFSET;
	
	GC_gcollect();
	for (i = 0; i < N; ++i)
		GC_malloc(i * 5);
	GC_gcollect();
	
	for (i = 0; i < N; ++i)
		for (j = 0; j < SIZE; ++j)
			if (blocks[i][j - OFFSET] != FILL)
				{
				printf("phase 2 - blocks[%d][%d] modified\n", i, j);
				return 1;
				}

	return 0;
	}

Prints: phase 2 - blocks[1][0] modified

If you change the offset to 1000 or less it succeeds.

andrew



More information about the Gc mailing list