/* Vector API for GNU compiler.
- Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010
+ Free Software Foundation, Inc.
Contributed by Nathan Sidwell <nathan@codesourcery.com>
This file is part of GCC.
#endif
#include "system.h"
+#include "coretypes.h"
#include "ggc.h"
#include "vec.h"
-#include "coretypes.h"
#include "diagnostic-core.h"
#include "hashtab.h"
-struct vec_prefix
-{
- unsigned num;
- unsigned alloc;
- void *vec[1];
-};
-
-
#ifdef GATHER_STATISTICS
/* Store information about each particular vector. */
{
struct vec_prefix *pfx = (struct vec_prefix *) vec;
unsigned alloc = calculate_allocation (pfx, reserve, exact);
+ size_t size;
if (!alloc)
{
return NULL;
}
- vec = ggc_realloc_stat (vec, vec_offset + alloc * elt_size PASS_MEM_STAT);
+ /* Calculate the amount of space we want. */
+ size = vec_offset + alloc * elt_size;
+ /* Ask the allocator how much space it will really give us. */
+ size = ggc_round_alloc_size (size);
+ /* Adjust the number of slots accordingly. */
+ alloc = (size - vec_offset) / elt_size;
+ /* And finally, recalculate the amount of space we ask for. */
+ size = vec_offset + alloc * elt_size;
+
+ vec = ggc_realloc_stat (vec, size PASS_MEM_STAT);
+
((struct vec_prefix *)vec)->alloc = alloc;
if (!pfx)
((struct vec_prefix *)vec)->num = 0;
vec_gc_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
return vec_gc_o_reserve_1 (vec, reserve,
- offsetof (struct vec_prefix, vec),
+ sizeof (struct vec_prefix),
sizeof (void *), false
PASS_MEM_STAT);
}
vec_gc_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
{
return vec_gc_o_reserve_1 (vec, reserve,
- offsetof (struct vec_prefix, vec),
+ sizeof (struct vec_prefix),
sizeof (void *), true
PASS_MEM_STAT);
}
vec_heap_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve,
- offsetof (struct vec_prefix, vec),
+ sizeof (struct vec_prefix),
sizeof (void *), false
PASS_MEM_STAT);
}
vec_heap_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve,
- offsetof (struct vec_prefix, vec),
+ sizeof (struct vec_prefix),
sizeof (void *), true
PASS_MEM_STAT);
}
if (newvec && vec)
{
((struct vec_prefix *) newvec)->num = ((struct vec_prefix *) vec)->num;
- memcpy (((struct vec_prefix *) newvec)->vec,
- ((struct vec_prefix *) vec)->vec,
+ memcpy (((struct vec_prefix *) newvec)+1,
+ ((struct vec_prefix *) vec)+1,
((struct vec_prefix *) vec)->num * elt_size);
}
return newvec;
vec_stack_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
return vec_stack_o_reserve_1 (vec, reserve,
- offsetof (struct vec_prefix, vec),
+ sizeof (struct vec_prefix),
sizeof (void *), false
PASS_MEM_STAT);
}
vec_stack_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
{
return vec_stack_o_reserve_1 (vec, reserve,
- offsetof (struct vec_prefix, vec),
+ sizeof (struct vec_prefix),
sizeof (void *), true
PASS_MEM_STAT);
}