perf options: Type check all the remaining OPT_ variants

OPT_SET_INT was renamed to OPT_SET_UINT since the only use in these
tools is to set something that has an enum type, that is builtin
compatible with unsigned int.

Several string constifications were done to make OPT_STRING require a
const char * type.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 8035458f
...@@ -95,7 +95,7 @@ static void dump_suites(int subsys_index) ...@@ -95,7 +95,7 @@ static void dump_suites(int subsys_index)
return; return;
} }
static char *bench_format_str; static const char *bench_format_str;
int bench_format = BENCH_FORMAT_DEFAULT; int bench_format = BENCH_FORMAT_DEFAULT;
static const struct option bench_options[] = { static const struct option bench_options[] = {
...@@ -126,7 +126,7 @@ static void print_usage(void) ...@@ -126,7 +126,7 @@ static void print_usage(void)
printf("\n"); printf("\n");
} }
static int bench_str2int(char *str) static int bench_str2int(const char *str)
{ {
if (!str) if (!str)
return BENCH_FORMAT_DEFAULT; return BENCH_FORMAT_DEFAULT;
......
...@@ -33,10 +33,10 @@ static bool show_all = false; ...@@ -33,10 +33,10 @@ static bool show_all = false;
static enum help_format help_format = HELP_FORMAT_MAN; static enum help_format help_format = HELP_FORMAT_MAN;
static struct option builtin_help_options[] = { static struct option builtin_help_options[] = {
OPT_BOOLEAN('a', "all", &show_all, "print all available commands"), OPT_BOOLEAN('a', "all", &show_all, "print all available commands"),
OPT_SET_INT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN), OPT_SET_UINT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN),
OPT_SET_INT('w', "web", &help_format, "show manual in web browser", OPT_SET_UINT('w', "web", &help_format, "show manual in web browser",
HELP_FORMAT_WEB), HELP_FORMAT_WEB),
OPT_SET_INT('i', "info", &help_format, "show info page", OPT_SET_UINT('i', "info", &help_format, "show info page",
HELP_FORMAT_INFO), HELP_FORMAT_INFO),
OPT_END(), OPT_END(),
}; };
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <pthread.h> #include <pthread.h>
#include <math.h> #include <math.h>
static char *file_name; static const char *file_name;
static char name_buffer[256]; static char name_buffer[256];
bool perf_host = 1; bool perf_host = 1;
......
...@@ -39,8 +39,8 @@ static bool dont_use_callchains; ...@@ -39,8 +39,8 @@ static bool dont_use_callchains;
static bool show_threads; static bool show_threads;
static struct perf_read_values show_threads_values; static struct perf_read_values show_threads_values;
static char default_pretty_printing_style[] = "normal"; static const char default_pretty_printing_style[] = "normal";
static char *pretty_printing_style = default_pretty_printing_style; static const char *pretty_printing_style = default_pretty_printing_style;
static char callchain_default_opt[] = "fractal,0.5"; static char callchain_default_opt[] = "fractal,0.5";
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
static char const *input_name = "perf.data"; static char const *input_name = "perf.data";
static char default_sort_order[] = "avg, max, switch, runtime"; static char default_sort_order[] = "avg, max, switch, runtime";
static char *sort_order = default_sort_order; static const char *sort_order = default_sort_order;
static int profile_cpu = -1; static int profile_cpu = -1;
......
...@@ -96,7 +96,7 @@ struct source_line { ...@@ -96,7 +96,7 @@ struct source_line {
struct source_line *next; struct source_line *next;
}; };
static char *sym_filter = NULL; static const char *sym_filter = NULL;
struct sym_entry *sym_filter_entry = NULL; struct sym_entry *sym_filter_entry = NULL;
struct sym_entry *sym_filter_entry_sched = NULL; struct sym_entry *sym_filter_entry_sched = NULL;
static int sym_pcnt_filter = 5; static int sym_pcnt_filter = 5;
......
...@@ -662,7 +662,7 @@ size_t hists__fprintf(struct hists *self, struct hists *pair, ...@@ -662,7 +662,7 @@ size_t hists__fprintf(struct hists *self, struct hists *pair,
long displacement = 0; long displacement = 0;
unsigned int width; unsigned int width;
const char *sep = symbol_conf.field_sep; const char *sep = symbol_conf.field_sep;
char *col_width = symbol_conf.col_width_list_str; const char *col_width = symbol_conf.col_width_list_str;
init_rem_hits(); init_rem_hits();
......
...@@ -51,7 +51,7 @@ static int get_value(struct parse_opt_ctx_t *p, ...@@ -51,7 +51,7 @@ static int get_value(struct parse_opt_ctx_t *p,
case OPTION_BOOLEAN: case OPTION_BOOLEAN:
case OPTION_INCR: case OPTION_INCR:
case OPTION_BIT: case OPTION_BIT:
case OPTION_SET_INT: case OPTION_SET_UINT:
case OPTION_SET_PTR: case OPTION_SET_PTR:
return opterror(opt, "takes no value", flags); return opterror(opt, "takes no value", flags);
case OPTION_END: case OPTION_END:
...@@ -83,8 +83,8 @@ static int get_value(struct parse_opt_ctx_t *p, ...@@ -83,8 +83,8 @@ static int get_value(struct parse_opt_ctx_t *p,
*(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
return 0; return 0;
case OPTION_SET_INT: case OPTION_SET_UINT:
*(int *)opt->value = unset ? 0 : opt->defval; *(unsigned int *)opt->value = unset ? 0 : opt->defval;
return 0; return 0;
case OPTION_SET_PTR: case OPTION_SET_PTR:
...@@ -515,13 +515,13 @@ int usage_with_options_internal(const char * const *usagestr, ...@@ -515,13 +515,13 @@ int usage_with_options_internal(const char * const *usagestr,
pos += fprintf(stderr, " ..."); pos += fprintf(stderr, " ...");
} }
break; break;
default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */ default: /* OPTION_{BIT,BOOLEAN,SET_UINT,SET_PTR} */
case OPTION_END: case OPTION_END:
case OPTION_GROUP: case OPTION_GROUP:
case OPTION_BIT: case OPTION_BIT:
case OPTION_BOOLEAN: case OPTION_BOOLEAN:
case OPTION_INCR: case OPTION_INCR:
case OPTION_SET_INT: case OPTION_SET_UINT:
case OPTION_SET_PTR: case OPTION_SET_PTR:
break; break;
} }
......
...@@ -13,7 +13,7 @@ enum parse_opt_type { ...@@ -13,7 +13,7 @@ enum parse_opt_type {
OPTION_BIT, OPTION_BIT,
OPTION_BOOLEAN, OPTION_BOOLEAN,
OPTION_INCR, OPTION_INCR,
OPTION_SET_INT, OPTION_SET_UINT,
OPTION_SET_PTR, OPTION_SET_PTR,
/* options with arguments (usually) */ /* options with arguments (usually) */
OPTION_STRING, OPTION_STRING,
...@@ -79,7 +79,7 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset); ...@@ -79,7 +79,7 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
* *
* `defval`:: * `defval`::
* default value to fill (*->value) with for PARSE_OPT_OPTARG. * 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_UINT,SET_PTR} store the {mask,integer,pointer} to put in
* the value when met. * the value when met.
* CALLBACKS can use it like they want. * CALLBACKS can use it like they want.
*/ */
...@@ -101,16 +101,16 @@ struct option { ...@@ -101,16 +101,16 @@ struct option {
#define OPT_END() { .type = OPTION_END } #define OPT_END() { .type = OPTION_END }
#define OPT_ARGUMENT(l, h) { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) } #define OPT_ARGUMENT(l, h) { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) }
#define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) }
#define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (b) } #define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h), .defval = (b) }
#define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h) } #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h) }
#define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } #define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) }
#define OPT_SET_INT(s, l, v, h, i) { .type = OPTION_SET_INT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (i) } #define OPT_SET_UINT(s, l, v, h, i) { .type = OPTION_SET_UINT, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h), .defval = (i) }
#define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) }
#define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) }
#define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) } #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) }
#define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) }
#define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } #define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) }
#define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) } #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h) }
#define OPT_DATE(s, l, v, h) \ #define OPT_DATE(s, l, v, h) \
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }
#define OPT_CALLBACK(s, l, v, a, h, f) \ #define OPT_CALLBACK(s, l, v, a, h, f) \
......
#include "sort.h" #include "sort.h"
regex_t parent_regex; regex_t parent_regex;
char default_parent_pattern[] = "^sys_|^do_page_fault"; const char default_parent_pattern[] = "^sys_|^do_page_fault";
char *parent_pattern = default_parent_pattern; const char *parent_pattern = default_parent_pattern;
char default_sort_order[] = "comm,dso,symbol"; const char default_sort_order[] = "comm,dso,symbol";
char *sort_order = default_sort_order; const char *sort_order = default_sort_order;
int sort__need_collapse = 0; int sort__need_collapse = 0;
int sort__has_parent = 0; int sort__has_parent = 0;
......
...@@ -25,10 +25,10 @@ ...@@ -25,10 +25,10 @@
#include "sort.h" #include "sort.h"
extern regex_t parent_regex; extern regex_t parent_regex;
extern char *sort_order; extern const char *sort_order;
extern char default_parent_pattern[]; extern const char default_parent_pattern[];
extern char *parent_pattern; extern const char *parent_pattern;
extern char default_sort_order[]; extern const char default_sort_order[];
extern int sort__need_collapse; extern int sort__need_collapse;
extern int sort__has_parent; extern int sort__has_parent;
extern char *field_sep; extern char *field_sep;
......
...@@ -78,7 +78,7 @@ struct symbol_conf { ...@@ -78,7 +78,7 @@ struct symbol_conf {
*default_guest_kallsyms, *default_guest_kallsyms,
*default_guest_modules; *default_guest_modules;
const char *guestmount; const char *guestmount;
char *dso_list_str, const char *dso_list_str,
*comm_list_str, *comm_list_str,
*sym_list_str, *sym_list_str,
*col_width_list_str; *col_width_list_str;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册