[PATCH 02/40] Eliminate make_cleanup_obstack_free, introduce auto_obstack
Pedro Alves
palves@redhat.com
Wed Jun 28 14:39:00 GMT 2017
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
More information about the Gdb-patches
mailing list