This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [libiberty] add obstack macros (was Re: PR #53525 - track-macro-expansion performance regression)
- From: Ian Lance Taylor <iant at google dot com>
- To: Dimitrios Apostolou <jimis at gmx dot net>
- Cc: Dodji Seketeli <dodji at redhat dot com>, gcc-patches at gcc dot gnu dot org, Andrey Belevantsev <abel at ispras dot ru>, DJ Delorie <dj at redhat dot com>, Tom Tromey <tromey at redhat dot com>, Jason Merrill <jason dot merrill at gmail dot com>
- Date: Fri, 3 Aug 2012 17:26:58 -0700
- Subject: Re: [libiberty] add obstack macros (was Re: PR #53525 - track-macro-expansion performance regression)
- References: <alpine.LNX.2.02.1207080847210.4288@localhost.localdomain> <m3mx2wq4kr.fsf@redhat.com> <alpine.LNX.2.02.1207312009120.20463@localhost.localdomain>
> 2012-08-04 Dimitrios Apostolou <jimis@gmx.net>
>
> * libiberty.h
> (XOBDELETE,XOBGROW,XOBGROWVEC,XOBSHRINK,XOBSHRINKVEC): New
> type-safe macros for obstack allocation.
> (XOBFINISH): Renamed argument to PT since it is a pointer to T.
> +/* Type-safe obstack allocator. You must first initialize the obstack with
> + obstack_init() or _obstack_begin().
This should recommend obstack_init, or obstack_begin, but not
_obstack_begin. Also obstack_specify_allocation and
obstack_specify_allocation_with_arg are OK, so really it might be
better not to list the functions, but simply say "You must first
initialization the obstack."
> + T: Type, O: Obstack, N: Number of elements, S: raw Size,
s/Size/size/
> +#define XOBSHRINK(O, T) obstack_blank ((O), -1 * sizeof (T))
> +#define XOBSHRINKVEC(O, T, N) obstack_blank ((O), -1 * sizeof (T) * (N))
These are hard to use safely. I'm not sure we should define them at all.
> +#define XOBFINISH(O, PT) ((PT) obstack_finish ((O)))
For XOBNEW, etc., we use (T *) rather than (PT). Using (PT) seems
error-probe--it's the only use of the obstack with a different type
parameter. Why not use T rather than PT here, and return (T *)?
Ian