This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 02/40] Eliminate make_cleanup_obstack_free, introduce auto_obstack
- From: Pedro Alves <palves at redhat dot com>
- To: Yao Qi <qiyaoltc at gmail dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 28 Jun 2017 15:39:28 +0100
- Subject: Re: [PATCH 02/40] Eliminate make_cleanup_obstack_free, introduce auto_obstack
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E2218C04575B
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E2218C04575B
- References: <1496406158-12663-1-git-send-email-palves@redhat.com> <1496406158-12663-3-git-send-email-palves@redhat.com> <86lgoce6vh.fsf@gmail.com>
On 06/28/2017 11:36 AM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
>
>> +/* An obstack that frees itself on scope exit. */
>> +struct auto_obstack : obstack
>> +{
>> + auto_obstack ()
>> + { obstack_init (this); }
>> +
>> + ~auto_obstack ()
>> + { obstack_free (this, NULL); }
>> +
>> + /* Free all memory in the obstack but leave it valid for further
>> + allocation. */
>> + void clear ()
>> + { obstack_free (this, obstack_base (this)); }
>> +};
>
> Hi Pedro,
> Did you consider "upstream" this to include/obstack.h? so that gcc can
> use it as well.
>
A little, but not very seriously. I did name the type as "auto_"
thinking that that's what GCC folks tend to name their
container/RAII types.
But OTOH, it feel a bit too early to propose that; it feels like
we could do more with extending the auto_obstack API; but OTOH I'm
not sure whether we'll continue to use obstacks directly that much;
I suspect that we may end up with allocators instead, thought
I haven't given that that much thought.
Also, I think that it couldn't be put in include/obstack.h,
since the obstack API requires that you define the
obstack_chunk_alloc/obstack_chunk_free macros (and GCC
defines those differently from us, which would be recipe
for ODR violations).
Also, unfortunately GCC is still C++03, and I didn't want to
paint myself into a corner. :-)
Thanks,
Pedro Alves