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