From e5226da128493945a2248331c6ad30f14f5ac7a2 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 13 Aug 2023 22:54:39 -0700 Subject: til_stream: return skipped count from til_stream_gc_module_contexts() Preparatory commit for making til_stream_free() assert on leaked module contexts. --- src/til_stream.c | 15 +++++++++++---- src/til_stream.h | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/til_stream.c b/src/til_stream.c index 021e0d4..0f35a17 100644 --- a/src/til_stream.c +++ b/src/til_stream.c @@ -646,9 +646,10 @@ int til_stream_find_module_contexts(til_stream_t *stream, const char *path, size } -void til_stream_gc_module_contexts(til_stream_t *stream) +/* returns count of remaining contexts or zero if none remain */ +unsigned til_stream_gc_module_contexts(til_stream_t *stream) { - unsigned freed; + unsigned freed, skipped; assert(stream); @@ -668,6 +669,7 @@ void til_stream_gc_module_contexts(til_stream_t *stream) */ do { freed = 0; + skipped = 0; for (size_t b = 0; b < TIL_STREAM_CTXT_BUCKETS_COUNT; b++) { til_stream_module_context_t *c, *c_prev, *c_next; @@ -684,6 +686,7 @@ void til_stream_gc_module_contexts(til_stream_t *stream) if (i < c->n_module_contexts) { c_prev = c; + skipped++; continue; } @@ -697,13 +700,17 @@ void til_stream_gc_module_contexts(til_stream_t *stream) freed = 1; } - if (c_prev) + + if (c_prev) { c_prev->next = c_next; - else + } else { stream->module_context_buckets[b] = c_next; + } } } } while (freed); + + return skipped; } diff --git a/src/til_stream.h b/src/til_stream.h index 5473aec..eab078c 100644 --- a/src/til_stream.h +++ b/src/til_stream.h @@ -74,7 +74,7 @@ int til_stream_for_each_module_context(til_stream_t *stream, til_stream_module_c int til_stream_register_module_contexts(til_stream_t *stream, size_t n_contexts, til_module_context_t **contexts); int til_stream_find_module_contexts(til_stream_t *stream, const char *path, size_t n_contexts, til_module_context_t **res_contexts); -void til_stream_gc_module_contexts(til_stream_t *stream); +unsigned til_stream_gc_module_contexts(til_stream_t *stream); void til_stream_fprint_module_contexts(til_stream_t *stream, FILE *out); #endif -- cgit v1.2.1