comparison gcc/alloc-pool.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents 77e2b8dfacca
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
1 /* Functions to support a pool of allocatable objects. 1 /* Functions to support a pool of allocatable objects.
2 Copyright (C) 1987, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2 Copyright (C) 1987, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
3 2007, 2008 Free Software Foundation, Inc. 3 2007, 2008, 2010 Free Software Foundation, Inc.
4 Contributed by Daniel Berlin <dan@cgsoftware.com> 4 Contributed by Daniel Berlin <dan@cgsoftware.com>
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it under 8 GCC is free software; you can redistribute it and/or modify it under
135 size_t header_size; 135 size_t header_size;
136 #ifdef GATHER_STATISTICS 136 #ifdef GATHER_STATISTICS
137 struct alloc_pool_descriptor *desc; 137 struct alloc_pool_descriptor *desc;
138 #endif 138 #endif
139 139
140 gcc_assert (name); 140 gcc_checking_assert (name);
141 141
142 /* Make size large enough to store the list header. */ 142 /* Make size large enough to store the list header. */
143 if (size < sizeof (alloc_pool_list)) 143 if (size < sizeof (alloc_pool_list))
144 size = sizeof (alloc_pool_list); 144 size = sizeof (alloc_pool_list);
145 145
150 /* Add the aligned size of ID. */ 150 /* Add the aligned size of ID. */
151 size += offsetof (allocation_object, u.data); 151 size += offsetof (allocation_object, u.data);
152 #endif 152 #endif
153 153
154 /* Um, we can't really allocate 0 elements per block. */ 154 /* Um, we can't really allocate 0 elements per block. */
155 gcc_assert (num); 155 gcc_checking_assert (num);
156 156
157 /* Allocate memory for the pool structure. */ 157 /* Allocate memory for the pool structure. */
158 pool = XNEW (struct alloc_pool_def); 158 pool = XNEW (struct alloc_pool_def);
159 159
160 /* Now init the various pieces of our pool structure. */ 160 /* Now init the various pieces of our pool structure. */
199 alloc_pool_list block, next_block; 199 alloc_pool_list block, next_block;
200 #ifdef GATHER_STATISTICS 200 #ifdef GATHER_STATISTICS
201 struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name); 201 struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name);
202 #endif 202 #endif
203 203
204 gcc_assert (pool); 204 gcc_checking_assert (pool);
205 205
206 /* Free each block allocated to the pool. */ 206 /* Free each block allocated to the pool. */
207 for (block = pool->block_list; block != NULL; block = next_block) 207 for (block = pool->block_list; block != NULL; block = next_block)
208 { 208 {
209 next_block = block->next; 209 next_block = block->next;
258 desc->current += pool->elt_size; 258 desc->current += pool->elt_size;
259 if (desc->peak < desc->current) 259 if (desc->peak < desc->current)
260 desc->peak = desc->current; 260 desc->peak = desc->current;
261 #endif 261 #endif
262 262
263 gcc_assert (pool); 263 gcc_checking_assert (pool);
264 264
265 /* If there are no more free elements, make some more!. */ 265 /* If there are no more free elements, make some more!. */
266 if (!pool->returned_free_list) 266 if (!pool->returned_free_list)
267 { 267 {
268 char *block; 268 char *block;
326 alloc_pool_list header; 326 alloc_pool_list header;
327 #ifdef GATHER_STATISTICS 327 #ifdef GATHER_STATISTICS
328 struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name); 328 struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name);
329 #endif 329 #endif
330 330
331 gcc_assert (ptr); 331
332 332 #ifdef ENABLE_CHECKING
333 #ifdef ENABLE_CHECKING 333 gcc_assert (ptr
334 /* Check whether the PTR was allocated from POOL. */ 334 /* Check if we free more than we allocated, which is Bad (TM). */
335 gcc_assert (pool->id == ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id); 335 && pool->elts_free < pool->elts_allocated
336 /* Check whether the PTR was allocated from POOL. */
337 && pool->id == ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id);
336 338
337 memset (ptr, 0xaf, pool->elt_size - offsetof (allocation_object, u.data)); 339 memset (ptr, 0xaf, pool->elt_size - offsetof (allocation_object, u.data));
338 340
339 /* Mark the element to be free. */ 341 /* Mark the element to be free. */
340 ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id = 0; 342 ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id = 0;
341 #else 343 #else
342 /* Check if we free more than we allocated, which is Bad (TM). */
343 gcc_assert (pool->elts_free < pool->elts_allocated);
344 #endif 344 #endif
345 345
346 header = (alloc_pool_list) ptr; 346 header = (alloc_pool_list) ptr;
347 header->next = pool->returned_free_list; 347 header->next = pool->returned_free_list;
348 pool->returned_free_list = header; 348 pool->returned_free_list = header;