Merge branch 'mr/opt-set-ptr'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2014 19:00:16 +0000 (12:00 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2014 19:00:17 +0000 (12:00 -0700)
OPT_SET_PTR() implementation was broken on IL32P64 platforms;
it turns out that the macro is not used by any real user.

* mr/opt-set-ptr:
parse-options: remove unused OPT_SET_PTR
parse-options: add cast to correct pointer type to OPT_SET_PTR
MSVC: fix t0040-parse-options crash

1  2 
parse-options.c
parse-options.h
diff --combined parse-options.c
index c81d3a06550a1015ab0f4f7284bb48dce0293ab2,245bf3d6f31108d3ecea306143d217565cf2a84c..b536896f2689dee23afae7d3a169c065592aaabe
@@@ -127,10 -127,6 +127,6 @@@ static int get_value(struct parse_opt_c
                *(int *)opt->value = opt->defval;
                return 0;
  
-       case OPTION_SET_PTR:
-               *(void **)opt->value = unset ? NULL : (void *)opt->defval;
-               return 0;
        case OPTION_STRING:
                if (unset)
                        *(const char **)opt->value = NULL;
@@@ -223,10 -219,13 +219,10 @@@ static int parse_long_opt(struct parse_
                            const struct option *options)
  {
        const struct option *all_opts = options;
 -      const char *arg_end = strchr(arg, '=');
 +      const char *arg_end = strchrnul(arg, '=');
        const struct option *abbrev_option = NULL, *ambiguous_option = NULL;
        int abbrev_flags = 0, ambiguous_flags = 0;
  
 -      if (!arg_end)
 -              arg_end = arg + strlen(arg);
 -
        for (; options->type != OPTION_END; options++) {
                const char *rest, *long_name = options->long_name;
                int flags = 0, opt_flags = 0;
@@@ -367,7 -366,6 +363,6 @@@ static void parse_options_check(const s
                case OPTION_BIT:
                case OPTION_NEGBIT:
                case OPTION_SET_INT:
-               case OPTION_SET_PTR:
                case OPTION_NUMBER:
                        if ((opts->flags & PARSE_OPT_OPTARG) ||
                            !(opts->flags & PARSE_OPT_NOARG))
                default:
                        ; /* ok. (usually accepts an argument) */
                }
 +              if (opts->argh &&
 +                  strcspn(opts->argh, " _") != strlen(opts->argh))
 +                      err |= optbug(opts, "multi-word argh should use dash to separate words");
        }
        if (err)
                exit(128);
diff --combined parse-options.h
index 8fa02dc9a947b9bc56f929b81a71f122f2457dc1,dd46f884226bcc675ff796b64585c3f17fc60fd2..3189676695bc173cf6475445cfb6365d08a37906
@@@ -12,7 -12,6 +12,6 @@@ enum parse_opt_type 
        OPTION_NEGBIT,
        OPTION_COUNTUP,
        OPTION_SET_INT,
-       OPTION_SET_PTR,
        OPTION_CMDMODE,
        /* options with arguments (usually) */
        OPTION_STRING,
@@@ -96,7 -95,7 +95,7 @@@ typedef int parse_opt_ll_cb(struct pars
   *
   * `defval`::
   *   default value to fill (*->value) with for PARSE_OPT_OPTARG.
-  *   OPTION_{BIT,SET_INT,SET_PTR} store the {mask,integer,pointer} to put in
+  *   OPTION_{BIT,SET_INT} store the {mask,integer,pointer} to put in
   *   the value when met.
   *   CALLBACKS can use it like they want.
   */
@@@ -128,8 -127,6 +127,6 @@@ struct option 
  #define OPT_BOOL(s, l, v, h)        OPT_SET_INT(s, l, v, h, 1)
  #define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \
                                      (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
- #define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, \
-                                     (h), PARSE_OPT_NOARG, NULL, (p) }
  #define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
                                      (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }
  #define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
        { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0,    \
          parse_opt_approxidate_cb }
  #define OPT_EXPIRY_DATE(s, l, v, h) \
 -      { OPTION_CALLBACK, (s), (l), (v), N_("expiry date"),(h), 0,     \
 +      { OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0,     \
          parse_opt_expiry_date_cb }
  #define OPT_CALLBACK(s, l, v, a, h, f) \
        { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }