1 // excess errors test - XFAIL xstormy16-*-*
2 // Copyright (C) 2000 Free Software Foundation, Inc.
3 // Contributed by Nathan Sidwell 6 June 2000 <nathan@codesourcery.com>
5 // Check we can throw a bad_alloc exception when malloc dies.
7 typedef __SIZE_TYPE__ size_t;
8 extern "C" void abort();
9 extern "C" void *memcpy(void *, const void *, size_t);
11 // Assume that STACK_SIZE defined implies a system that does not have a
12 // large data space either, and additionally that we're not linking against
13 // a shared libstdc++ (which requires quite a bit more initialization space).
15 const int arena_size = 256;
17 const int arena_size = 32768;
22 size_t size __attribute__((aligned));
25 static char arena[arena_size] __attribute__((aligned));
28 // So we can force a failure when needed.
31 extern "C" void *malloc (size_t size)
33 object *p = reinterpret_cast<object *>(&arena[pos]);
39 size = (size + __alignof__(object) + 1) & - __alignof__(object);
40 pos += size + sizeof(object);
42 // Verify that we didn't run out of memory before getting initialized.
49 extern "C" void free (void *)
53 extern "C" void *realloc (void *p, size_t size)
59 object *o = reinterpret_cast<object *>(p) - 1;
60 size_t old_size = o->size;
70 memcpy (r, p, old_size);
80 void fn_throw() throw(int)
85 void fn_rethrow() throw(int)
92 void fn_catchthrow() throw(int)
109 try{fn_catchthrow();}