X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/3e91d7006fc792367326ae5a259bde5f8aba89c3..bcd8cc02e12c429c670408c24ddbbaf1186c76d1:/src/irc_dictionary.c diff --git a/src/irc_dictionary.c b/src/irc_dictionary.c index 2c901e9..0de08b6 100644 --- a/src/irc_dictionary.c +++ b/src/irc_dictionary.c @@ -23,16 +23,12 @@ */ #include "stdinc.h" -#include "sprintf_irc.h" -#include "tools.h" -#include "irc_string.h" +#include "match.h" #include "client.h" -#include "memory.h" #include "setup.h" -#include "balloc.h" #include "irc_dictionary.h" -static BlockHeap *elem_heap = NULL; +static rb_bh *elem_heap = NULL; struct Dictionary { @@ -60,12 +56,12 @@ struct Dictionary */ struct Dictionary *irc_dictionary_create(DCF compare_cb) { - struct Dictionary *dtree = (struct Dictionary *) MyMalloc(sizeof(struct Dictionary)); + struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); dtree->compare_cb = compare_cb; if (!elem_heap) - elem_heap = BlockHeapCreate(sizeof(struct DictionaryElement), 1024); + elem_heap = rb_bh_create(sizeof(struct DictionaryElement), 1024, "dictionary_elem_heap"); return dtree; } @@ -90,13 +86,13 @@ struct Dictionary *irc_dictionary_create(DCF compare_cb) struct Dictionary *irc_dictionary_create_named(const char *name, DCF compare_cb) { - struct Dictionary *dtree = (struct Dictionary *) MyMalloc(sizeof(struct Dictionary)); + struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); dtree->compare_cb = compare_cb; - DupString(dtree->id, name); + dtree->id = rb_strdup(name); if (!elem_heap) - elem_heap = BlockHeapCreate(sizeof(struct DictionaryElement), 1024); + elem_heap = rb_bh_create(sizeof(struct DictionaryElement), 1024, "dictionary_elem_heap"); return dtree; } @@ -207,7 +203,7 @@ irc_dictionary_get_linear_index(struct Dictionary *dict, const char *key) * Side Effects: * - a new root node is nominated. */ -void +static void irc_dictionary_retune(struct Dictionary *dict, const char *key) { struct DictionaryElement n, *tn, *left, *right, *node; @@ -306,7 +302,7 @@ irc_dictionary_retune(struct Dictionary *dict, const char *key) * Side Effects: * - a node is linked to the dictionary tree */ -void +static void irc_dictionary_link(struct Dictionary *dict, struct DictionaryElement *delem) { @@ -367,7 +363,7 @@ irc_dictionary_link(struct Dictionary *dict, dict->root->data = delem->data; dict->count--; - BlockHeapFree(elem_heap, delem); + rb_bh_free(elem_heap, delem); } } } @@ -386,7 +382,7 @@ irc_dictionary_link(struct Dictionary *dict, * Side Effects: * - the root node is unlinked from the dictionary tree */ -void +static void irc_dictionary_unlink_root(struct Dictionary *dict) { struct DictionaryElement *delem, *nextnode, *parentofnext; @@ -471,15 +467,15 @@ void irc_dictionary_destroy(struct Dictionary *dtree, s_assert(dtree != NULL); - DLINK_FOREACH_SAFE(n, tn, dtree->head) + RB_DLINK_FOREACH_SAFE(n, tn, dtree->head) { if (destroy_cb != NULL) (*destroy_cb)(n, privdata); - BlockHeapFree(elem_heap, n); + rb_bh_free(elem_heap, n); } - MyFree(dtree); + rb_free(dtree); } /* @@ -508,7 +504,7 @@ void irc_dictionary_foreach(struct Dictionary *dtree, s_assert(dtree != NULL); - DLINK_FOREACH_SAFE(n, tn, dtree->head) + RB_DLINK_FOREACH_SAFE(n, tn, dtree->head) { /* delem_t is a subclass of node_t. */ struct DictionaryElement *delem = (struct DictionaryElement *) n; @@ -546,7 +542,7 @@ void *irc_dictionary_search(struct Dictionary *dtree, s_assert(dtree != NULL); - DLINK_FOREACH_SAFE(n, tn, dtree->head) + RB_DLINK_FOREACH_SAFE(n, tn, dtree->head) { /* delem_t is a subclass of node_t. */ struct DictionaryElement *delem = (struct DictionaryElement *) n; @@ -648,7 +644,7 @@ void irc_dictionary_foreach_next(struct Dictionary *dtree, if (state->cur == NULL) { - ilog(L_MAIN, "irc_dictionary_foreach_next(): called again after iteration finished on dtree<%p>", dtree); + ilog(L_MAIN, "irc_dictionary_foreach_next(): called again after iteration finished on dtree<%p>", (void *)dtree); return; } @@ -707,7 +703,7 @@ struct DictionaryElement *irc_dictionary_find(struct Dictionary *dict, const cha * Side Effects: * - data is inserted into the DTree. */ -struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, char *key, void *data) +struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, const char *key, void *data) { struct DictionaryElement *delem; @@ -716,14 +712,14 @@ struct DictionaryElement *irc_dictionary_add(struct Dictionary *dict, char *key, s_assert(data != NULL); s_assert(irc_dictionary_find(dict, key) == NULL); - delem = BlockHeapAlloc(elem_heap); + delem = rb_bh_alloc(elem_heap); delem->key = key; delem->data = data; /* TBD: is this needed? --nenolod */ if (delem->key == NULL) { - BlockHeapFree(elem_heap, delem); + rb_bh_free(elem_heap, delem); return NULL; } @@ -762,7 +758,7 @@ void *irc_dictionary_delete(struct Dictionary *dtree, const char *key) data = delem->data; irc_dictionary_unlink_root(dtree); - BlockHeapFree(elem_heap, delem); + rb_bh_free(elem_heap, delem); return data; } @@ -858,7 +854,7 @@ void irc_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, dict->id, dict->count); else snprintf(str, sizeof str, "Dictionary stats for <%p> (%d)", - dict, dict->count); + (void *)dict, dict->count); cb(str, privdata); maxdepth = 0; sum = stats_recurse(dict->root, 0, &maxdepth);