From: Andrew Cagney <cagney@gnu.org>
To: Bernardo Innocenti <bernie@develer.com>
Cc: 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: Mon, 28 Jun 2004 15:43:00 -0000 [thread overview]
Message-ID: <40E03CB7.1060500@gnu.org> (raw)
In-Reply-To: <40DE5CC0.7070102@develer.com>
> Andrew Cagney wrote:
>
>
>>>>>Bernando, you've now got an interface which allows reallocating to a
>>>>>variable size, but not allocating to one... There's no need for a
>>>>>rush, let's give people some time to comment before putting this into
>>>>>libiberty. As DJ says, it's hard to take things out of libiberty.
>>
>>>
>>> I guess daniel had this in mind:
>>>
>>
>>>>>/* Utility macros to allocate typed memory. Avoids errors like:
>>>>> struct foo *foo = xmalloc (sizeof struct bar); and memset (foo,
>>>>> sizeof (struct foo), 0). */
>>>>>#define XZALLOC(TYPE) ((TYPE*) memset (xmalloc (sizeof (TYPE)), 0, sizeof (TYPE)
>>>>>))
>>>>>#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
>>>>>#define XCALLOC(NMEMB, TYPE) ((TYPE*) xcalloc ((NMEMB), sizeof (TYPE)))
>
>
> Hmmm... What's the advantage of using XZALLOC over XCALLOC?
It avoids that extra argument (but yes, XZALLOC should be implemented
using XCALLOC).
> These macros don't address vector allocations and aren't paired
> with corresponding macros to release memory.
So far no need. Since its C everyone already knows to call free().
>>They first appeared in GDB in '99 and were added to GDB's global header
>>> file in '02 (and I'm sure the idea was stolen from elsewhere). Unlike
>>> the macros being proposed, these:
>>>
>>> - use uppercase to make it very very clear that they are macros
>
>
> This contraddicts the GCC addenda to the GNU coding conventions: macros
> meant to be used like C functions should be named like C functions.
> See http://gcc.gnu.org/codingconventions.html (Miscellaneous Conventions).
Fortunatly that addenda _only_ applies to GCC :-)
>>> - are named in a way that directly reflects their C herritage
>
>
> What we're trying to do is getting away from the (dangerous) C
> practice of allocating structures by casting around void pointers
> to raw memory blocks.
Right, and the above achieved that goal, and using a naming convention
that is very familar to the C programmer.
The bottom line is that there's no "right" answer here.
> The libcpp macros for type-safe memory allocation resemble C++-style
> memory allocation, hence the new/delete names.
> (Actually, C++'s new and delete would also perform construction
> and destruction, which we can't possibly do in C).
So lets (as in GDB, GCC and BINUTILS) stop beating about the bush and
accept C++ (and yes I hate C++).
Lets add these to a GCC(?) specific include/ header. That way projects
that want those macros can.
Andrew
next prev parent reply other threads:[~2004-06-28 15:43 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 [this message]
2004-06-28 18:27 ` Bernardo Innocenti
2004-06-28 18:52 ` Joseph S. Myers
2004-07-01 7:18 ` Bernardo Innocenti
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=40E03CB7.1060500@gnu.org \
--to=cagney@gnu.org \
--cc=bernie@develer.com \
--cc=binutils@sources.redhat.com \
--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