commit 036c104e0d5b8758a8cf72c9085af23956fdfa6f from: Omar Polo date: Tue Jan 11 17:12:33 2022 UTC de-duplicate hash_* function: collect them in util.c commit - 4e3871f5a61f3d1781f0e1b273ab3c7eeb9924f7 commit + 036c104e0d5b8758a8cf72c9085af23956fdfa6f blob - 18b9b98b7e296edb99d6ecc528efc5761c2209a6 blob + 505eaf866ab0e7671de8887bb9403e7983c59eed --- mcache.c +++ mcache.c @@ -48,32 +48,6 @@ struct mcache_entry { char url[]; }; -static void *hash_alloc(size_t, void *); -static void *hash_calloc(size_t, size_t, void *); -static void hash_free(void *, void *); - -static void * -hash_alloc(size_t len, void *d) -{ - if ((d = malloc(len)) == NULL) - abort(); - return d; -} - -static void * -hash_calloc(size_t nmemb, size_t size, void *d) -{ - if ((d = calloc(nmemb, size)) == NULL) - abort(); - return d; -} - -static void -hash_free(void *ptr, void *d) -{ - free(ptr); -} - void mcache_init(void) { blob - d1b876a21449a636a63d9dc5bcf516bdb4d818c3 blob + 50efbbc118ebd670512e80037968e4ab5146ea79 --- telescope.h +++ telescope.h @@ -351,6 +351,9 @@ int unicode_isspace(uint32_t); int unicode_isgraph(uint32_t); int dispatch_imsg(struct imsgev *, short, imsg_handlerfn **, size_t); int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, int, const void *, uint16_t); +void *hash_alloc(size_t, void *); +void *hash_calloc(size_t, size_t, void *); +void hash_free(void *, void *); /* wrap.c */ void erase_buffer(struct buffer *); blob - fa211ceb197301f961bddc1abf98b065eca6f140 blob + 44d124290db2b1e4e3e80987aed32e503a0ed8e4 --- tofu.c +++ tofu.c @@ -14,37 +14,13 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "telescope.h" +#include "compat.h" #include #include -static void *hash_alloc(size_t, void*); -static void *hash_calloc(size_t, size_t, void*); -static void hash_free(void*, void*); +#include "telescope.h" -static void * -hash_alloc(size_t len, void *d) -{ - if ((d = malloc(len)) == NULL) - abort(); - return d; -} - -static void * -hash_calloc(size_t nmemb, size_t size, void *d) -{ - if ((d = calloc(nmemb, size)) == NULL) - abort(); - return d; -} - -static void -hash_free(void *ptr, void *d) -{ - free(ptr); -} - void tofu_init(struct ohash *h, unsigned int sz, ptrdiff_t ko) { blob - 0c1b5d78e8ce1a182cba23a1248acc8ac065f9e5 blob + 41296df6a6181b9222ec5bcaf889f4a4dbac4563 --- util.c +++ util.c @@ -145,3 +145,25 @@ imsg_compose_event(struct imsgev *iev, uint16_t type, return ret; } + +void * +hash_alloc(size_t len, void *d) +{ + if ((d = malloc(len)) == NULL) + abort(); + return d; +} + +void * +hash_calloc(size_t nmemb, size_t size, void *d) +{ + if ((d = calloc(nmemb, size)) == NULL) + abort(); + return d; +} + +void +hash_free(void *ptr, void *d) +{ + free(ptr); +}