From b31e82aaf8fe4ea7f858dd6ece98169765d2e9d3 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 28 May 2026 20:53:53 +0100 Subject: [PATCH] fx.io: update iterator semantics --- fx.io/sys/apple/directory.c | 17 ++++++----------- fx.io/test/tree.c | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/fx.io/sys/apple/directory.c b/fx.io/sys/apple/directory.c index a65ff3b..1b0173f 100644 --- a/fx.io/sys/apple/directory.c +++ b/fx.io/sys/apple/directory.c @@ -35,6 +35,7 @@ struct fx_directory_iterator_p { fx_directory *root; fx_directory_entry entry; + fx_value entry_value; }; /*** PRIVATE FUNCTIONS ********************************************************/ @@ -375,8 +376,6 @@ fx_result fx_directory_open_temp(fx_directory **out) fx_path_unlink(rpath); fx_path_unref(rpath); - - return status; } } @@ -512,6 +511,8 @@ static void update_iterator_data(struct fx_directory_iterator_p *it) fx_path *path = fx_path_create_from_cstr( ent->fts_path + fx_path_length(it->_p->d_path_abs) + 1); + fx_value_unset(&it->entry_value); + it->entry_value = FX_POINTER(&it->entry); it->entry.filename = ent->fts_name; it->entry.filepath = path; @@ -619,12 +620,7 @@ fx_iterator *fx_directory_begin( return it_obj; } -static fx_iterator *iterator_begin(fx_object *obj) -{ - return fx_directory_begin(obj, FX_DIRECTORY_ITERATE_PARENT_FIRST); -} - -static const fx_iterator *iterator_cbegin(const fx_object *obj) +static const fx_iterator *iterator_begin(const fx_object *obj) { return fx_directory_begin( (fx_object *)obj, @@ -698,13 +694,13 @@ static enum fx_status iterator_erase(fx_iterator *obj) return iterator_move_next(obj); } -static fx_value iterator_get_value(const fx_iterator *obj) +static const fx_value *iterator_get_value(const fx_iterator *obj) { struct fx_directory_iterator_p *it = fx_object_get_private( obj, FX_TYPE_DIRECTORY_ITERATOR); - return FX_POINTER(&it->entry); + return &it->entry_value; } /*** CLASS DEFINITION *********************************************************/ @@ -717,7 +713,6 @@ FX_TYPE_CLASS_BEGIN(fx_directory) FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE) FX_INTERFACE_ENTRY(it_begin) = iterator_begin; - FX_INTERFACE_ENTRY(it_cbegin) = iterator_cbegin; FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE) FX_TYPE_CLASS_END(fx_directory) diff --git a/fx.io/test/tree.c b/fx.io/test/tree.c index 91cd936..309e62e 100644 --- a/fx.io/test/tree.c +++ b/fx.io/test/tree.c @@ -26,7 +26,7 @@ int main(int argc, const char **argv) fx_foreach(val, it) { fx_directory_entry *entry = NULL; - fx_value_get_pointer(&val, (void **)&entry); + fx_value_get_pointer(val, (void **)&entry); printf("%s\n", fx_path_ptr(entry->filepath)); }