From 11c8aed35423fed9c94cda956f10ad713e217e38 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Fri, 9 Nov 2018 10:52:15 -0600 Subject: [PATCH] Added API for user provided iterators. --- src/excit.c | 20 +++++++++++++++++++- src/excit.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/excit.c b/src/excit.c index d6f11b3..05213af 100644 --- a/src/excit.c +++ b/src/excit.c @@ -1538,6 +1538,21 @@ error: return NULL; } +excit_t excit_alloc_user(const struct excit_func_table_s *functions) +{ + excit_t it; + + it = malloc(sizeof(const struct excit_s)); + if (!it) + return NULL; + ALLOC_EXCIT(it, (*functions)); + it->type = EXCIT_USER; + return it; +error: + free(it); + return NULL; +} + excit_t excit_dup(excit_t it) { excit_t result = NULL; @@ -1559,10 +1574,13 @@ error: void excit_free(excit_t it) { - if (!it || !it->functions) + if (!it) return; + if (!it->functions) + goto error; if (it->functions->free) it->functions->free(it); +error: free(it); } diff --git a/src/excit.h b/src/excit.h index 2e553f3..6605d2a 100644 --- a/src/excit.h +++ b/src/excit.h @@ -8,6 +8,7 @@ enum excit_type_e { EXCIT_HILBERT2D, EXCIT_PRODUCT, EXCIT_SLICE, + EXCIT_USER, EXCIT_TYPE_MAX }; @@ -45,6 +46,7 @@ struct excit_func_table_s { }; excit_t excit_alloc(enum excit_type_e type); +excit_t excit_alloc_user(const struct excit_func_table_s *functions); excit_t excit_dup(const excit_t it); void excit_free(excit_t it); -- 2.26.2