Commit 91b69454 authored by Masahiro Yamada's avatar Masahiro Yamada

kconfig: use generic macros to implement symbol hashtable

Use helper macros in hashtable.h for generic hashtable implementation.

We can git rid of the hash head index of for_all_symbols().
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent cc25cfc5
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <errno.h> #include <errno.h>
#include "internal.h"
#include "lkc.h" #include "lkc.h"
static void conf(struct menu *menu); static void conf(struct menu *menu);
...@@ -171,7 +172,7 @@ enum conf_def_mode { ...@@ -171,7 +172,7 @@ enum conf_def_mode {
static bool conf_set_all_new_symbols(enum conf_def_mode mode) static bool conf_set_all_new_symbols(enum conf_def_mode mode)
{ {
struct symbol *sym, *csym; struct symbol *sym, *csym;
int i, cnt; int cnt;
/* /*
* can't go as the default in switch-case below, otherwise gcc whines * can't go as the default in switch-case below, otherwise gcc whines
* about -Wmaybe-uninitialized * about -Wmaybe-uninitialized
...@@ -226,7 +227,7 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) ...@@ -226,7 +227,7 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode)
} }
} }
for_all_symbols(i, sym) { for_all_symbols(sym) {
if (sym_has_value(sym) || sym->flags & SYMBOL_VALID) if (sym_has_value(sym) || sym->flags & SYMBOL_VALID)
continue; continue;
switch (sym_get_type(sym)) { switch (sym_get_type(sym)) {
...@@ -278,14 +279,14 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) ...@@ -278,14 +279,14 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode)
* and the rest to no. * and the rest to no.
*/ */
if (mode != def_random) { if (mode != def_random) {
for_all_symbols(i, csym) { for_all_symbols(csym) {
if ((sym_is_choice(csym) && !sym_has_value(csym)) || if ((sym_is_choice(csym) && !sym_has_value(csym)) ||
sym_is_choice_value(csym)) sym_is_choice_value(csym))
csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES; csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES;
} }
} }
for_all_symbols(i, csym) { for_all_symbols(csym) {
if (sym_has_value(csym) || !sym_is_choice(csym)) if (sym_has_value(csym) || !sym_is_choice(csym))
continue; continue;
...@@ -304,9 +305,8 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) ...@@ -304,9 +305,8 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode)
static void conf_rewrite_tristates(tristate old_val, tristate new_val) static void conf_rewrite_tristates(tristate old_val, tristate new_val)
{ {
struct symbol *sym; struct symbol *sym;
int i;
for_all_symbols(i, sym) { for_all_symbols(sym) {
if (sym_get_type(sym) == S_TRISTATE && if (sym_get_type(sym) == S_TRISTATE &&
sym->def[S_DEF_USER].tri == old_val) sym->def[S_DEF_USER].tri == old_val)
sym->def[S_DEF_USER].tri = new_val; sym->def[S_DEF_USER].tri = new_val;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include "internal.h"
#include "lkc.h" #include "lkc.h"
struct gstr autoconf_cmd; struct gstr autoconf_cmd;
...@@ -322,7 +323,7 @@ int conf_read_simple(const char *name, int def) ...@@ -322,7 +323,7 @@ int conf_read_simple(const char *name, int def)
size_t line_asize = 0; size_t line_asize = 0;
char *p, *val; char *p, *val;
struct symbol *sym; struct symbol *sym;
int i, def_flags; int def_flags;
const char *warn_unknown, *sym_name; const char *warn_unknown, *sym_name;
warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS"); warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
...@@ -380,7 +381,7 @@ int conf_read_simple(const char *name, int def) ...@@ -380,7 +381,7 @@ int conf_read_simple(const char *name, int def)
conf_warnings = 0; conf_warnings = 0;
def_flags = SYMBOL_DEF << def; def_flags = SYMBOL_DEF << def;
for_all_symbols(i, sym) { for_all_symbols(sym) {
sym->flags |= SYMBOL_CHANGED; sym->flags |= SYMBOL_CHANGED;
sym->flags &= ~(def_flags|SYMBOL_VALID); sym->flags &= ~(def_flags|SYMBOL_VALID);
if (sym_is_choice(sym)) if (sym_is_choice(sym))
...@@ -489,7 +490,6 @@ int conf_read(const char *name) ...@@ -489,7 +490,6 @@ int conf_read(const char *name)
{ {
struct symbol *sym; struct symbol *sym;
int conf_unsaved = 0; int conf_unsaved = 0;
int i;
conf_set_changed(false); conf_set_changed(false);
...@@ -500,7 +500,7 @@ int conf_read(const char *name) ...@@ -500,7 +500,7 @@ int conf_read(const char *name)
sym_calc_value(modules_sym); sym_calc_value(modules_sym);
for_all_symbols(i, sym) { for_all_symbols(sym) {
sym_calc_value(sym); sym_calc_value(sym);
if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE)) if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE))
continue; continue;
...@@ -524,7 +524,7 @@ int conf_read(const char *name) ...@@ -524,7 +524,7 @@ int conf_read(const char *name)
/* maybe print value in verbose mode... */ /* maybe print value in verbose mode... */
} }
for_all_symbols(i, sym) { for_all_symbols(sym) {
if (sym_has_value(sym) && !sym_is_choice_value(sym)) { if (sym_has_value(sym) && !sym_is_choice_value(sym)) {
/* Reset values of generates values, so they'll appear /* Reset values of generates values, so they'll appear
* as new, if they should become visible, but that * as new, if they should become visible, but that
...@@ -862,7 +862,6 @@ int conf_write(const char *name) ...@@ -862,7 +862,6 @@ int conf_write(const char *name)
const char *str; const char *str;
char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1]; char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1];
char *env; char *env;
int i;
bool need_newline = false; bool need_newline = false;
if (!name) if (!name)
...@@ -946,7 +945,7 @@ int conf_write(const char *name) ...@@ -946,7 +945,7 @@ int conf_write(const char *name)
} }
fclose(out); fclose(out);
for_all_symbols(i, sym) for_all_symbols(sym)
sym->flags &= ~SYMBOL_WRITTEN; sym->flags &= ~SYMBOL_WRITTEN;
if (*tmpname) { if (*tmpname) {
...@@ -1016,7 +1015,7 @@ static int conf_touch_deps(void) ...@@ -1016,7 +1015,7 @@ static int conf_touch_deps(void)
{ {
const char *name, *tmp; const char *name, *tmp;
struct symbol *sym; struct symbol *sym;
int res, i; int res;
name = conf_get_autoconfig_name(); name = conf_get_autoconfig_name();
tmp = strrchr(name, '/'); tmp = strrchr(name, '/');
...@@ -1030,7 +1029,7 @@ static int conf_touch_deps(void) ...@@ -1030,7 +1029,7 @@ static int conf_touch_deps(void)
conf_read_simple(name, S_DEF_AUTO); conf_read_simple(name, S_DEF_AUTO);
sym_calc_value(modules_sym); sym_calc_value(modules_sym);
for_all_symbols(i, sym) { for_all_symbols(sym) {
sym_calc_value(sym); sym_calc_value(sym);
if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name) if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name)
continue; continue;
...@@ -1096,7 +1095,7 @@ static int __conf_write_autoconf(const char *filename, ...@@ -1096,7 +1095,7 @@ static int __conf_write_autoconf(const char *filename,
char tmp[PATH_MAX]; char tmp[PATH_MAX];
FILE *file; FILE *file;
struct symbol *sym; struct symbol *sym;
int ret, i; int ret;
if (make_parent_dir(filename)) if (make_parent_dir(filename))
return -1; return -1;
...@@ -1113,7 +1112,7 @@ static int __conf_write_autoconf(const char *filename, ...@@ -1113,7 +1112,7 @@ static int __conf_write_autoconf(const char *filename,
conf_write_heading(file, comment_style); conf_write_heading(file, comment_style);
for_all_symbols(i, sym) for_all_symbols(sym)
if ((sym->flags & SYMBOL_WRITE) && sym->name) if ((sym->flags & SYMBOL_WRITE) && sym->name)
print_symbol(file, sym); print_symbol(file, sym);
...@@ -1136,7 +1135,7 @@ int conf_write_autoconf(int overwrite) ...@@ -1136,7 +1135,7 @@ int conf_write_autoconf(int overwrite)
{ {
struct symbol *sym; struct symbol *sym;
const char *autoconf_name = conf_get_autoconfig_name(); const char *autoconf_name = conf_get_autoconfig_name();
int ret, i; int ret;
if (!overwrite && is_present(autoconf_name)) if (!overwrite && is_present(autoconf_name))
return 0; return 0;
...@@ -1148,7 +1147,7 @@ int conf_write_autoconf(int overwrite) ...@@ -1148,7 +1147,7 @@ int conf_write_autoconf(int overwrite)
if (conf_touch_deps()) if (conf_touch_deps())
return 1; return 1;
for_all_symbols(i, sym) for_all_symbols(sym)
sym_calc_value(sym); sym_calc_value(sym);
ret = __conf_write_autoconf(conf_get_autoheader_name(), ret = __conf_write_autoconf(conf_get_autoheader_name(),
......
...@@ -17,6 +17,8 @@ extern "C" { ...@@ -17,6 +17,8 @@ extern "C" {
#include <stdbool.h> #include <stdbool.h>
#endif #endif
#include "list_types.h"
typedef enum tristate { typedef enum tristate {
no, mod, yes no, mod, yes
} tristate; } tristate;
...@@ -74,8 +76,8 @@ enum { ...@@ -74,8 +76,8 @@ enum {
* SYMBOL_CHOICE bit set in 'flags'. * SYMBOL_CHOICE bit set in 'flags'.
*/ */
struct symbol { struct symbol {
/* The next symbol in the same bucket in the symbol hash table */ /* link node for the hash table */
struct symbol *next; struct hlist_node node;
/* The name of the symbol, e.g. "FOO" for 'config FOO' */ /* The name of the symbol, e.g. "FOO" for 'config FOO' */
char *name; char *name;
...@@ -124,8 +126,6 @@ struct symbol { ...@@ -124,8 +126,6 @@ struct symbol {
struct expr_value implied; struct expr_value implied;
}; };
#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next)
#define SYMBOL_CONST 0x0001 /* symbol is const */ #define SYMBOL_CONST 0x0001 /* symbol is const */
#define SYMBOL_CHECK 0x0008 /* used during dependency checking */ #define SYMBOL_CHECK 0x0008 /* used during dependency checking */
#define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */ #define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */
...@@ -150,7 +150,6 @@ struct symbol { ...@@ -150,7 +150,6 @@ struct symbol {
#define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000 #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000
#define SYMBOL_MAXLENGTH 256 #define SYMBOL_MAXLENGTH 256
#define SYMBOL_HASHSIZE 9973
/* A property represent the config options that can be associated /* A property represent the config options that can be associated
* with a config "symbol". * with a config "symbol".
......
...@@ -2,6 +2,15 @@ ...@@ -2,6 +2,15 @@
#ifndef INTERNAL_H #ifndef INTERNAL_H
#define INTERNAL_H #define INTERNAL_H
#include "hashtable.h"
#define SYMBOL_HASHSIZE (1U << 14)
extern HASHTABLE_DECLARE(sym_hashtable, SYMBOL_HASHSIZE);
#define for_all_symbols(sym) \
hash_for_each(sym_hashtable, sym, node)
struct menu; struct menu;
extern struct menu *current_menu, *current_entry; extern struct menu *current_menu, *current_entry;
......
...@@ -18,8 +18,6 @@ void conf_set_message_callback(void (*fn)(const char *s)); ...@@ -18,8 +18,6 @@ void conf_set_message_callback(void (*fn)(const char *s));
bool conf_errors(void); bool conf_errors(void);
/* symbol.c */ /* symbol.c */
extern struct symbol * symbol_hash[SYMBOL_HASHSIZE];
struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_lookup(const char *name, int flags);
struct symbol * sym_find(const char *name); struct symbol * sym_find(const char *name);
void print_symbol_for_listconfig(struct symbol *sym); void print_symbol_for_listconfig(struct symbol *sym);
......
...@@ -28,8 +28,6 @@ static void zconf_error(const char *err, ...); ...@@ -28,8 +28,6 @@ static void zconf_error(const char *err, ...);
static bool zconf_endtoken(const char *tokenname, static bool zconf_endtoken(const char *tokenname,
const char *expected_tokenname); const char *expected_tokenname);
struct symbol *symbol_hash[SYMBOL_HASHSIZE];
struct menu *current_menu, *current_entry; struct menu *current_menu, *current_entry;
%} %}
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string.h> #include <string.h>
#include <regex.h> #include <regex.h>
#include "internal.h"
#include "lkc.h" #include "lkc.h"
struct symbol symbol_yes = { struct symbol symbol_yes = {
...@@ -160,9 +161,8 @@ static void sym_set_changed(struct symbol *sym) ...@@ -160,9 +161,8 @@ static void sym_set_changed(struct symbol *sym)
static void sym_set_all_changed(void) static void sym_set_all_changed(void)
{ {
struct symbol *sym; struct symbol *sym;
int i;
for_all_symbols(i, sym) for_all_symbols(sym)
sym_set_changed(sym); sym_set_changed(sym);
} }
...@@ -475,9 +475,8 @@ void sym_calc_value(struct symbol *sym) ...@@ -475,9 +475,8 @@ void sym_calc_value(struct symbol *sym)
void sym_clear_all_valid(void) void sym_clear_all_valid(void)
{ {
struct symbol *sym; struct symbol *sym;
int i;
for_all_symbols(i, sym) for_all_symbols(sym)
sym->flags &= ~SYMBOL_VALID; sym->flags &= ~SYMBOL_VALID;
conf_set_changed(true); conf_set_changed(true);
sym_calc_value(modules_sym); sym_calc_value(modules_sym);
...@@ -803,6 +802,8 @@ bool sym_is_changeable(struct symbol *sym) ...@@ -803,6 +802,8 @@ bool sym_is_changeable(struct symbol *sym)
return sym->visible > sym->rev_dep.tri; return sym->visible > sym->rev_dep.tri;
} }
HASHTABLE_DEFINE(sym_hashtable, SYMBOL_HASHSIZE);
struct symbol *sym_lookup(const char *name, int flags) struct symbol *sym_lookup(const char *name, int flags)
{ {
struct symbol *symbol; struct symbol *symbol;
...@@ -817,9 +818,9 @@ struct symbol *sym_lookup(const char *name, int flags) ...@@ -817,9 +818,9 @@ struct symbol *sym_lookup(const char *name, int flags)
case 'n': return &symbol_no; case 'n': return &symbol_no;
} }
} }
hash = strhash(name) % SYMBOL_HASHSIZE; hash = strhash(name);
for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { hash_for_each_possible(sym_hashtable, symbol, node, hash) {
if (symbol->name && if (symbol->name &&
!strcmp(symbol->name, name) && !strcmp(symbol->name, name) &&
(flags ? symbol->flags & flags (flags ? symbol->flags & flags
...@@ -838,8 +839,7 @@ struct symbol *sym_lookup(const char *name, int flags) ...@@ -838,8 +839,7 @@ struct symbol *sym_lookup(const char *name, int flags)
symbol->type = S_UNKNOWN; symbol->type = S_UNKNOWN;
symbol->flags = flags; symbol->flags = flags;
symbol->next = symbol_hash[hash]; hash_add(sym_hashtable, &symbol->node, hash);
symbol_hash[hash] = symbol;
return symbol; return symbol;
} }
...@@ -859,9 +859,9 @@ struct symbol *sym_find(const char *name) ...@@ -859,9 +859,9 @@ struct symbol *sym_find(const char *name)
case 'n': return &symbol_no; case 'n': return &symbol_no;
} }
} }
hash = strhash(name) % SYMBOL_HASHSIZE; hash = strhash(name);
for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { hash_for_each_possible(sym_hashtable, symbol, node, hash) {
if (symbol->name && if (symbol->name &&
!strcmp(symbol->name, name) && !strcmp(symbol->name, name) &&
!(symbol->flags & SYMBOL_CONST)) !(symbol->flags & SYMBOL_CONST))
...@@ -921,7 +921,7 @@ struct symbol **sym_re_search(const char *pattern) ...@@ -921,7 +921,7 @@ struct symbol **sym_re_search(const char *pattern)
if (regcomp(&re, pattern, REG_EXTENDED|REG_ICASE)) if (regcomp(&re, pattern, REG_EXTENDED|REG_ICASE))
return NULL; return NULL;
for_all_symbols(i, sym) { for_all_symbols(sym) {
if (sym->flags & SYMBOL_CONST || !sym->name) if (sym->flags & SYMBOL_CONST || !sym->name)
continue; continue;
if (regexec(&re, sym->name, 1, match, 0)) if (regexec(&re, sym->name, 1, match, 0))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment