xref: /dflybsd-src/contrib/gdb-7/gdb/gdb_obstack.h (revision c50c785cb49e9377ca78104c5540c7b33f768771)
15796c8dcSSimon Schubert /* Obstack wrapper for GDB.
25796c8dcSSimon Schubert 
3*c50c785cSJohn Marino    Copyright (C) 2002, 2007, 2008, 2009, 2010, 2011
4*c50c785cSJohn Marino    Free Software Foundation, Inc.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    This file is part of GDB.
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
95796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
105796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
115796c8dcSSimon Schubert    (at your option) any later version.
125796c8dcSSimon Schubert 
135796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
145796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
155796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165796c8dcSSimon Schubert    GNU General Public License for more details.
175796c8dcSSimon Schubert 
185796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
195796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
205796c8dcSSimon Schubert 
215796c8dcSSimon Schubert #if !defined (GDB_OBSTACK_H)
225796c8dcSSimon Schubert #define GDB_OBSTACK_H 1
235796c8dcSSimon Schubert 
245796c8dcSSimon Schubert #include "obstack.h"
255796c8dcSSimon Schubert 
265796c8dcSSimon Schubert /* Utility macros - wrap obstack alloc into something more robust.  */
275796c8dcSSimon Schubert 
28*c50c785cSJohn Marino #define OBSTACK_ZALLOC(OBSTACK,TYPE) \
29*c50c785cSJohn Marino   (memset (obstack_alloc ((OBSTACK), sizeof (TYPE)), 0, sizeof (TYPE)))
305796c8dcSSimon Schubert 
31*c50c785cSJohn Marino #define OBSTACK_CALLOC(OBSTACK,NUMBER,TYPE) \
32*c50c785cSJohn Marino   (memset (obstack_alloc ((OBSTACK), (NUMBER) * sizeof (TYPE)), \
33*c50c785cSJohn Marino 	   0, (NUMBER) * sizeof (TYPE)))
345796c8dcSSimon Schubert 
355796c8dcSSimon Schubert /* Unless explicitly specified, GDB obstacks always use xmalloc() and
365796c8dcSSimon Schubert    xfree().  */
375796c8dcSSimon Schubert /* Note: ezannoni 2004-02-09: One could also specify the allocation
385796c8dcSSimon Schubert    functions using a special init function for each obstack,
395796c8dcSSimon Schubert    obstack_specify_allocation.  However we just use obstack_init and
405796c8dcSSimon Schubert    let these defines here do the job.  While one could argue the
415796c8dcSSimon Schubert    superiority of one approach over the other, we just chose one
425796c8dcSSimon Schubert    throughout.  */
435796c8dcSSimon Schubert 
445796c8dcSSimon Schubert #define obstack_chunk_alloc xmalloc
455796c8dcSSimon Schubert #define obstack_chunk_free xfree
465796c8dcSSimon Schubert 
475796c8dcSSimon Schubert #define obstack_grow_str(OBSTACK,STRING) \
485796c8dcSSimon Schubert   obstack_grow (OBSTACK, STRING, strlen (STRING))
495796c8dcSSimon Schubert #define obstack_grow_str0(OBSTACK,STRING) \
505796c8dcSSimon Schubert   obstack_grow0 (OBSTACK, STRING, strlen (STRING))
515796c8dcSSimon Schubert 
525796c8dcSSimon Schubert #define obstack_grow_wstr(OBSTACK, WSTRING) \
535796c8dcSSimon Schubert   obstack_grow (OBSTACK, WSTRING, sizeof (gdb_wchar_t) * gdb_wcslen (WSTRING))
545796c8dcSSimon Schubert 
555796c8dcSSimon Schubert #endif
56