diff options
author | Maria Matejka <mq@ucw.cz> | 2022-05-02 20:29:03 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2022-05-04 15:38:42 +0200 |
commit | 165156beeb2926472bbceca3c103aacc3f81a8cc (patch) | |
tree | 483ee32846c8758ded4b8c4bfeea3d3ae07a21d2 /conf/conf.h | |
parent | cf07d8ad79273a3bbf0617c17e438602e4b64ece (diff) |
Conf: Symbols are properly scoped
Now there is a persistent root symbol scope and all scopes have their
symbol hashes to store local symbols and not leak any symbol out.
Diffstat (limited to 'conf/conf.h')
-rw-r--r-- | conf/conf.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/conf/conf.h b/conf/conf.h index 55cb9c58..2700295b 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -16,7 +16,6 @@ #include "lib/timer.h" /* Configuration structure */ - struct config { pool *pool; /* Pool the configuration is stored in */ linpool *mem; /* Linear pool containing configuration data */ @@ -54,8 +53,7 @@ struct config { char *err_file_name; /* File name containing error */ char *file_name; /* Name of main configuration file */ int file_fd; /* File descriptor of main configuration file */ - HASH(struct symbol) sym_hash; /* Lexer: symbol hash table */ - struct config *fallback; /* Link to regular config for CLI parsing */ + struct sym_scope *root_scope; /* Scope for root symbols */ int obstacle_count; /* Number of items blocking freeing of this config */ int shutdown; /* This is a pseudo-config for daemon shutdown */ @@ -133,10 +131,15 @@ struct symbol { struct sym_scope { struct sym_scope *next; /* Next on scope stack */ struct symbol *name; /* Name of this scope */ + + HASH(struct symbol) hash; /* Local symbol hash */ + uint slots; /* Variable slots */ int active; /* Currently entered */ }; +extern struct sym_scope *global_root_scope; + struct bytestring { size_t length; byte data[]; @@ -185,7 +188,14 @@ int cf_lex(void); void cf_lex_init(int is_cli, struct config *c); void cf_lex_unwind(void); -struct symbol *cf_find_symbol(const struct config *cfg, const byte *c); +struct symbol *cf_find_symbol_scope(const struct sym_scope *scope, const byte *c); +static inline struct symbol *cf_find_symbol_cfg(const struct config *cfg, const byte *c) +{ return cf_find_symbol_scope(cfg->root_scope, c); } + +#define cf_find_symbol(where, what) _Generic(*(where), \ + struct config: cf_find_symbol_cfg, \ + struct sym_scope: cf_find_symbol_scope \ + )((where), (what)) struct symbol *cf_get_symbol(const byte *c); struct symbol *cf_default_name(char *template, int *counter); |