Skip to content

Commit 6425e3b

Browse files
committed
kconfig: add const qualifiers to several function arguments
Clarify that the given structures are not modified. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 8bfd6f0 commit 6425e3b

File tree

8 files changed

+40
-36
lines changed

8 files changed

+40
-36
lines changed

scripts/kconfig/expr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ static int expr_compare_type(enum expr_type t1, enum expr_type t2)
10961096
return 0;
10971097
}
10981098

1099-
void expr_print(struct expr *e,
1099+
void expr_print(const struct expr *e,
11001100
void (*fn)(void *, struct symbol *, const char *),
11011101
void *data, int prevtoken)
11021102
{
@@ -1221,7 +1221,7 @@ static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *s
12211221
str_printf(gs, " [=%s]", sym_str);
12221222
}
12231223

1224-
void expr_gstr_print(struct expr *e, struct gstr *gs)
1224+
void expr_gstr_print(const struct expr *e, struct gstr *gs)
12251225
{
12261226
expr_print(e, expr_print_gstr_helper, gs, E_NONE);
12271227
}

scripts/kconfig/expr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symb
291291

292292
void expr_fprint(struct expr *e, FILE *out);
293293
struct gstr; /* forward */
294-
void expr_gstr_print(struct expr *e, struct gstr *gs);
294+
void expr_gstr_print(const struct expr *e, struct gstr *gs);
295295
void expr_gstr_print_revdep(struct expr *e, struct gstr *gs,
296296
tristate pr_type, const char *title);
297297

298-
static inline int expr_is_yes(struct expr *e)
298+
static inline int expr_is_yes(const struct expr *e)
299299
{
300300
return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes);
301301
}

scripts/kconfig/lkc.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct gstr str_new(void);
7575
void str_free(struct gstr *gs);
7676
void str_append(struct gstr *gs, const char *s);
7777
void str_printf(struct gstr *gs, const char *fmt, ...);
78-
char *str_get(struct gstr *gs);
78+
char *str_get(const struct gstr *gs);
7979

8080
/* menu.c */
8181
struct menu *menu_next(struct menu *menu, struct menu *root);
@@ -84,13 +84,14 @@ struct menu *menu_next(struct menu *menu, struct menu *root);
8484
#define menu_for_each_entry(menu) \
8585
menu_for_each_sub_entry(menu, &rootmenu)
8686
void _menu_init(void);
87-
void menu_warn(struct menu *menu, const char *fmt, ...);
87+
void menu_warn(const struct menu *menu, const char *fmt, ...);
8888
struct menu *menu_add_menu(void);
8989
void menu_end_menu(void);
9090
void menu_add_entry(struct symbol *sym);
9191
void menu_add_dep(struct expr *dep);
9292
void menu_add_visibility(struct expr *dep);
93-
struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
93+
struct property *menu_add_prompt(enum prop_type type, const char *prompt,
94+
struct expr *dep);
9495
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
9596
void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
9697
void menu_finalize(void);
@@ -100,8 +101,8 @@ extern struct menu rootmenu;
100101

101102
bool menu_is_empty(struct menu *menu);
102103
bool menu_is_visible(struct menu *menu);
103-
bool menu_has_prompt(struct menu *menu);
104-
const char *menu_get_prompt(struct menu *menu);
104+
bool menu_has_prompt(const struct menu *menu);
105+
const char *menu_get_prompt(const struct menu *menu);
105106
struct menu *menu_get_parent_menu(struct menu *menu);
106107
int get_jump_key_char(void);
107108
struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head);
@@ -114,25 +115,25 @@ struct symbol *sym_calc_choice(struct menu *choice);
114115
struct property *sym_get_range_prop(struct symbol *sym);
115116
const char *sym_get_string_default(struct symbol *sym);
116117
struct symbol *sym_check_deps(struct symbol *sym);
117-
struct symbol *prop_get_symbol(struct property *prop);
118+
struct symbol *prop_get_symbol(const struct property *prop);
118119

119-
static inline tristate sym_get_tristate_value(struct symbol *sym)
120+
static inline tristate sym_get_tristate_value(const struct symbol *sym)
120121
{
121122
return sym->curr.tri;
122123
}
123124

124-
static inline bool sym_is_choice(struct symbol *sym)
125+
static inline bool sym_is_choice(const struct symbol *sym)
125126
{
126127
/* A choice is a symbol with no name */
127128
return sym->name == NULL;
128129
}
129130

130-
static inline bool sym_is_choice_value(struct symbol *sym)
131+
static inline bool sym_is_choice_value(const struct symbol *sym)
131132
{
132133
return sym->flags & SYMBOL_CHOICEVAL ? true : false;
133134
}
134135

135-
static inline bool sym_has_value(struct symbol *sym)
136+
static inline bool sym_has_value(const struct symbol *sym)
136137
{
137138
return sym->flags & SYMBOL_DEF_USER ? true : false;
138139
}

scripts/kconfig/lkc_proto.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,23 @@ struct symbol ** sym_re_search(const char *pattern);
2525
const char * sym_type_name(enum symbol_type type);
2626
void sym_calc_value(struct symbol *sym);
2727
bool sym_dep_errors(void);
28-
enum symbol_type sym_get_type(struct symbol *sym);
29-
bool sym_tristate_within_range(struct symbol *sym,tristate tri);
28+
enum symbol_type sym_get_type(const struct symbol *sym);
29+
bool sym_tristate_within_range(const struct symbol *sym, tristate tri);
3030
bool sym_set_tristate_value(struct symbol *sym,tristate tri);
3131
void choice_set_value(struct menu *choice, struct symbol *sym);
3232
tristate sym_toggle_tristate_value(struct symbol *sym);
3333
bool sym_string_valid(struct symbol *sym, const char *newval);
3434
bool sym_string_within_range(struct symbol *sym, const char *str);
3535
bool sym_set_string_value(struct symbol *sym, const char *newval);
36-
bool sym_is_changeable(struct symbol *sym);
37-
struct menu *sym_get_choice_menu(struct symbol *sym);
36+
bool sym_is_changeable(const struct symbol *sym);
37+
struct menu *sym_get_choice_menu(const struct symbol *sym);
3838
const char * sym_get_string_value(struct symbol *sym);
3939

4040
const char * prop_get_type_name(enum prop_type type);
4141

4242
/* expr.c */
43-
void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken);
43+
void expr_print(const struct expr *e,
44+
void (*fn)(void *, struct symbol *, const char *),
45+
void *data, int prevtoken);
4446

4547
#endif /* LKC_PROTO_H */

scripts/kconfig/menu.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct menu *menu_next(struct menu *menu, struct menu *root)
3838
return menu->next;
3939
}
4040

41-
void menu_warn(struct menu *menu, const char *fmt, ...)
41+
void menu_warn(const struct menu *menu, const char *fmt, ...)
4242
{
4343
va_list ap;
4444
va_start(ap, fmt);
@@ -48,7 +48,7 @@ void menu_warn(struct menu *menu, const char *fmt, ...)
4848
va_end(ap);
4949
}
5050

