[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/3] maint: simplify parse-gram.y
From: |
Jim Meyering |
Subject: |
Re: [PATCH 2/3] maint: simplify parse-gram.y |
Date: |
Sun, 06 May 2012 09:31:16 +0200 |
Akim Demaille wrote:
> This is perfect, push whenever you want.
>
> Le 5 mai 2012 à 15:26, Jim Meyering a écrit :
>
>> + size_t name_len = strspn (name_start, alphanum);
>> + char *name = xmemdup (name_start, name_len + 1);
>> name[name_len] = '\0';
>
> For my education, you prefer memdup to strndup because of
> of the inner strnlen of the latter, right? It makes plenty
Precisely.
> of sense, but this split memdup + '=0' is not nice looking.
> It would be cleaner to have say xmemdup0 which would add
> this 0.
>
> Actually, I just grepped xmemdup in gnulib to see if there
> are many such memdup + '=0', and here is what I found:
>
> lib/xmemdup0.c:
> char *
> xmemdup0 (void const *p, size_t s)
> {
> char *result = xcharalloc (s + 1);
> memcpy (result, p, s);
> result[s] = 0;
> return result;
> }
>
> :) So please, make it
>
> {
> char *name = xmemdup0 (name_start, strspn (name_start, alphanum));
> muscle_pair_list_grow (type, decl, name);
> free (name);
> }
Hah! That's even better.
It's not often that one can replace so many lines with just one.
Pushed.
> (I think this is the last time I will bug you with this patch :)
> but looking at the surrounding code, I see that we do not support
> \n in %parse-param, which is not nice, I will make another patch
> on top of yours).
- nuke strncpy, Jim Meyering, 2012/05/03
- [PATCH 1/3] maint: s/strncpy/memcpy/, when equivalent, Jim Meyering, 2012/05/03
- [PATCH 3/3] maint: regen src/parse-gram.[ch], Jim Meyering, 2012/05/03
- [PATCH 2/3] maint: simplify parse-gram.y, Jim Meyering, 2012/05/03
- Re: [PATCH 2/3] maint: simplify parse-gram.y, Akim Demaille, 2012/05/04
- Re: [PATCH 2/3] maint: simplify parse-gram.y, Jim Meyering, 2012/05/04
- Re: [PATCH 2/3] maint: simplify parse-gram.y, Jim Meyering, 2012/05/05
- Re: [PATCH 2/3] maint: simplify parse-gram.y, Akim Demaille, 2012/05/06
- Re: [PATCH 2/3] maint: simplify parse-gram.y,
Jim Meyering <=
- Re: [PATCH 2/3] maint: simplify parse-gram.y, Akim Demaille, 2012/05/06
- Re: [PATCH 2/3] maint: simplify parse-gram.y, Jim Meyering, 2012/05/06
- Re: [PATCH 2/3] maint: simplify parse-gram.y, Akim Demaille, 2012/05/09