Skip to content

Commit b389e04

Browse files
committed
Merge branch 'mr/opt-set-ptr'
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
2 parents ed15e20 + 20d1c65 commit b389e04

File tree

5 files changed

+4
-19
lines changed

5 files changed

+4
-19
lines changed

Documentation/technical/api-parse-options.txt

-4
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ There are some macros to easily define options:
160160
`int_var` is set to `integer` with `--option`, and
161161
reset to zero with `--no-option`.
162162

163-
`OPT_SET_PTR(short, long, &ptr_var, description, ptr)`::
164-
Introduce a boolean option.
165-
If used, set `ptr_var` to `ptr`.
166-
167163
`OPT_STRING(short, long, &str_var, arg_str, description)`::
168164
Introduce an option with string argument.
169165
The string argument is put into `str_var`.

parse-options.c

-5
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ static int get_value(struct parse_opt_ctx_t *p,
127127
*(int *)opt->value = opt->defval;
128128
return 0;
129129

130-
case OPTION_SET_PTR:
131-
*(void **)opt->value = unset ? NULL : (void *)opt->defval;
132-
return 0;
133-
134130
case OPTION_STRING:
135131
if (unset)
136132
*(const char **)opt->value = NULL;
@@ -367,7 +363,6 @@ static void parse_options_check(const struct option *opts)
367363
case OPTION_BIT:
368364
case OPTION_NEGBIT:
369365
case OPTION_SET_INT:
370-
case OPTION_SET_PTR:
371366
case OPTION_NUMBER:
372367
if ((opts->flags & PARSE_OPT_OPTARG) ||
373368
!(opts->flags & PARSE_OPT_NOARG))

parse-options.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ enum parse_opt_type {
1212
OPTION_NEGBIT,
1313
OPTION_COUNTUP,
1414
OPTION_SET_INT,
15-
OPTION_SET_PTR,
1615
OPTION_CMDMODE,
1716
/* options with arguments (usually) */
1817
OPTION_STRING,
@@ -96,7 +95,7 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
9695
*
9796
* `defval`::
9897
* default value to fill (*->value) with for PARSE_OPT_OPTARG.
99-
* OPTION_{BIT,SET_INT,SET_PTR} store the {mask,integer,pointer} to put in
98+
* OPTION_{BIT,SET_INT} store the {mask,integer,pointer} to put in
10099
* the value when met.
101100
* CALLBACKS can use it like they want.
102101
*/
@@ -128,8 +127,6 @@ struct option {
128127
#define OPT_BOOL(s, l, v, h) OPT_SET_INT(s, l, v, h, 1)
129128
#define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \
130129
(h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
131-
#define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, \
132-
(h), PARSE_OPT_NOARG, NULL, (p) }
133130
#define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
134131
(h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }
135132
#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }

t/t0040-parse-options.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ String options
3030
--string2 <str> get another string
3131
--st <st> get another string (pervert ordering)
3232
-o <str> get another string
33-
--default-string set string to default
3433
--list <str> add str to list
3534
3635
Magic arguments
@@ -293,7 +292,7 @@ cat > expect <<EOF
293292
boolean: 0
294293
integer: 0
295294
timestamp: 1
296-
string: default
295+
string: (not set)
297296
abbrev: 7
298297
verbose: 0
299298
quiet: yes
@@ -302,8 +301,8 @@ file: (not set)
302301
arg 00: foo
303302
EOF
304303

305-
test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
306-
test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \
304+
test_expect_success 'OPT_DATE() works' '
305+
test-parse-options -t "1970-01-01 00:00:01 +0000" \
307306
foo -q > output 2> output.err &&
308307
test_must_be_empty output.err &&
309308
test_cmp expect output

test-parse-options.c

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ int main(int argc, char **argv)
5959
OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
6060
OPT_STRING('o', NULL, &string, "str", "get another string"),
6161
OPT_NOOP_NOARG(0, "obsolete"),
62-
OPT_SET_PTR(0, "default-string", &string,
63-
"set string to default", (unsigned long)"default"),
6462
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
6563
OPT_GROUP("Magic arguments"),
6664
OPT_ARGUMENT("quux", "means --quux"),

0 commit comments

Comments
 (0)