From 6d3cdfb888ecbedfcbe398be389d80ddedf34df2 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Tue, 29 Aug 2023 18:40:29 +0200 Subject: [PATCH] easy: use generic collector for easy directory This commit updates cextras to the latest version and implements the generic collector for easy directory instead of implementing it manually. --- lib/easy/directory.c | 77 +++---------- .../.clang-format | 0 .../.clang-tidy | 0 .../.editorconfig | 0 .../.github/ISSUE_TEMPLATE/bug_report.md | 0 .../.github/ISSUE_TEMPLATE/feature_request.md | 0 .../.github/workflows/ci.yaml | 0 .../.gitignore | 0 .../.meson-subproject-wrap-hash.txt | 1 + .../Makefile | 0 .../README.md | 0 .../include/cextras/collection.h | 11 +- .../include/cextras/concurrency.h | 0 .../include/cextras/endian_compat.h | 0 .../include/cextras/error.h | 0 .../include/cextras/macro.h | 0 .../include/cextras/types.h | 0 .../include/meson.build | 0 .../lib/collection/buffer.c | 0 .../lib/collection/collector.c | 78 +++++++++++++ .../lib/collection/lru.c | 0 .../lib/collection/meson.build | 1 + .../lib/collection/rc_hash_map.c | 0 .../lib/collection/rc_map.c | 0 .../lib/concurrency/future.c | 0 .../lib/concurrency/meson.build | 0 .../lib/concurrency/threadpool.c | 0 .../lib/meson.build | 0 .../meson.build | 0 .../meson_options.txt | 0 .../testlib/driver.c | 0 .../testlib/include/testlib.h | 0 .../testlib/meson.build | 0 .../tests/collection/buffer_test.c | 0 .../tests/collection/collector.c | 104 ++++++++++++++++++ .../tests/collection/lru_test.c | 0 .../tests/collection/rc_hash_map_test.c | 0 .../tests/collection/rc_map_test.c | 0 .../tests/concurrency/future_test.c | 0 .../tests/concurrency/threadpool_test.c | 0 .../tests/meson.build | 1 + .../tests/testlib.c | 0 .../tests/testlib.cpp | 0 .../.meson-subproject-wrap-hash.txt | 1 - subprojects/cextras.wrap | 8 +- test/easy/directory.c | 2 +- 46 files changed, 217 insertions(+), 67 deletions(-) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/.clang-format (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/.clang-tidy (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/.editorconfig (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/.github/ISSUE_TEMPLATE/bug_report.md (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/.github/ISSUE_TEMPLATE/feature_request.md (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/.github/workflows/ci.yaml (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/.gitignore (100%) create mode 100644 subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.meson-subproject-wrap-hash.txt rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/Makefile (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/README.md (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/include/cextras/collection.h (98%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/include/cextras/concurrency.h (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/include/cextras/endian_compat.h (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/include/cextras/error.h (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/include/cextras/macro.h (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/include/cextras/types.h (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/include/meson.build (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/lib/collection/buffer.c (100%) create mode 100644 subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/collector.c rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/lib/collection/lru.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/lib/collection/meson.build (82%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/lib/collection/rc_hash_map.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/lib/collection/rc_map.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/lib/concurrency/future.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/lib/concurrency/meson.build (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/lib/concurrency/threadpool.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/lib/meson.build (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/meson.build (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/meson_options.txt (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/testlib/driver.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/testlib/include/testlib.h (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/testlib/meson.build (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/tests/collection/buffer_test.c (100%) create mode 100644 subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/collector.c rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/tests/collection/lru_test.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/tests/collection/rc_hash_map_test.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/tests/collection/rc_map_test.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/tests/concurrency/future_test.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/tests/concurrency/threadpool_test.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/tests/meson.build (94%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/tests/testlib.c (100%) rename subprojects/{cextras-990106e5492c382669a7238a2e291d655c19fedb => cextras-04517a4939153026a9ccdf2778ed11403be6f4e7}/tests/testlib.cpp (100%) delete mode 100644 subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.meson-subproject-wrap-hash.txt diff --git a/lib/easy/directory.c b/lib/easy/directory.c index 7c35438e2..a4535dca1 100644 --- a/lib/easy/directory.c +++ b/lib/easy/directory.c @@ -46,86 +46,43 @@ #include "../../include/sqsh_file_private.h" #include "../../include/sqsh_tree_private.h" +static int +directory_collector_next(void *iterator, const char **value, size_t *size) { + int rv = 0; + if (sqsh_directory_iterator_next(iterator, &rv)) { + *value = sqsh_directory_iterator_name(iterator); + *size = (size_t)sqsh_directory_iterator_name_size(iterator); + } + return rv; +} + char ** -sqsh_easy_directory_list( - struct SqshArchive *archive, const char *path, int *err) { +sqsh_easy_directory_list(struct SqshArchive *archive, const char *path, int *err) { int rv = 0; - static const uintptr_t nullptr = 0; - struct CxBuffer dir_list = {0}; - struct CxBuffer dir_list_names = {0}; - size_t elements = 0; struct SqshFile *file = NULL; - struct SqshDirectoryIterator *iterator = NULL; - char **dir_list_data = NULL; + struct SqshDirectoryIterator iterator = {0}; + char **list = NULL; file = sqsh_open(archive, path, &rv); if (rv < 0) { goto out; } - if (sqsh_file_type(file) != SQSH_FILE_TYPE_DIRECTORY) { - rv = -SQSH_ERROR_NOT_A_DIRECTORY; - goto out; - } - - rv = cx_buffer_init(&dir_list); - if (rv < 0) { - goto out; - } - rv = cx_buffer_init(&dir_list_names); - if (rv < 0) { - goto out; - } - - iterator = sqsh_directory_iterator_new(file, &rv); + rv = sqsh__directory_iterator_init(&iterator, file); if (rv < 0) { goto out; } - while (sqsh_directory_iterator_next(iterator, &rv)) { - const char *name = sqsh_directory_iterator_name(iterator); - size_t name_len = sqsh_directory_iterator_name_size(iterator); - size_t index = cx_buffer_size(&dir_list_names); - char *index_ptr = (void *)index; - elements++; - rv = cx_buffer_append(&dir_list, (uint8_t *)&index_ptr, sizeof(char *)); - if (rv < 0) { - goto out; - } - rv = cx_buffer_append(&dir_list_names, (uint8_t *)name, name_len); - if (rv < 0) { - goto out; - } - rv = cx_buffer_append( - &dir_list_names, (uint8_t *)&nullptr, sizeof(char)); - if (rv < 0) { - goto out; - } - } - - rv = cx_buffer_append(&dir_list, (uint8_t *)&nullptr, sizeof(char *)); - size_t base_size = cx_buffer_size(&dir_list); - - const uint8_t *names_data = cx_buffer_data(&dir_list_names); - size_t names_size = cx_buffer_size(&dir_list_names); - rv = cx_buffer_append(&dir_list, names_data, names_size); + rv = cx_collect(&list, directory_collector_next, &iterator); if (rv < 0) { goto out; } - dir_list_data = (char **)cx_buffer_unwrap(&dir_list); - - for (sqsh_index_t i = 0; i < elements; i++) { - dir_list_data[i] += base_size + (uintptr_t)dir_list_data; - } - out: - sqsh_directory_iterator_free(iterator); - cx_buffer_cleanup(&dir_list); - cx_buffer_cleanup(&dir_list_names); + sqsh__directory_iterator_cleanup(&iterator); sqsh_close(file); if (err) { *err = rv; } - return dir_list_data; + return list; } diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.clang-format b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.clang-format similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.clang-format rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.clang-format diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.clang-tidy b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.clang-tidy similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.clang-tidy rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.clang-tidy diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.editorconfig b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.editorconfig similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.editorconfig rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.editorconfig diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.github/ISSUE_TEMPLATE/bug_report.md b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.github/ISSUE_TEMPLATE/bug_report.md similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.github/ISSUE_TEMPLATE/bug_report.md rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.github/ISSUE_TEMPLATE/bug_report.md diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.github/ISSUE_TEMPLATE/feature_request.md b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.github/ISSUE_TEMPLATE/feature_request.md similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.github/ISSUE_TEMPLATE/feature_request.md rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.github/ISSUE_TEMPLATE/feature_request.md diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.github/workflows/ci.yaml b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.github/workflows/ci.yaml similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.github/workflows/ci.yaml rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.github/workflows/ci.yaml diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.gitignore b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.gitignore similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.gitignore rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.gitignore diff --git a/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.meson-subproject-wrap-hash.txt b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.meson-subproject-wrap-hash.txt new file mode 100644 index 000000000..86bb2b8f2 --- /dev/null +++ b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/.meson-subproject-wrap-hash.txt @@ -0,0 +1 @@ +c65f3da22779c3e7b3935233687cd5ed017464a7d70eef65eb95a29865d37099 diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/Makefile b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/Makefile similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/Makefile rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/Makefile diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/README.md b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/README.md similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/README.md rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/README.md diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/collection.h b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/collection.h similarity index 98% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/collection.h rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/collection.h index 6bd8973de..73560b9d5 100644 --- a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/collection.h +++ b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/collection.h @@ -518,7 +518,7 @@ CX_NO_UNUSED int cx_lru_touch(struct CxLru *lru, size_t id); int cx_lru_cleanup(struct CxLru *lru); /*************************************** - * primitive/reader.c + * collection/reader.c */ /** @@ -556,6 +556,15 @@ struct CxReader { const uint8_t *data; }; +/*************************************** + * collection/collector.c + */ + +typedef int (*cx_collector_next_t)( + void *iterator, const char **value, size_t *size); + +int cx_collect(char ***target, cx_collector_next_t next, void *iterator); + #ifdef __cplusplus } #endif diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/concurrency.h b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/concurrency.h similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/concurrency.h rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/concurrency.h diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/endian_compat.h b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/endian_compat.h similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/endian_compat.h rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/endian_compat.h diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/error.h b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/error.h similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/error.h rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/error.h diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/macro.h b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/macro.h similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/macro.h rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/macro.h diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/types.h b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/types.h similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/cextras/types.h rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/cextras/types.h diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/meson.build b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/meson.build similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/include/meson.build rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/include/meson.build diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/buffer.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/buffer.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/buffer.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/buffer.c diff --git a/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/collector.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/collector.c new file mode 100644 index 000000000..3d4e49afa --- /dev/null +++ b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/collector.c @@ -0,0 +1,78 @@ +/** + * @author : Enno Boland (mail@eboland.de) + * @file : iterator_collector + * @created : Tuesday Aug 29, 2023 17:27:35 CEST + */ + +#include "../../include/cextras/collection.h" +#include "../../include/cextras/error.h" + +int +cx_collect(char ***target, cx_collector_next_t next, void *iterator) { + int rv = 0; + static const uintptr_t nullptr = 0; + struct CxBuffer list = {0}; + struct CxBuffer list_values = {0}; + size_t elements = 0; + char **result = NULL; + + rv = cx_buffer_init(&list); + if (rv < 0) { + goto out; + } + rv = cx_buffer_init(&list_values); + if (rv < 0) { + goto out; + } + + for (;;) { + const char *value = NULL; + size_t size = 0; + + rv = next(iterator, &value, &size); + if (rv < 0) { + goto out; + } + if (value == NULL) { + break; + } + + size_t index = cx_buffer_size(&list_values); + char *index_ptr = (void *)index; + elements++; + rv = cx_buffer_append(&list, (uint8_t *)&index_ptr, sizeof(char *)); + if (rv < 0) { + goto out; + } + rv = cx_buffer_append(&list_values, (uint8_t *)value, size); + if (rv < 0) { + goto out; + } + rv = cx_buffer_append(&list_values, (uint8_t *)&nullptr, sizeof(char)); + if (rv < 0) { + goto out; + } + } + + rv = cx_buffer_append(&list, (uint8_t *)&nullptr, sizeof(char *)); + size_t base_size = cx_buffer_size(&list); + + const uint8_t *values_data = cx_buffer_data(&list_values); + size_t values_size = cx_buffer_size(&list_values); + + rv = cx_buffer_append(&list, values_data, values_size); + if (rv < 0) { + goto out; + } + + result = (char **)cx_buffer_unwrap(&list); + for (cx_index_t i = 0; i < elements; i++) { + result[i] += base_size + (uintptr_t)result; + } + *target = result; + +out: + cx_buffer_cleanup(&list); + cx_buffer_cleanup(&list_values); + return rv; +} diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/lru.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/lru.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/lru.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/lru.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/meson.build b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/meson.build similarity index 82% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/meson.build rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/meson.build index a1b00a97c..e0a8e3380 100644 --- a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/meson.build +++ b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/meson.build @@ -1,5 +1,6 @@ collection_src = files( 'buffer.c', + 'collector.c', 'lru.c', 'rc_hash_map.c', 'rc_map.c', diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/rc_hash_map.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/rc_hash_map.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/rc_hash_map.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/rc_hash_map.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/rc_map.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/rc_map.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/collection/rc_map.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/collection/rc_map.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/concurrency/future.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/concurrency/future.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/concurrency/future.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/concurrency/future.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/concurrency/meson.build b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/concurrency/meson.build similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/concurrency/meson.build rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/concurrency/meson.build diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/concurrency/threadpool.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/concurrency/threadpool.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/concurrency/threadpool.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/concurrency/threadpool.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/meson.build b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/meson.build similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/lib/meson.build rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/lib/meson.build diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/meson.build b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/meson.build similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/meson.build rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/meson.build diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/meson_options.txt b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/meson_options.txt similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/meson_options.txt rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/meson_options.txt diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/testlib/driver.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/testlib/driver.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/testlib/driver.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/testlib/driver.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/testlib/include/testlib.h b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/testlib/include/testlib.h similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/testlib/include/testlib.h rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/testlib/include/testlib.h diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/testlib/meson.build b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/testlib/meson.build similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/testlib/meson.build rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/testlib/meson.build diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/collection/buffer_test.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/buffer_test.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/collection/buffer_test.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/buffer_test.c diff --git a/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/collector.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/collector.c new file mode 100644 index 000000000..1ed61edfb --- /dev/null +++ b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/collector.c @@ -0,0 +1,104 @@ +/* + * BSD 2-Clause License + * + * Copyright (c) 2023, Enno Boland + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Enno Boland (mail@eboland.de) + * @file rc_map.c + */ + +#include +#include +#include +#include +#include +#include + +#define LENGTH(x) (sizeof(x) / sizeof(*x)) + +struct TestCollectIter { + cx_index_t index; + char **array; + size_t size; + int rv; +}; + +static int +test_collect_next(void *iter, const char **value, size_t *size) { + struct TestCollectIter *i = iter; + if (i->index >= i->size) { + return i->rv; + } + *value = i->array[i->index]; + *size = strlen(i->array[i->index]); + i->index++; + return i->rv; +} + +static void +collector(void) { + int rv = 0; + char *values[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}; + char **target = NULL; + struct TestCollectIter iter = { + .index = 0, + .array = values, + .size = LENGTH(values), + }; + + rv = cx_collect(&target, test_collect_next, &iter); + assert(rv == 0); + + for (size_t i = 0; i < LENGTH(values); i++) { + assert(strcmp(values[i], target[i]) == 0); + } + assert(target[LENGTH(values)] == NULL); + free(target); +} + +static void +collector_fail(void) { + int rv = 0; + char *values[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}; + char **target = NULL; + struct TestCollectIter iter = { + .index = 0, + .array = values, + .size = LENGTH(values), + .rv = -1, + }; + + rv = cx_collect(&target, test_collect_next, &iter); + assert(rv == -1); + assert(target == NULL); +} + +DECLARE_TESTS +TEST(collector) +TEST(collector_fail) +END_TESTS diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/collection/lru_test.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/lru_test.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/collection/lru_test.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/lru_test.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/collection/rc_hash_map_test.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/rc_hash_map_test.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/collection/rc_hash_map_test.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/rc_hash_map_test.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/collection/rc_map_test.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/rc_map_test.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/collection/rc_map_test.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/collection/rc_map_test.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/concurrency/future_test.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/concurrency/future_test.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/concurrency/future_test.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/concurrency/future_test.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/concurrency/threadpool_test.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/concurrency/threadpool_test.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/concurrency/threadpool_test.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/concurrency/threadpool_test.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/meson.build b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/meson.build similarity index 94% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/meson.build rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/meson.build index 5e3a44381..34f5c24fa 100644 --- a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/meson.build +++ b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/meson.build @@ -6,6 +6,7 @@ tests = [ 'concurrency/threadpool_test.c', 'concurrency/future_test.c', 'collection/buffer_test.c', + 'collection/collector.c', 'collection/lru_test.c', 'collection/rc_hash_map_test.c', 'collection/rc_map_test.c', diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/testlib.c b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/testlib.c similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/testlib.c rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/testlib.c diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/testlib.cpp b/subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/testlib.cpp similarity index 100% rename from subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/tests/testlib.cpp rename to subprojects/cextras-04517a4939153026a9ccdf2778ed11403be6f4e7/tests/testlib.cpp diff --git a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.meson-subproject-wrap-hash.txt b/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.meson-subproject-wrap-hash.txt deleted file mode 100644 index 26d14a62d..000000000 --- a/subprojects/cextras-990106e5492c382669a7238a2e291d655c19fedb/.meson-subproject-wrap-hash.txt +++ /dev/null @@ -1 +0,0 @@ -e70215fb6a380f912b876c2bff3e251d358cfe38ebb79715be16c4a5c4e6d24a diff --git a/subprojects/cextras.wrap b/subprojects/cextras.wrap index 30cca98eb..5efd280f2 100644 --- a/subprojects/cextras.wrap +++ b/subprojects/cextras.wrap @@ -1,9 +1,9 @@ [wrap-file] -directory = cextras-990106e5492c382669a7238a2e291d655c19fedb +directory = cextras-04517a4939153026a9ccdf2778ed11403be6f4e7 -source_url = https://github.com/Gottox/cextras/archive/990106e5492c382669a7238a2e291d655c19fedb.tar.gz -source_filename = cextras-990106e5492c382669a7238a2e291d655c19fedb.tar.gz -source_hash = fdfedf3e143f3dfeb1ca6ae970ba52f94fa5929742b0196f6b784f66ba20d2cb +source_url = https://github.com/Gottox/cextras/archive/04517a4939153026a9ccdf2778ed11403be6f4e7.tar.gz +source_filename = cextras-04517a4939153026a9ccdf2778ed11403be6f4e7.tar.gz +source_hash = 572e6fc8d9bd17367926a36583a2b06974b7236ad40d571ba30f471359c1b78e [provide] cextras=cextras_dep diff --git a/test/easy/directory.c b/test/easy/directory.c index d9934cb3a..7eeb58d12 100644 --- a/test/easy/directory.c +++ b/test/easy/directory.c @@ -49,7 +49,7 @@ list_two_files(void) { /* inode */ [INODE_TABLE_OFFSET] = METABLOCK_HEADER(0, 1024), INODE_HEADER(1, 0, 0, 0, 0, 1), - INODE_BASIC_DIR(0, 1024, 0, 0), + INODE_BASIC_DIR(0, 33, 0, 0), [INODE_TABLE_OFFSET+2+128] = INODE_HEADER(3, 0, 0, 0, 0, 2), INODE_BASIC_SYMLINK(3),