git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 07/14] parse-options: allow ll_callback with OPTION_CALLBACK

From
Duy Nguyen <pclouds@gmail.com>
Date
Apr 16, 2019, 08:52 UTC
Message-ID
<CACsJy8DDKuK5VYhh0GNYSJK1_y3MZgK5Vcq99N4jYcusVFnvQQ@mail.gmail.com>
In-Reply-To
<02d2a828-b191-9d9a-7422-d76cdca69ef1@gmail.com>
On Mon, Apr 15, 2019 at 9:06 PM Derrick Stolee <stolee@gmail.com> wrote:
Show 20 quoted lines
>
> On 1/26/2019 7:35 PM, Nguyễn Thái Ngọc Duy wrote:
> > @@ -238,7 +249,10 @@ static enum parse_opt_result parse_short_opt(struct parse_opt_ctx_t *p,
> >                       len++;
> >               arg = xmemdupz(p->opt, len);
> >               p->opt = p->opt[len] ? p->opt + len : NULL;
> > -             rc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0;
> > +             if (numopt->callback)
> > +                     rc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0;
> > +             else
> > +                     rc = (*numopt->ll_callback)(p, numopt, arg, 0);
> >               free(arg);
> >               return rc;
> >       }
>
> Hi Duy,
>
> This "else" condition is unreachable. This block is only hit when we have a "-<n>"
> option, using OPT_NUMBER_CALLBACK, which is implemented by filling "callback", never
> "ll_callback".

It does not mean ll_callback cannot be used in the future though. We have three options

1. drop the else clause
2. replace with "else BUG();"
3. implement proper else clause

Option #1 to me sounds wrong. If you don't support something, yell up. Silently ignoring it only makes it harder to track down to this unsupported location when it becomes reachable, however unlikely that is.

Which leaves options #2 and #3. If you think this one line is risky enough, I'll send a patch to replace it with BUG().

> I recommend reverting this diff segment, but please let me know if I'm missing something.
>
> Thanks,
> -Stolee
-- 
Duy
Previous: Derrick StoleeNext: Derrick Stolee
Message 10 of 19 in “nd/diff-parseopt part 1”
  1. 00/14 nd/diff-parseopt part 1Nguyễn Thái Ngọc Duy, Jan 27, 2019
  2. 01/14 parse-options.h: remove extern on function prototypesNguyễn Thái Ngọc Duy, Jan 27, 2019
  3. 02/14 parse-options: add one-shot modeNguyễn Thái Ngọc Duy, Jan 27, 2019
  4. 03/14 parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWNNguyễn Thái Ngọc Duy, Jan 27, 2019
  5. 04/14 parse-options: add OPT_BITOP()Nguyễn Thái Ngọc Duy, Jan 27, 2019
  6. 05/14 parse-options: stop abusing 'callback' for lowlevel callbacksNguyễn Thái Ngọc Duy, Jan 27, 2019
  7. 06/14 parse-options: avoid magic return codesNguyễn Thái Ngọc Duy, Jan 27, 2019
  8. 07/14 parse-options: allow ll_callback with OPTION_CALLBACKNguyễn Thái Ngọc Duy, Jan 27, 2019
  9. Derrick StoleeApr 15, 2019
  10. Duy NguyenApr 16, 2019
  11. Derrick StoleeApr 16, 2019
  12. 08/14 diff.h: keep forward struct declarations sortedNguyễn Thái Ngọc Duy, Jan 27, 2019
  13. 09/14 diff.h: avoid bit fields in struct diff_flagsNguyễn Thái Ngọc Duy, Jan 27, 2019
  14. 10/14 diff.c: prepare to use parse_options() for parsingNguyễn Thái Ngọc Duy, Jan 27, 2019
  15. 11/14 diff.c: convert -u|-p|--patchNguyễn Thái Ngọc Duy, Jan 27, 2019
  16. 12/14 diff.c: convert -U|--unifiedNguyễn Thái Ngọc Duy, Jan 27, 2019
  17. 13/14 diff.c: convert -W|--[no-]function-contextNguyễn Thái Ngọc Duy, Jan 27, 2019
  18. 14/14 diff.c: convert --rawNguyễn Thái Ngọc Duy, Jan 27, 2019
  19. Junio C HamanoJan 28, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.