Hello,

this patch has been discussed here:

  http://gcc.gnu.org/ml/gcc-patches/2004-06/msg02122.html

The idea is to use a familiar C++ idiom for allocation and
destruction of structures.

Hiding both the sizeof expression and the cast from void *
(or char *) inside the macro avoids problems with
mismatching types, allows a shorter syntax.

Moreover, using these macros make client code portable
across all C dialects (K&R C, C89, C99 and C++).


include/
2004-06-26  Bernardo Innocenti  <bernie@develer.com>

	* libiberty.h (XNEW, XCNEW, XNEWVEC, XCNEWVEC, XOBNEW): Move
	here from libcpp/internal.h.
	(XDELETE, XRESIZEVEC, XDELETEVEC, XNEWVAR, XCNEWVAR, XRESIZEVAR): New
	macros.

libcpp/
2004-06-26  Bernardo Innocenti  <bernie@develer.com>

	* internal.h (xnew, xcnew, xnewvec, xcnewvec, xobnew): Move these
	macros to include/libiberty.h.

diff -u -p -r1.35 libiberty.h
--- include/libiberty.h	15 May 2003 19:02:12 -0000	1.35
+++ include/libiberty.h	26 Jun 2004 16:35:34 -0000
@@ -250,6 +250,37 @@ extern PTR xmemdup PARAMS ((const PTR, s
 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


diff -u -p -u -r1.3 internal.h
--- libcpp/internal.h	9 Jun 2004 20:10:13 -0000	1.3
+++ libcpp/internal.h	26 Jun 2004 00:27:50 -0000
@@ -559,11 +559,6 @@ extern const char *_cpp_default_encoding
 
 /* Utility routines and macros.  */
 #define DSC(str) (const uchar *)str, sizeof str - 1
-#define xnew(T)		(T *) xmalloc (sizeof(T))
-#define xcnew(T)	(T *) xcalloc (1, sizeof(T))
-#define xnewvec(T, N)	(T *) xmalloc (sizeof(T) * (N))
-#define xcnewvec(T, N)	(T *) xcalloc (N, sizeof(T))
-#define xobnew(O, T)	(T *) obstack_alloc (O, sizeof(T))
 
 /* These are inline functions instead of macros so we can get type
    checking.  */
