Commit cf785988 by Richard Henderson

badalloc1.C (arena_size): New.

        * g++.old-deja/g++.eh/badalloc1.C (arena_size): New.
        (arena): Use it.
        (malloc): Correct allocation logic.  Abort if we fill up the
        arena before initialization complete.
        (realloc): Correct allocation logic.

From-SVN: r48224
parent 5bc27702
2001-12-20 Richard Henderson <rth@redhat.com>
* g++.old-deja/g++.eh/badalloc1.C (arena_size): New.
(arena): Use it.
(malloc): Correct allocation logic. Abort if we fill up the
arena before initialization complete.
(realloc): Correct allocation logic.
2001-12-20 Jakub Jelinek <jakub@redhat.com>
* gcc.c-torture/compile/20011219-2.c: New test.
......@@ -52,7 +60,7 @@ Mon Dec 17 16:54:56 2001 Nicola Pero <nicola@brainstorm.co.uk>
2001-12-13 John David Anglin <dave@hiauly1.hia.nrc.ca>
* g++.old-deja/g++.jason/template31.C: Remove templates for classes
std::__malloc_alloc_template<0> and
std::__malloc_alloc_template<0> and
std::__default_alloc_template<false, 0>.
Thu Dec 13 10:35:33 2001 Nicola Pero <n.pero@mi.flashnet.it>
......@@ -117,13 +125,13 @@ Thu Dec 13 10:35:33 2001 Nicola Pero <n.pero@mi.flashnet.it>
2001-10-08 Aldy Hernandez <aldyh@redhat.com>
* gcc.c-torture/execute/builtin-types-compatible-p.c: New.
* gcc.c-torture/execute/builtin-types-compatible-p.c: New.
* gcc.dg/builtin-choose-expr.c: New.
* gcc.dg/builtin-choose-expr.c: New.
2001-12-07 Aldy Hernandez <aldyh@redhat.com>
* gcc.dg/altivec-2.c: New.
* gcc.dg/altivec-2.c: New.
2001-12-07 Richard Henderson <rth@redhat.com>
......@@ -281,7 +289,7 @@ Fri Nov 23 15:55:44 2001 Jeffrey A Law (law@cygnus.com)
2001-11-17 Aldy Hernandez <aldyh@redhat.com>
* gcc.dg/altivec-1.c: Fix typo.
* gcc.dg/altivec-1.c: Fix typo.
2001-11-20 Joseph S. Myers <jsm28@cam.ac.uk>
......@@ -306,7 +314,7 @@ Fri Nov 23 15:55:44 2001 Jeffrey A Law (law@cygnus.com)
2001-11-19 Aldy Hernandez <aldyh@redhat.com>
* gcc.dg/altivec-1.c: New.
* gcc.dg/altivec-1.c: New.
2001-11-19 Neil Booth <neil@daikokuya.demon.co.uk>
......@@ -434,7 +442,7 @@ Fri Nov 23 15:55:44 2001 Jeffrey A Law (law@cygnus.com)
2001-11-01 Stephane Carrez <Stephane.Carrez@worldnet.fr>
* gcc.c-torture/compile/20010327-1.c: Use __SIZE_TYPE__ instead
of unsigned long.
of unsigned long.
2001-10-30 Jakub Jelinek <jakub@redhat.com>
......@@ -663,7 +671,7 @@ Mon Oct 29 21:19:53 2001 Nicola Pero <n.pero@mi.flashnet.it>
2001-09-15 Aldy Hernandez <aldyh@redhat.com>
* gcc.c-torture/execute/980223.c: Change type of addr from long
* gcc.c-torture/execute/980223.c: Change type of addr from long
to char *.
2001-09-15 Hans-Peter Nilsson <hp@axis.com>
......@@ -769,7 +777,7 @@ Mon Oct 29 21:19:53 2001 Nicola Pero <n.pero@mi.flashnet.it>
2001-08-25 Aldy Hernandez <aldyh@redhat.com>
* gcc.dg/asm-names.c (ymain): New.
* gcc.dg/asm-names.c (ymain): New.
2001-08-22 Geoffrey Keating <geoffk@redhat.com>
......@@ -788,7 +796,7 @@ Mon Oct 29 21:19:53 2001 Nicola Pero <n.pero@mi.flashnet.it>
2001-08-21 Aldy Hernandez <aldyh@redhat.com>
* gcc.c-torture/execute/divmod-1.c: Convert to ANSI.
* gcc.c-torture/execute/divmod-1.c: Convert to ANSI.
2001-08-20 Janis Johnson <janis187@us.ibm.com>
......@@ -896,7 +904,7 @@ Mon Oct 29 21:19:53 2001 Nicola Pero <n.pero@mi.flashnet.it>
* g77.dg/ffixed-line-length-7.f
* g77.dg/ffixed-line-length-72.f
* g77.dg/ffixed-line-length-none.f
* g77.dg/ffree-form-1.f
* g77.dg/ffree-form-1.f
* g77.dg/fno-backslash.f
* g77.dg/fno-f90-1.f
* g77.dg/fno-fixed-form-1.f
......
......@@ -2,43 +2,78 @@
// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 6 June 2000 <nathan@codesourcery.com>
// Check we can throw a bad_alloc exception when malloc dies
// Check we can throw a bad_alloc exception when malloc dies.
static __SIZE_TYPE__ arena[64]; // so things can initialize
typedef __SIZE_TYPE__ size_t;
extern "C" void abort();
extern "C" void *memcpy(void *, const void *, size_t);
// Assume that STACK_SIZE defined implies a system that does not have a
// large data space either, and additionally that we're not linking against
// a shared libstdc++ (which requires quite a bit more initialization space).
#ifdef STACK_SIZE
const int arena_size = 256;
#else
const int arena_size = 32768;
#endif
struct object
{
size_t size __attribute__((aligned));
};
static char arena[arena_size] __attribute__((aligned));
static size_t pos;
// So we can force a failure when needed.
static int fail;
static unsigned pos;
extern "C" void *malloc (__SIZE_TYPE__ size)
extern "C" void *malloc (size_t size)
{
__SIZE_TYPE__ *p = &arena[pos];
object *p = reinterpret_cast<object *>(&arena[pos]);
if (fail)
return 0;
arena[pos] = size;
size = (size + 4 * sizeof (__SIZE_TYPE__) - 1)
/ sizeof (__SIZE_TYPE__) & ~3; // Yes, this is a hack
pos += size + 4;
return p + 4;
p->size = size;
size = (size + __alignof__(object) + 1) & - __alignof__(object);
pos += size + sizeof(object);
// Verify that we didn't run out of memory before getting initialized.
if (pos > arena_size)
abort ();
return p + 1;
}
extern "C" void free (void *)
{
}
extern "C" void *realloc (void *p, __SIZE_TYPE__ size)
extern "C" void *realloc (void *p, size_t size)
{
void *r = malloc (size);
unsigned int oldSize;
if (r && p)
void *r;
if (p)
{
oldSize = ((__SIZE_TYPE__ *)p)[-4];
if (oldSize < size)
size = oldSize;
while (size--)
((char *)r)[size] = ((char *)p)[size];
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);
}
}
free (p);
else
r = malloc (size);
return r;
}
......
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