From: Guus Sliepen Date: Sat, 5 Oct 2019 12:16:43 +0000 (+0200) Subject: Remove unused functions, and make more functions static. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=6eb1cfb2b112baf54d7c91e6d303f823ddb8acdd;p=meshlink Remove unused functions, and make more functions static. --- diff --git a/src/list.c b/src/list.c index 8a483604..b93ebfc5 100644 --- a/src/list.c +++ b/src/list.c @@ -35,11 +35,11 @@ void list_free(list_t *list) { free(list); } -list_node_t *list_alloc_node(void) { +static list_node_t *list_alloc_node(void) { return xzalloc(sizeof(list_node_t)); } -void list_free_node(list_t *list, list_node_t *node) { +static void list_free_node(list_t *list, list_node_t *node) { if(node->data && list->delete) { list->delete(node->data); } @@ -87,47 +87,11 @@ list_node_t *list_insert_tail(list_t *list, void *data) { return node; } -list_node_t *list_insert_after(list_t *list, list_node_t *after, void *data) { - list_node_t *node = list_alloc_node(); - - node->data = data; - node->next = after->next; - node->prev = after; - after->next = node; - - if(node->next) { - node->next->prev = node; - } else { - list->tail = node; - } +static void list_unlink_node(list_t *list, list_node_t *node) { + assert(list->count); + assert(node->prev || list->head == node); + assert(node->next || list->tail == node); - list->count++; - - return node; -} - -list_node_t *list_insert_before(list_t *list, list_node_t *before, void *data) { - list_node_t *node; - - node = list_alloc_node(); - - node->data = data; - node->next = before; - node->prev = before->prev; - before->prev = node; - - if(node->prev) { - node->prev->next = node; - } else { - list->head = node; - } - - list->count++; - - return node; -} - -void list_unlink_node(list_t *list, list_node_t *node) { if(node->prev) { node->prev->next = node->next; } else { @@ -157,10 +121,11 @@ void list_delete_tail(list_t *list) { } void list_delete(list_t *list, const void *data) { - for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) + for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) { if(node->data == data) { list_delete_node(list, node); } + } } /* Head/tail lookup */ @@ -203,8 +168,9 @@ void list_foreach_node(list_t *list, list_action_node_t action) { } void list_foreach(list_t *list, list_action_t action) { - for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) + for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) { if(node->data) { action(node->data); } + } } diff --git a/src/list.h b/src/list.h index 186e0ad6..60f9a437 100644 --- a/src/list.h +++ b/src/list.h @@ -46,19 +46,14 @@ typedef struct list_t { extern list_t *list_alloc(list_action_t) __attribute__((__malloc__)); extern void list_free(list_t *); -extern list_node_t *list_alloc_node(void); -extern void list_free_node(list_t *, list_node_t *); /* Insertion and deletion */ extern list_node_t *list_insert_head(list_t *, void *); extern list_node_t *list_insert_tail(list_t *, void *); -extern list_node_t *list_insert_after(list_t *, list_node_t *, void *); -extern list_node_t *list_insert_before(list_t *, list_node_t *, void *); extern void list_delete(list_t *, const void *); -extern void list_unlink_node(list_t *, list_node_t *); extern void list_delete_node(list_t *, list_node_t *); extern void list_delete_head(list_t *); diff --git a/src/protocol_key.c b/src/protocol_key.c index a9bc1c0a..bf6c40a2 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -275,12 +275,6 @@ bool req_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return true; } -bool send_ans_key(meshlink_handle_t *mesh, node_t *to) { - (void)mesh; - (void)to; - abort(); -} - bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { assert(request); assert(*request); diff --git a/src/splay_tree.c b/src/splay_tree.c index 53f109f2..2d694719 100644 --- a/src/splay_tree.c +++ b/src/splay_tree.c @@ -277,10 +277,6 @@ splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) { return tree; } -void splay_free_tree(splay_tree_t *tree) { - free(tree); -} - splay_node_t *splay_alloc_node(void) { return xzalloc(sizeof(splay_node_t)); } @@ -409,13 +405,15 @@ splay_node_t *splay_search_closest_greater_node(splay_tree_t *tree, const void * /* Insertion and deletion */ -void splay_insert_top(splay_tree_t *tree, splay_node_t *node) { +static void splay_insert_top(splay_tree_t *tree, splay_node_t *node) { node->prev = node->next = node->left = node->right = node->parent = NULL; tree->head = tree->tail = tree->root = node; tree->count++; } -void splay_insert_before(splay_tree_t *tree, splay_node_t *before, splay_node_t *node) { +static void splay_insert_after(splay_tree_t *tree, splay_node_t *after, splay_node_t *node); + +static void splay_insert_before(splay_tree_t *tree, splay_node_t *before, splay_node_t *node) { if(!before) { if(tree->tail) { splay_insert_after(tree, tree->tail, node); @@ -452,7 +450,7 @@ void splay_insert_before(splay_tree_t *tree, splay_node_t *before, splay_node_t tree->count++; } -void splay_insert_after(splay_tree_t *tree, splay_node_t *after, splay_node_t *node) { +static void splay_insert_after(splay_tree_t *tree, splay_node_t *after, splay_node_t *node) { if(!after) { if(tree->head) { splay_insert_before(tree, tree->head, node); diff --git a/src/splay_tree.h b/src/splay_tree.h index b6727908..ca53dc37 100644 --- a/src/splay_tree.h +++ b/src/splay_tree.h @@ -64,7 +64,7 @@ typedef struct splay_tree_t { /* (De)constructors */ extern splay_tree_t *splay_alloc_tree(splay_compare_t, splay_action_t) __attribute__((__malloc__)); -extern void splay_free_tree(splay_tree_t *); +extern void splay_delete_tree(splay_tree_t *); extern splay_node_t *splay_alloc_node(void) __attribute__((__malloc__)); extern void splay_free_node(splay_tree_t *tree, splay_node_t *); @@ -74,19 +74,11 @@ extern void splay_free_node(splay_tree_t *tree, splay_node_t *); extern splay_node_t *splay_insert(splay_tree_t *, void *); extern splay_node_t *splay_insert_node(splay_tree_t *, splay_node_t *); -extern void splay_insert_top(splay_tree_t *, splay_node_t *); -extern void splay_insert_before(splay_tree_t *, splay_node_t *, splay_node_t *); -extern void splay_insert_after(splay_tree_t *, splay_node_t *, splay_node_t *); - extern splay_node_t *splay_unlink(splay_tree_t *, void *); extern void splay_unlink_node(splay_tree_t *tree, splay_node_t *); extern void splay_delete(splay_tree_t *, void *); extern void splay_delete_node(splay_tree_t *, splay_node_t *); -/* Fast tree cleanup */ - -extern void splay_delete_tree(splay_tree_t *); - /* Searching */ extern void *splay_search(splay_tree_t *, const void *); diff --git a/src/submesh.c b/src/submesh.c index 6780b8a0..4af2be07 100644 --- a/src/submesh.c +++ b/src/submesh.c @@ -30,6 +30,15 @@ #include "xalloc.h" #include "protocol.h" +static submesh_t *new_submesh(void) { + return xzalloc(sizeof(submesh_t)); +} + +static void free_submesh(submesh_t *s) { + free(s->name); + free(s); +} + void init_submeshes(meshlink_handle_t *mesh) { assert(!mesh->submeshes); mesh->submeshes = list_alloc((list_action_t)free_submesh); @@ -43,37 +52,17 @@ void exit_submeshes(meshlink_handle_t *mesh) { mesh->submeshes = NULL; } -submesh_t *new_submesh(void) { - submesh_t *s = xzalloc(sizeof(*s)); - - s->name = NULL; - s->priv = NULL; - - return s; -} - -void free_submesh(submesh_t *s) { - if(s->name) { - free(s->name); - } - - free(s); -} - -static submesh_t *submesh_new(meshlink_handle_t *mesh, const char *submesh) { - submesh_t *s = NULL; +static submesh_t *submesh_add(meshlink_handle_t *mesh, const char *submesh) { assert(submesh); - s = new_submesh(); + submesh_t *s = new_submesh(); s->name = xstrdup(submesh); - - submesh_add(mesh, (submesh_t *)s); + list_insert_tail(mesh->submeshes, (void *)s); return s; } submesh_t *create_submesh(meshlink_handle_t *mesh, const char *submesh) { assert(submesh); - submesh_t *s = NULL; if(0 == strcmp(submesh, CORE_MESH)) { logger(NULL, MESHLINK_ERROR, "Cannot create submesh handle for core mesh!\n"); @@ -87,23 +76,17 @@ submesh_t *create_submesh(meshlink_handle_t *mesh, const char *submesh) { return NULL; } - s = lookup_submesh(mesh, submesh); - - if(s) { + if(lookup_submesh(mesh, submesh)) { logger(NULL, MESHLINK_ERROR, "SubMesh Already exists!\n"); meshlink_errno = MESHLINK_EEXIST; return NULL; } - s = submesh_new(mesh, submesh); - - meshlink_errno = MESHLINK_OK; - return s; + return submesh_add(mesh, submesh); } submesh_t *lookup_or_create_submesh(meshlink_handle_t *mesh, const char *submesh) { assert(submesh); - submesh_t *s = NULL; if(0 == strcmp(submesh, CORE_MESH)) { logger(NULL, MESHLINK_ERROR, "Cannot create submesh handle for core mesh!\n"); @@ -117,26 +100,14 @@ submesh_t *lookup_or_create_submesh(meshlink_handle_t *mesh, const char *submesh return NULL; } - s = lookup_submesh(mesh, submesh); + submesh_t *s = lookup_submesh(mesh, submesh); if(s) { meshlink_errno = MESHLINK_OK; return s; } - s = submesh_new(mesh, submesh); - - meshlink_errno = MESHLINK_OK; - return s; -} - -void submesh_add(meshlink_handle_t *mesh, submesh_t *s) { - s->mesh = mesh; - list_insert_tail(mesh->submeshes, (void *)s); -} - -void submesh_del(meshlink_handle_t *mesh, submesh_t *s) { - list_delete(mesh->submeshes, (void *)s); + return submesh_add(mesh, submesh); } submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *submesh_name) { diff --git a/src/submesh.h b/src/submesh.h index 31f166a4..d6122d8f 100644 --- a/src/submesh.h +++ b/src/submesh.h @@ -33,11 +33,7 @@ typedef struct submesh_t { extern void init_submeshes(struct meshlink_handle *mesh); extern void exit_submeshes(struct meshlink_handle *mesh); -extern submesh_t *new_submesh(void) __attribute__((__malloc__)); -extern void free_submesh(submesh_t *); extern submesh_t *create_submesh(struct meshlink_handle *mesh, const char *); -extern void submesh_add(struct meshlink_handle *mesh, submesh_t *); -extern void submesh_del(struct meshlink_handle *mesh, submesh_t *); extern submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *); extern submesh_t *lookup_or_create_submesh(struct meshlink_handle *mesh, const char *); extern bool submesh_allows_node(const submesh_t *submesh, const struct node_t *node);