/* stack of pointers Copyright (C) 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "config.h" #include "system.h" #include "coretypes.h" #include "ptrstack.h" #define DEFAULT_PTRSTACK_SIZE 256 /* Create empty stack. */ ptrstack ptrstack_create (void) { ptrstack stack = xmalloc (sizeof (struct ptrstack) + (DEFAULT_PTRSTACK_SIZE - 1) * sizeof (void *)); stack->prev = stack; stack->size = DEFAULT_PTRSTACK_SIZE; stack->used = 0; return stack; } /* Free empty stack. */ void ptrstack_free (ptrstack stack) { gcc_assert (stack->prev && !stack->used && stack->prev == stack); stack->prev = NULL; free (stack); } /* Helper function for ptrstack_push - allocate new memory container. */ ptrstack ptrstack_grow_internal (ptrstack stack_header) { ptrstack stack = stack_header->prev; ptrstack newstack; size_t newsize = (size_t) stack->size + (size_t) stack->size / 2; if (newsize > 65536) newsize = 65536; newstack = xmalloc (sizeof (struct ptrstack) + (newsize - 1) * sizeof (void *)); newstack->prev = stack; newstack->size = newsize; newstack->used = 0; stack_header->prev = newstack; return newstack; }