typedef __SIZE_TYPE__ size_t;
extern "C" void abort();
extern "C" void *memcpy(void *, const void *, size_t);
#ifdef STACK_SIZE
const int arena_size = 256;
#else
#if defined(__FreeBSD__) || defined(__sun__) || defined(__hpux__)
const int arena_size = 262144;
#else
const int arena_size = 32768;
#endif
#endif
struct object
{
size_t size __attribute__((aligned));
};
static char arena[arena_size] __attribute__((aligned));
static size_t pos;
static int fail;
extern "C" void *malloc (size_t size)
{
object *p = reinterpret_cast<object *>(&arena[pos]);
if (fail)
return 0;
p->size = size;
size = (size + __alignof__(object) - 1) & - __alignof__(object);
pos += size + sizeof(object);
if (pos > arena_size)
abort ();
return p + 1;
}
extern "C" void free (void *)
{
}
extern "C" void *realloc (void *p, size_t size)
{
void *r;
if (p)
{
object *o = reinterpret_cast<object *>(p) - 1;
size_t old_size = o->size;
if (old_size >= size)
{
r = p;
o->size = size;
}
else
{
r = malloc (size);
memcpy (r, p, old_size);
free (p);
}
}
else
r = malloc (size);
return r;
}
void fn_throw() throw(int)
{
throw 1;
}
void fn_rethrow() throw(int)
{
try{fn_throw();}
catch(int a){
throw;}
}
void fn_catchthrow() throw(int)
{
try{fn_throw();}
catch(int a){
throw a + 1;}
}
int main()
{
try{fn_throw();}
catch(int a){}
fail = 1;
try{fn_throw();}
catch(int a){}
try{fn_rethrow();}
catch(int a){}
try{fn_catchthrow();}
catch(int a){}
return 0;
}