This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[LIBIBERTY PATCH]: Add missing allocator macros
- From: "Kaveh R. GHAZI" <ghazi at caip dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org, dj at redhat dot com, iant at google dot com
- Date: Mon, 23 Jun 2008 19:10:34 -0400 (EDT)
- Subject: [LIBIBERTY PATCH]: Add missing allocator macros
This patch adds several missing allocator macros to libiberty.h for
alloca(), xmemdup() and obstack_alloc(). These are in response to a
discussion here:
http://gcc.gnu.org/ml/gcc-patches/2008-06/msg01455.html
Bootstrapped on x86_64-unknown-linux-gnu, nothing uses these macros yet so
a bootstrap only checks that I didn't introduce a syntax error. I have a
separate patch that uses them testing as we speak. Will post it shortly.
Okay for mainline?
Thanks,
--Kaveh
(PS: I don't have write access src.)
2008-06-23 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* libiberty.h (XALLOCA, XDUP, XALLOCAVEC, XDUPVEC, XALLOCAVAR,
XDUPVAR, XOBNEWVEC, XOBNEWVAR): New.
diff -rup orig/egcc-SVN20080623/include/libiberty.h egcc-SVN20080623/include/libiberty.h
--- orig/egcc-SVN20080623/include/libiberty.h 2008-03-14 00:42:30.000000000 +0100
+++ egcc-SVN20080623/include/libiberty.h 2008-06-23 23:30:41.000000000 +0200
@@ -320,26 +320,34 @@ extern double physmem_available (void);
/* Scalar allocators. */
+#define XALLOCA(T) ((T *) alloca (sizeof (T)))
#define XNEW(T) ((T *) xmalloc (sizeof (T)))
#define XCNEW(T) ((T *) xcalloc (1, sizeof (T)))
+#define XDUP(T, P) ((T *) xmemdup ((P), sizeof (T), sizeof (T)))
#define XDELETE(P) free ((void*) (P))
/* Array allocators. */
+#define XALLOCAVEC(T, N) ((T *) alloca (sizeof (T) * (N)))
#define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N)))
#define XCNEWVEC(T, N) ((T *) xcalloc ((N), sizeof (T)))
+#define XDUPVEC(T, P, N) ((T *) xmemdup ((P), sizeof (T) * (N), sizeof (T) * (N)))
#define XRESIZEVEC(T, P, N) ((T *) xrealloc ((void *) (P), sizeof (T) * (N)))
#define XDELETEVEC(P) free ((void*) (P))
/* Allocators for variable-sized structures and raw buffers. */
+#define XALLOCAVAR(T, S) ((T *) alloca ((S)))
#define XNEWVAR(T, S) ((T *) xmalloc ((S)))
#define XCNEWVAR(T, S) ((T *) xcalloc (1, (S)))
+#define XDUPVAR(T, P, S1, S2) ((T *) xmemdup ((P), (S1), (S2)))
#define XRESIZEVAR(T, P, S) ((T *) xrealloc ((P), (S)))
/* Type-safe obstack allocator. */
#define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T)))
+#define XOBNEWVEC(O, T, N) ((T *) obstack_alloc ((O), sizeof (T) * (N)))
+#define XOBNEWVAR(O, T, S) ((T *) obstack_alloc ((O), (S)))
#define XOBFINISH(O, T) ((T) obstack_finish ((O)))
/* hex character manipulation routines */