51-
static void prop_warn(struct property *prop, const char *fmt, ...)
51+
static void prop_warn(const struct property *prop, const char *fmt, ...)
5252
{
5353
va_list ap;
5454
va_start(ap, fmt);
@@ -175,7 +175,7 @@ static struct property *menu_add_prop(enum prop_type type, struct expr *expr,
175175
return prop;
176176
}
177177

178-
struct property *menu_add_prompt(enum prop_type type, char *prompt,
178+
struct property *menu_add_prompt(enum prop_type type, const char *prompt,
179179
struct expr *dep)
180180
{
181181
struct property *prop = menu_add_prop(type, NULL, dep);
@@ -527,7 +527,7 @@ void menu_finalize(void)
527527
_menu_finalize(&rootmenu, false);
528528
}
529529

530-
bool menu_has_prompt(struct menu *menu)
530+
bool menu_has_prompt(const struct menu *menu)
531531
{
532532
if (!menu->prompt)
533533
return false;
@@ -573,7 +573,7 @@ bool menu_is_visible(struct menu *menu)
573573
return visible != no;
574574
}
575575

576-
const char *menu_get_prompt(struct menu *menu)
576+
const char *menu_get_prompt(const struct menu *menu)
577577
{
578578
if (menu->prompt)
579579
return menu->prompt->text;
@@ -594,13 +594,14 @@ struct menu *menu_get_parent_menu(struct menu *menu)
594594
return menu;
595595
}
596596

597-
static void get_def_str(struct gstr *r, struct menu *menu)
597+
static void get_def_str(struct gstr *r, const struct menu *menu)
598598
{
599599
str_printf(r, "Defined at %s:%d\n",
600600
menu->filename, menu->lineno);
601601
}
602602

603-
static void get_dep_str(struct gstr *r, struct expr *expr, const char *prefix)
603+
static void get_dep_str(struct gstr *r, const struct expr *expr,
604+
const char *prefix)
604605
{
605606
if (!expr_is_yes(expr)) {
606607
str_append(r, prefix);

scripts/kconfig/parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ assign_val:
489489
*
490490
* Return: -1 if an error is found, 0 otherwise.
491491
*/
492-
static int choice_check_sanity(struct menu *menu)
492+
static int choice_check_sanity(const struct menu *menu)
493493
{
494494
struct property *prop;
495495
int ret = 0;
@@ -644,7 +644,7 @@ static void print_quoted_string(FILE *out, const char *str)
644644
putc('"', out);
645645
}
646646

647-
static void print_symbol(FILE *out, struct menu *menu)
647+
static void print_symbol(FILE *out, const struct menu *menu)
648648
{
649649
struct symbol *sym = menu->sym;
650650
struct property *prop;

scripts/kconfig/symbol.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct symbol *modules_sym;
4040
static tristate modules_val;
4141
static int sym_warnings;
4242

43-
enum symbol_type sym_get_type(struct symbol *sym)
43+
enum symbol_type sym_get_type(const struct symbol *sym)
4444
{
4545
enum symbol_type type = sym->type;
4646

@@ -75,7 +75,7 @@ const char *sym_type_name(enum symbol_type type)
7575
*
7676
* Return: a choice menu if this function is called against a choice member.
7777
*/
78-
struct menu *sym_get_choice_menu(struct symbol *sym)
78+
struct menu *sym_get_choice_menu(const struct symbol *sym)
7979
{
8080
struct menu *menu = NULL;
8181
struct menu *m;
@@ -355,7 +355,7 @@ struct symbol *sym_calc_choice(struct menu *choice)
355355
return res;
356356
}
357357

358-
static void sym_warn_unmet_dep(struct symbol *sym)
358+
static void sym_warn_unmet_dep(const struct symbol *sym)
359359
{
360360
struct gstr gs = str_new();
361361

@@ -521,7 +521,7 @@ void sym_clear_all_valid(void)
521521
sym_calc_value(modules_sym);
522522
}
523523

524-
bool sym_tristate_within_range(struct symbol *sym, tristate val)
524+
bool sym_tristate_within_range(const struct symbol *sym, tristate val)
525525
{
526526
int type = sym_get_type(sym);
527527

@@ -866,7 +866,7 @@ const char *sym_get_string_value(struct symbol *sym)
866866
return (const char *)sym->curr.val;
867867
}
868868

869-
bool sym_is_changeable(struct symbol *sym)
869+
bool sym_is_changeable(const struct symbol *sym)
870870
{
871871
return !sym_is_choice(sym) && sym->visible > sym->rev_dep.tri;
872872
}
@@ -1150,7 +1150,7 @@ static void sym_check_print_recursive(struct symbol *last_sym)
11501150
dep_stack_remove();
11511151
}
11521152

1153-
static struct symbol *sym_check_expr_deps(struct expr *e)
1153+
static struct symbol *sym_check_expr_deps(const struct expr *e)
11541154
{
11551155
struct symbol *sym;
11561156

@@ -1309,7 +1309,7 @@ struct symbol *sym_check_deps(struct symbol *sym)
13091309
return sym2;
13101310
}
13111311

1312-
struct symbol *prop_get_symbol(struct property *prop)
1312+
struct symbol *prop_get_symbol(const struct property *prop)
13131313
{
13141314
if (prop->expr && prop->expr->type == E_SYMBOL)
13151315
return prop->expr->left.sym;

scripts/kconfig/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void str_printf(struct gstr *gs, const char *fmt, ...)
9898
}
9999

100100
/* Retrieve value of growable string */
101-
char *str_get(struct gstr *gs)
101+
char *str_get(const struct gstr *gs)
102102
{
103103
return gs->s;
104104
}

0 commit comments

Comments
 (0)