From 049d23ab28f2708506dbde362539e9b5f36a10c4 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Sun, 12 Nov 2023 19:45:08 +0100 Subject: Update liblist api and remote --- src/ref.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/ref.c') diff --git a/src/ref.c b/src/ref.c index 4960852..b628d51 100644 --- a/src/ref.c +++ b/src/ref.c @@ -1,6 +1,9 @@ #include "ref.h" +#include "list.h" #include "util.h" +#include + struct ref * ref_alloc(void *data) { @@ -9,7 +12,7 @@ ref_alloc(void *data) ref = malloc(sizeof(struct ref)); if (!ref) ERROR(SYSTEM, "malloc"); - ref->link = LINK_EMPTY; + ref->link = LIST_LINK_INIT; ref->data = data; return ref; @@ -24,19 +27,19 @@ ref_free(void *ref) void refs_free(struct list *list) { - list_free(list, ref_free, LINK_OFFSET(struct ref, link)); + list_free_items(list, ref_free, LIST_OFFSET(struct ref, link)); } int refs_index(struct list *list, void *data) { - struct link *iter; + struct list_link *iter; struct ref *ref; int index; index = 0; for (LIST_ITER(list, iter)) { - ref = UPCAST(iter, struct ref, link); + ref = LIST_UPCAST(iter, struct ref, link); if (ref->data == data) return index; index++; @@ -45,14 +48,14 @@ refs_index(struct list *list, void *data) return -1; } -struct link * +struct list_link * refs_find(struct list *list, void *data) { - struct link *iter; + struct list_link *iter; struct ref *ref; for (LIST_ITER(list, iter)) { - ref = UPCAST(iter, struct ref, link); + ref = LIST_UPCAST(iter, struct ref, link); if (ref->data == data) return iter; } @@ -63,7 +66,7 @@ refs_find(struct list *list, void *data) int refs_incl(struct list *list, void *data) { - struct link *ref; + struct list_link *ref; ref = refs_find(list, data); @@ -73,14 +76,14 @@ refs_incl(struct list *list, void *data) void refs_rm(struct list *list, void *data) { - struct link *ref; + struct list_link *ref; struct ref *dataref; ref = refs_find(list, data); if (!ref) return; - dataref = UPCAST(ref, struct ref, link); - link_pop(ref); + dataref = LIST_UPCAST(ref, struct ref, link); + list_link_pop(ref); free(dataref); } -- cgit v1.2.3-71-gd317