On Sun, Oct 16, 2016 at 12:06:02PM +0200, René Scharfe wrote: > > Yeah, this NULL computation is pretty nasty. I recall trying to get rid > > of it, but I think it is impossible to do so portably while still using > > the generic xalloc_flex() helper. > > The only way I see is to pass the type to the macro explicitly (because > typeof is an extention), and that would make call sites ugly.
Yep, exactly. I really wish we could use typeof(); there are a couple things that could be made less error-prone and ugly. But it's not even a matter of C99; it's a GNU-ism, so I don't think we are even close to having support for it everywhere. > > This looks correct. I wondered at first why you bothered with > > flex_array_len, but it is to avoid evaluating the "len" parameter > > multiple times. > > Right; we could drop that feature of the original macros and require > users to pass length expressions that don't have side effects -- all of > them already do that anyway. But let's keep it in this round; it just > costs one extra line. Oh, I think it's worth keeping forever, if only because it makes the macro interface have one fewer gotcha. Spending a line of code on that is OK with me. > > Now that xalloc_flex() has only this one caller remaining, perhaps it > > should just be inlined here, too, for simplicity. > > -- >8 -- > Subject: [PATCH 2/1] inline xalloc_flex() into FLEXPTR_ALLOC_MEM > > Allocate and copy directly in FLEXPTR_ALLOC_MEM and remove the now > unused helper function xalloc_flex(). The resulting code is shorter > and the offset arithmetic is a bit simpler. Looks good. Thanks for following up. -Peff