From 6150dcd14773517d5c0fff0fee7bc6fe6f75e086 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 23 Aug 2021 23:49:17 -0700 Subject: thunk_h: bump submodule for new lifecycle model Udpate thunk usage througout to explicitly control thunk instance lifecycles from calleees according to new model. This enables discarding a bunch of the per-object dispatch thunks, eliminates some thunk leaks, and I think generally makes the code more expressive and clear about what's going on. Keep in mind this is all experimental and and I'm not spending a whole lot of time on this, it's mostly a toy and exploring some different programming styles I'd never really consider for production/real work. Though it actually has some interesting properties, and produces some surprisingly succinct and readable listings at times once you have the cumbersome building blocks in place. Especially for non-daemon programs where you can basically either log+ignore errors or treat them as fatal, I think this programming style might actually have its place. --- src/verify-hashed-objects.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'src/verify-hashed-objects.c') diff --git a/src/verify-hashed-objects.c b/src/verify-hashed-objects.c index 8d79228..f5c2c74 100644 --- a/src/verify-hashed-objects.c +++ b/src/verify-hashed-objects.c @@ -174,17 +174,6 @@ THUNK_DEFINE_STATIC(per_hashed_object, journal_t *, journal, Header *, header, O return thunk_dispatch(closure); } -/* XXX TODO: this should prolly move into journals.[ch] now that it's - * in both here and report-entry-arrays.c - */ -THUNK_DEFINE_STATIC(per_object_dispatch, uint64_t *, iter_offset, thunk_t *, closure) -{ - if (!(*iter_offset)) - return thunk_dispatch(closure); - - return thunk_dispatch_keep(closure); -} - THUNK_DEFINE_STATIC(per_object, thunk_t *, self, iou_t *, iou, journal_t **, journal, Header *, header, uint64_t *, iter_offset, ObjectHeader *, iter_object_header, Object **, iter_object, void **, decompressed) { @@ -201,8 +190,7 @@ THUNK_DEFINE_STATIC(per_object, thunk_t *, self, iou_t *, iou, journal_t **, jou /* skip non-hashed objects */ if (iter_object_header->type != OBJECT_FIELD && iter_object_header->type != OBJECT_DATA) - return journal_iter_next_object(iou, journal, header, iter_offset, iter_object_header, THUNK( - per_object_dispatch(iter_offset, self))); + return thunk_mid(journal_iter_next_object(iou, journal, header, iter_offset, iter_object_header, self)); if (malloc_usable_size(*iter_object) < iter_object_header->size) { free(*iter_object); @@ -212,10 +200,9 @@ THUNK_DEFINE_STATIC(per_object, thunk_t *, self, iou_t *, iou, journal_t **, jou return -ENOMEM; } - return journal_get_object(iou, journal, iter_offset, &iter_object_header->size, iter_object, THUNK( + return thunk_mid(journal_get_object(iou, journal, iter_offset, &iter_object_header->size, iter_object, THUNK( per_hashed_object(*journal, header, iter_object, decompressed, THUNK( - journal_iter_next_object(iou, journal, header, iter_offset, iter_object_header, THUNK( - per_object_dispatch(iter_offset, self))))))); + journal_iter_next_object(iou, journal, header, iter_offset, iter_object_header, self)))))); } @@ -240,9 +227,8 @@ THUNK_DEFINE_STATIC(per_journal, iou_t *, iou, journal_t **, journal_iter) foo->iter_object = foo->decompressed = NULL; return journal_get_header(iou, &foo->journal, &foo->header, THUNK( - journal_iter_next_object(iou, &foo->journal, &foo->header, &foo->iter_offset, &foo->iter_object_header, THUNK( - per_object_dispatch(&foo->iter_offset, THUNK_INIT( - per_object(closure, closure, iou, &foo->journal, &foo->header, &foo->iter_offset, &foo->iter_object_header, &foo->iter_object, &foo->decompressed))))))); + journal_iter_next_object(iou, &foo->journal, &foo->header, &foo->iter_offset, &foo->iter_object_header, THUNK_INIT( + per_object(closure, closure, iou, &foo->journal, &foo->header, &foo->iter_offset, &foo->iter_object_header, &foo->iter_object, &foo->decompressed))))); } -- cgit v1.2.3