Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Bernardo Innocenti <bernie@develer.com>
To: Bernardo Innocenti <bernie@develer.com>
Cc: Andrew Cagney <cagney@gnu.org>,
	Daniel Jacobowitz <drow@false.org>,
	 Ian Lance Taylor <ian@wasabisystems.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	 gdb-patches@sources.redhat.com,  binutils@sources.redhat.com,
	DJ Delorie <dj@redhat.com>
Subject: Re: [top-level] C++-friendly allocators for libiberty
Date: Thu, 01 Jul 2004 07:18:00 -0000	[thread overview]
Message-ID: <40E3BA87.9070107@develer.com> (raw)
In-Reply-To: <40E06174.9020203@develer.com>

Bernardo Innocenti wrote:

> Couldn't we just agree on a few naming issues and use the
> same macros everywhere?   I'd like to hear from the
> binutils people too.

I'm leaving for vacation and I'll be (mostly) away from the
keyboard for one week.

This is the libiberty patch again updated with the latest
suggestions.

The X*VAR() macros try to provide a full interface to
allocat structures of variable lenght.  They're not
used anywhere at the moment, so I could drop them in
case the interface doesn't seem useful enough.

Andrew Cagney suggested using a different naming scheme
(XMALLOC, XCALLOC...) that has the advantage of being more
familiar to C programmers and has been used in GDB for a
few years.  I still prefer XNEW/XDELETE, but I'm open to
changes if someone suggests names for the full set,
including the deallocators.


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

	* include/libiberty.h (xnew, xcnew, xnewvec, xcnewvec, xobnew): Move
	here from libcpp/internal.h.
	(xdelete, xresizevec, xdeletevec, xnewvar, xcnewvar, xresizevar): New
	macros.

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



-- 
  // Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/  http://www.develer.com/


  parent reply	other threads:[~2004-07-01  7:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-26  0:50 Bernardo Innocenti
2004-06-26  1:05 ` Bernardo Innocenti
2004-06-26  1:14 ` Ian Lance Taylor
2004-06-26  1:27   ` Bernardo Innocenti
2004-06-26  2:19     ` Ian Lance Taylor
2004-06-26  2:39       ` Bernardo Innocenti
2004-06-26  2:46         ` Daniel Jacobowitz
2004-06-26  3:04           ` Bernardo Innocenti
2004-06-26 17:22           ` Andrew Cagney
2004-06-26 17:37             ` Daniel Jacobowitz
2004-06-26 17:51               ` Andrew Cagney
2004-06-27  5:36             ` Bernardo Innocenti
2004-06-28 15:43               ` Andrew Cagney
2004-06-28 18:27                 ` Bernardo Innocenti
2004-06-28 18:52                   ` Joseph S. Myers
2004-07-01  7:18                   ` Bernardo Innocenti [this message]
2004-06-26  3:45         ` Alexandre Oliva
2004-06-26  4:18           ` Bernardo Innocenti
2004-06-26 18:31             ` Alexandre Oliva
2004-06-27  5:05               ` Bernardo Innocenti
2004-06-26  4:56           ` Zack Weinberg
2004-06-26 11:19             ` Falk Hueffner
2004-06-26 16:52               ` Bernardo Innocenti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40E3BA87.9070107@develer.com \
    --to=bernie@develer.com \
    --cc=binutils@sources.redhat.com \
    --cc=cagney@gnu.org \
    --cc=dj@redhat.com \
    --cc=drow@false.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    --cc=ian@wasabisystems.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox