diff options
author | David Lamparter <equinox@diac24.net> | 2019-11-14 23:27:29 +0100 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2019-11-30 00:38:32 +0100 |
commit | 154e9ca142bddf748f12a8042519ec6438364625 (patch) | |
tree | d96c1306241b608e8c2048f73862a369abaa5470 | |
parent | lib: gcc 4.x workaround v2 for frr_interface_info (diff) | |
download | frr-154e9ca142bddf748f12a8042519ec6438364625.tar.xz frr-154e9ca142bddf748f12a8042519ec6438364625.zip |
lib: make cmd_element & qobj_type const
Signed-off-by: David Lamparter <equinox@diac24.net>
-rw-r--r-- | lib/command.c | 18 | ||||
-rw-r--r-- | lib/command.h | 8 | ||||
-rw-r--r-- | lib/command_graph.h | 2 | ||||
-rw-r--r-- | lib/command_parse.y | 8 | ||||
-rw-r--r-- | lib/qobj.c | 4 | ||||
-rw-r--r-- | lib/qobj.h | 12 |
6 files changed, 26 insertions, 26 deletions
diff --git a/lib/command.c b/lib/command.c index 59668e95f..9238ae412 100644 --- a/lib/command.c +++ b/lib/command.c @@ -74,7 +74,7 @@ const struct message tokennames[] = { {0}, }; -const char *node_names[] = { +const char *const node_names[] = { "auth", // AUTH_NODE, "view", // VIEW_NODE, "auth enable", // AUTH_ENABLE_NODE, @@ -370,7 +370,7 @@ const char *cmd_prompt(enum node_type node) } /* Install a command into a node. */ -void install_element(enum node_type ntype, struct cmd_element *cmd) +void install_element(enum node_type ntype, const struct cmd_element *cmd) { struct cmd_node *cnode; @@ -392,7 +392,7 @@ void install_element(enum node_type ntype, struct cmd_element *cmd) exit(EXIT_FAILURE); } - if (hash_lookup(cnode->cmd_hash, cmd) != NULL) { + if (hash_lookup(cnode->cmd_hash, (void *)cmd) != NULL) { fprintf(stderr, "%s[%s]:\n" "\tnode %d (%s) already has this command installed.\n" @@ -401,7 +401,7 @@ void install_element(enum node_type ntype, struct cmd_element *cmd) return; } - assert(hash_get(cnode->cmd_hash, cmd, hash_alloc_intern)); + assert(hash_get(cnode->cmd_hash, (void *)cmd, hash_alloc_intern)); struct graph *graph = graph_new(); struct cmd_token *token = @@ -413,13 +413,13 @@ void install_element(enum node_type ntype, struct cmd_element *cmd) cmd_graph_merge(cnode->cmdgraph, graph, +1); graph_delete_graph(graph); - vector_set(cnode->cmd_vector, cmd); + vector_set(cnode->cmd_vector, (void *)cmd); if (ntype == VIEW_NODE) install_element(ENABLE_NODE, cmd); } -void uninstall_element(enum node_type ntype, struct cmd_element *cmd) +void uninstall_element(enum node_type ntype, const struct cmd_element *cmd) { struct cmd_node *cnode; @@ -441,7 +441,7 @@ void uninstall_element(enum node_type ntype, struct cmd_element *cmd) exit(EXIT_FAILURE); } - if (hash_release(cnode->cmd_hash, cmd) == NULL) { + if (hash_release(cnode->cmd_hash, (void *)cmd) == NULL) { fprintf(stderr, "%s[%s]:\n" "\tnode %d (%s) does not have this command installed.\n" @@ -450,7 +450,7 @@ void uninstall_element(enum node_type ntype, struct cmd_element *cmd) return; } - vector_unset_value(cnode->cmd_vector, cmd); + vector_unset_value(cnode->cmd_vector, (void *)cmd); struct graph *graph = graph_new(); struct cmd_token *token = @@ -1660,7 +1660,7 @@ int cmd_list_cmds(struct vty *vty, int do_permute) permute(vector_slot(node->cmdgraph->nodes, 0), vty); else { /* loop over all commands at this node */ - struct cmd_element *element = NULL; + const struct cmd_element *element = NULL; for (unsigned int i = 0; i < vector_active(node->cmd_vector); i++) if ((element = vector_slot(node->cmd_vector, i)) diff --git a/lib/command.h b/lib/command.h index 68ac86f76..c8dd04604 100644 --- a/lib/command.h +++ b/lib/command.h @@ -165,7 +165,7 @@ enum node_type { extern vector cmdvec; extern const struct message tokennames[]; -extern const char *node_names[]; +extern const char *const node_names[]; /* Node which has some commands and prompt string and configuration function pointer . */ @@ -217,7 +217,7 @@ struct cmd_node { /* helper defines for end-user DEFUN* macros */ #define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \ - static struct cmd_element cmdname = { \ + static const struct cmd_element cmdname = { \ .string = cmdstr, \ .func = funcname, \ .doc = helpstr, \ @@ -421,11 +421,11 @@ struct cmd_node { /* Prototypes. */ extern void install_node(struct cmd_node *, int (*)(struct vty *)); extern void install_default(enum node_type); -extern void install_element(enum node_type, struct cmd_element *); +extern void install_element(enum node_type, const struct cmd_element *); /* known issue with uninstall_element: changes to cmd_token->attr (i.e. * deprecated/hidden) are not reversed. */ -extern void uninstall_element(enum node_type, struct cmd_element *); +extern void uninstall_element(enum node_type, const struct cmd_element *); /* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated string with a space between each element (allocated using diff --git a/lib/command_graph.h b/lib/command_graph.h index 903d51583..1efe8b180 100644 --- a/lib/command_graph.h +++ b/lib/command_graph.h @@ -116,7 +116,7 @@ extern struct cmd_token *cmd_token_dup(struct cmd_token *); extern void cmd_token_del(struct cmd_token *); extern void cmd_token_varname_set(struct cmd_token *token, const char *varname); -extern void cmd_graph_parse(struct graph *graph, struct cmd_element *cmd); +extern void cmd_graph_parse(struct graph *graph, const struct cmd_element *cmd); extern void cmd_graph_names(struct graph *graph); extern void cmd_graph_merge(struct graph *old, struct graph *n, int direction); diff --git a/lib/command_parse.y b/lib/command_parse.y index 062a4bb30..5dc19d2c9 100644 --- a/lib/command_parse.y +++ b/lib/command_parse.y @@ -84,7 +84,7 @@ struct parser_ctx { yyscan_t scanner; - struct cmd_element *el; + const struct cmd_element *el; struct graph *graph; struct graph_node *currnode; @@ -379,7 +379,7 @@ selector: '[' selector_seq_seq ']' varname_token DEFINE_MTYPE(LIB, LEX, "Lexer token (temporary)") void -cmd_graph_parse (struct graph *graph, struct cmd_element *cmd) +cmd_graph_parse (struct graph *graph, const struct cmd_element *cmd) { struct parser_ctx ctx = { .graph = graph, .el = cmd }; @@ -485,11 +485,11 @@ terminate_graph (CMD_YYLTYPE *locp, struct parser_ctx *ctx, { // end of graph should look like this // * -> finalnode -> END_TKN -> cmd_element - struct cmd_element *element = ctx->el; + const struct cmd_element *element = ctx->el; struct graph_node *end_token_node = new_token_node (ctx, END_TKN, CMD_CR_TEXT, ""); struct graph_node *end_element_node = - graph_new_node (ctx->graph, element, NULL); + graph_new_node (ctx->graph, (void *)element, NULL); if (ctx->docstr && strlen (ctx->docstr) > 1) { zlog_debug ("Excessive docstring while parsing '%s'", ctx->el->string); diff --git a/lib/qobj.c b/lib/qobj.c index 3e3860a96..1e48b541d 100644 --- a/lib/qobj.c +++ b/lib/qobj.c @@ -48,7 +48,7 @@ static pthread_rwlock_t nodes_lock; static struct qobj_nodes_head nodes = { }; -void qobj_reg(struct qobj_node *node, struct qobj_nodetype *type) +void qobj_reg(struct qobj_node *node, const struct qobj_nodetype *type) { node->type = type; pthread_rwlock_wrlock(&nodes_lock); @@ -76,7 +76,7 @@ struct qobj_node *qobj_get(uint64_t id) return rv; } -void *qobj_get_typed(uint64_t id, struct qobj_nodetype *type) +void *qobj_get_typed(uint64_t id, const struct qobj_nodetype *type) { struct qobj_node dummy = {.nid = id}; struct qobj_node *node; diff --git a/lib/qobj.h b/lib/qobj.h index 415eae02e..400ae0151 100644 --- a/lib/qobj.h +++ b/lib/qobj.h @@ -89,7 +89,7 @@ PREDECL_HASH(qobj_nodes) struct qobj_node { uint64_t nid; struct qobj_nodes_item nodehash; - struct qobj_nodetype *type; + const struct qobj_nodetype *type; }; #define QOBJ_FIELDS struct qobj_node qobj_node; @@ -111,20 +111,20 @@ struct qobj_node { * * in the long this may need another touch, e.g. built-in per-object locking. */ -void qobj_reg(struct qobj_node *node, struct qobj_nodetype *type); +void qobj_reg(struct qobj_node *node, const struct qobj_nodetype *type); void qobj_unreg(struct qobj_node *node); struct qobj_node *qobj_get(uint64_t id); -void *qobj_get_typed(uint64_t id, struct qobj_nodetype *type); +void *qobj_get_typed(uint64_t id, const struct qobj_nodetype *type); /* type declarations */ #define DECLARE_QOBJ_TYPE(structname) \ - extern struct qobj_nodetype qobj_t_##structname; + extern const struct qobj_nodetype qobj_t_##structname; #define DEFINE_QOBJ_TYPE(structname) \ - struct qobj_nodetype qobj_t_##structname = { \ + const struct qobj_nodetype qobj_t_##structname = { \ .node_member_offset = \ (ptrdiff_t)offsetof(struct structname, qobj_node)}; #define DEFINE_QOBJ_TYPE_INIT(structname, ...) \ - struct qobj_nodetype qobj_t_##structname = { \ + const struct qobj_nodetype qobj_t_##structname = { \ .node_member_offset = \ (ptrdiff_t)offsetof(struct structname, qobj_node), \ __VA_ARGS__}; |