xref: /dflybsd-src/contrib/gdb-7/gdb/gdb_obstack.h (revision 5796c8dc12c637f18a1740c26afd8d40ffa9b719)
1*5796c8dcSSimon Schubert /* Obstack wrapper for GDB.
2*5796c8dcSSimon Schubert 
3*5796c8dcSSimon Schubert    Copyright (C) 2002, 2007, 2008, 2009 Free Software Foundation, Inc.
4*5796c8dcSSimon Schubert 
5*5796c8dcSSimon Schubert    This file is part of GDB.
6*5796c8dcSSimon Schubert 
7*5796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
8*5796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
9*5796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
10*5796c8dcSSimon Schubert    (at your option) any later version.
11*5796c8dcSSimon Schubert 
12*5796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
13*5796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*5796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*5796c8dcSSimon Schubert    GNU General Public License for more details.
16*5796c8dcSSimon Schubert 
17*5796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
18*5796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19*5796c8dcSSimon Schubert 
20*5796c8dcSSimon Schubert #if !defined (GDB_OBSTACK_H)
21*5796c8dcSSimon Schubert #define GDB_OBSTACK_H 1
22*5796c8dcSSimon Schubert 
23*5796c8dcSSimon Schubert #include "obstack.h"
24*5796c8dcSSimon Schubert 
25*5796c8dcSSimon Schubert /* Utility macros - wrap obstack alloc into something more robust.  */
26*5796c8dcSSimon Schubert 
27*5796c8dcSSimon Schubert #define OBSTACK_ZALLOC(OBSTACK,TYPE) (memset (obstack_alloc ((OBSTACK), sizeof (TYPE)), 0, sizeof (TYPE)))
28*5796c8dcSSimon Schubert 
29*5796c8dcSSimon Schubert #define OBSTACK_CALLOC(OBSTACK,NUMBER,TYPE) (memset (obstack_alloc ((OBSTACK), (NUMBER) * sizeof (TYPE)), 0, (NUMBER) * sizeof (TYPE)))
30*5796c8dcSSimon Schubert 
31*5796c8dcSSimon Schubert /* Unless explicitly specified, GDB obstacks always use xmalloc() and
32*5796c8dcSSimon Schubert    xfree().  */
33*5796c8dcSSimon Schubert /* Note: ezannoni 2004-02-09: One could also specify the allocation
34*5796c8dcSSimon Schubert    functions using a special init function for each obstack,
35*5796c8dcSSimon Schubert    obstack_specify_allocation.  However we just use obstack_init and
36*5796c8dcSSimon Schubert    let these defines here do the job.  While one could argue the
37*5796c8dcSSimon Schubert    superiority of one approach over the other, we just chose one
38*5796c8dcSSimon Schubert    throughout.  */
39*5796c8dcSSimon Schubert 
40*5796c8dcSSimon Schubert #define obstack_chunk_alloc xmalloc
41*5796c8dcSSimon Schubert #define obstack_chunk_free xfree
42*5796c8dcSSimon Schubert 
43*5796c8dcSSimon Schubert #define obstack_grow_str(OBSTACK,STRING) \
44*5796c8dcSSimon Schubert   obstack_grow (OBSTACK, STRING, strlen (STRING))
45*5796c8dcSSimon Schubert #define obstack_grow_str0(OBSTACK,STRING) \
46*5796c8dcSSimon Schubert   obstack_grow0 (OBSTACK, STRING, strlen (STRING))
47*5796c8dcSSimon Schubert 
48*5796c8dcSSimon Schubert #define obstack_grow_wstr(OBSTACK, WSTRING) \
49*5796c8dcSSimon Schubert   obstack_grow (OBSTACK, WSTRING, sizeof (gdb_wchar_t) * gdb_wcslen (WSTRING))
50*5796c8dcSSimon Schubert 
51*5796c8dcSSimon Schubert #endif
52