aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBernardo Innocenti <bernie@develer.com>2004-07-24 17:48:01 +0000
committerBernardo Innocenti <bernie@develer.com>2004-07-24 17:48:01 +0000
commitbad88123ea167d645664f778d957e3eb328b4d68 (patch)
tree4c504fd2a4d3f4268fba46853fbb3488c315c964 /include
parent982b161283487e677c5a0528b1ccc16a421e1820 (diff)
* libiberty.h (XNEW, XCNEW, XNEWVEC, XCNEWVEC, XOBNEW): Move here from
libcpp/internal.h. (XDELETE, XRESIZEVEC, XDELETEVEC, XNEWVAR, XCNEWVAR, XRESIZEVAR): New macros. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@85119 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'include')
-rw-r--r--include/libiberty.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/libiberty.h b/include/libiberty.h
index 5c101538580..68eeeae7396 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -250,6 +250,37 @@ extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC;
extern double physmem_total PARAMS ((void));
extern double physmem_available PARAMS ((void));
+
+/* These macros provide a K&R/C89/C++-friendly way of allocating structures
+ with nice encapsulation. The XDELETE*() macros are technically
+ superfluous, but provided here for symmetry. Using them consistently
+ makes it easier to update client code to use different allocators such
+ as new/delete and new[]/delete[]. */
+
+/* Scalar allocators. */
+
+#define XNEW(T) ((T *) xmalloc (sizeof (T)))
+#define XCNEW(T) ((T *) xcalloc (1, sizeof (T)))
+#define XDELETE(P) free ((P))
+
+/* Array allocators. */
+
+#define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N)))
+#define XCNEWVEC(T, N) ((T *) xcalloc ((N), sizeof (T)))
+#define XRESIZEVEC(T, P, N) ((T *) xrealloc ((P), sizeof (T) * (N)))
+#define XDELETEVEC(P) free ((P))
+
+/* Allocators for variable-sized structures and raw buffers. */
+
+#define XNEWVAR(T, S) ((T *) xmalloc ((S)))
+#define XCNEWVAR(T, S) ((T *) xcalloc (1, (S)))
+#define XRESIZEVAR(T, P, S) ((T *) xrealloc ((P), (S)))
+
+/* Type-safe obstack allocator. */
+
+#define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T)))
+
+
/* hex character manipulation routines */
#define _hex_array_size 256