diff options
author | David Robillard <d@drobilla.net> | 2024-11-15 08:53:26 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-11-15 08:53:26 -0500 |
commit | c79edf4df9909bdb1313e74bb9cc7c8ea7936dcb (patch) | |
tree | a9a6642536eeb5860ae6c1eaaa74ba523385d7c8 | |
parent | 336aad280221ce643255032e948acccc27e7204f (diff) | |
download | zix-c79edf4df9909bdb1313e74bb9cc7c8ea7936dcb.tar.gz zix-c79edf4df9909bdb1313e74bb9cc7c8ea7936dcb.tar.bz2 zix-c79edf4df9909bdb1313e74bb9cc7c8ea7936dcb.zip |
Update clang-format configuration
-rw-r--r-- | .clang-format | 25 | ||||
-rw-r--r-- | benchmark/dict_bench.c | 3 | ||||
-rw-r--r-- | doc/overview_code.c | 3 | ||||
-rw-r--r-- | include/zix/allocator.h | 15 | ||||
-rw-r--r-- | include/zix/attributes.h | 15 | ||||
-rw-r--r-- | include/zix/btree.h | 47 | ||||
-rw-r--r-- | include/zix/bump_allocator.h | 3 | ||||
-rw-r--r-- | include/zix/digest.h | 18 | ||||
-rw-r--r-- | include/zix/filesystem.h | 58 | ||||
-rw-r--r-- | include/zix/hash.h | 49 | ||||
-rw-r--r-- | include/zix/path.h | 70 | ||||
-rw-r--r-- | include/zix/ring.h | 44 | ||||
-rw-r--r-- | include/zix/sem.h | 18 | ||||
-rw-r--r-- | include/zix/status.h | 3 | ||||
-rw-r--r-- | include/zix/string_view.h | 18 | ||||
-rw-r--r-- | include/zix/thread.h | 6 | ||||
-rw-r--r-- | include/zix/tree.h | 46 | ||||
-rw-r--r-- | src/allocator.c | 9 | ||||
-rw-r--r-- | src/btree.c | 9 | ||||
-rw-r--r-- | src/bump_allocator.c | 15 | ||||
-rw-r--r-- | src/errno_status.h | 6 | ||||
-rw-r--r-- | src/path.c | 18 | ||||
-rw-r--r-- | src/path_iter.h | 6 | ||||
-rw-r--r-- | src/posix/filesystem_posix.c | 3 | ||||
-rw-r--r-- | test/failing_allocator.c | 12 | ||||
-rw-r--r-- | test/test_btree.c | 3 | ||||
-rw-r--r-- | test/test_digest.c | 3 | ||||
-rw-r--r-- | test/test_hash.c | 27 | ||||
-rw-r--r-- | test/test_ring.c | 3 |
29 files changed, 183 insertions, 372 deletions
diff --git a/.clang-format b/.clang-format index 6245b22..808c8b5 100644 --- a/.clang-format +++ b/.clang-format @@ -1,10 +1,21 @@ -# Copyright 2020-2022 David Robillard <d@drobilla.net> +# Copyright 2020-2024 David Robillard <d@drobilla.net> # SPDX-License-Identifier: 0BSD OR ISC --- AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true -AlignEscapedNewlinesLeft: true +AlignEscapedNewlines: Left +AttributeMacros: + - ZIX_ALWAYS_INLINE_FUNC + - ZIX_API + - ZIX_CONST_API + - ZIX_CONST_FUNC + - ZIX_MALLOC_API + - ZIX_MALLOC_FUNC + - ZIX_NODISCARD + - ZIX_PURE_API + - ZIX_PURE_FUNC + - ZIX_PURE_WIN_API BasedOnStyle: Mozilla BraceWrapping: AfterEnum: false @@ -20,17 +31,7 @@ KeepEmptyLinesAtTheStartOfBlocks: false SpacesInContainerLiterals: false StatementMacros: - FALLTHROUGH - - ZIX_ALWAYS_INLINE_FUNC - - ZIX_API - ZIX_BEGIN_DECLS - - ZIX_CONST_API - - ZIX_CONST_FUNC - ZIX_END_DECLS - - ZIX_MALLOC_API - - ZIX_MALLOC_FUNC - - ZIX_NODISCARD - - ZIX_PURE_API - - ZIX_PURE_FUNC - - ZIX_PURE_WIN_API - _Pragma ... diff --git a/benchmark/dict_bench.c b/benchmark/dict_bench.c index 279e6ad..5d9acd0 100644 --- a/benchmark/dict_bench.c +++ b/benchmark/dict_bench.c @@ -45,8 +45,7 @@ lcg64(const uint64_t i) return (a * i) + c; } -ZIX_PURE_FUNC -static const ZixChunk* +ZIX_PURE_FUNC static const ZixChunk* identity(const ZixChunk* record) { return record; diff --git a/doc/overview_code.c b/doc/overview_code.c index 2f6a099..026467d 100644 --- a/doc/overview_code.c +++ b/doc/overview_code.c @@ -39,8 +39,7 @@ string_views(void) // end make-string-view } -ZIX_CONST_FUNC -int +ZIX_CONST_FUNC int main(void) { string_views(); diff --git a/include/zix/allocator.h b/include/zix/allocator.h index bace039..6c9a61d 100644 --- a/include/zix/allocator.h +++ b/include/zix/allocator.h @@ -103,13 +103,11 @@ struct ZixAllocatorImpl { }; /// Return the default allocator which simply uses the system allocator -ZIX_CONST_API -ZixAllocator* ZIX_NONNULL +ZIX_CONST_API ZixAllocator* ZIX_NONNULL zix_default_allocator(void); /// Convenience wrapper that defers to malloc() if allocator is null -ZIX_MALLOC_FUNC -static inline void* ZIX_ALLOCATED +ZIX_MALLOC_FUNC static inline void* ZIX_ALLOCATED zix_malloc(ZixAllocator* const ZIX_NULLABLE allocator, const size_t size) { ZixAllocator* const actual = allocator ? allocator : zix_default_allocator(); @@ -118,8 +116,7 @@ zix_malloc(ZixAllocator* const ZIX_NULLABLE allocator, const size_t size) } /// Convenience wrapper that defers to calloc() if allocator is null -ZIX_MALLOC_FUNC -static inline void* ZIX_ALLOCATED +ZIX_MALLOC_FUNC static inline void* ZIX_ALLOCATED zix_calloc(ZixAllocator* const ZIX_NULLABLE allocator, const size_t nmemb, const size_t size) @@ -130,8 +127,7 @@ zix_calloc(ZixAllocator* const ZIX_NULLABLE allocator, } /// Convenience wrapper that defers to realloc() if allocator is null -ZIX_NODISCARD -static inline void* ZIX_ALLOCATED +ZIX_NODISCARD static inline void* ZIX_ALLOCATED zix_realloc(ZixAllocator* const ZIX_NULLABLE allocator, void* const ZIX_NULLABLE ptr, const size_t size) @@ -152,8 +148,7 @@ zix_free(ZixAllocator* const ZIX_NULLABLE allocator, } /// Convenience wrapper that defers to the system allocator if allocator is null -ZIX_MALLOC_FUNC -static inline void* ZIX_ALLOCATED +ZIX_MALLOC_FUNC static inline void* ZIX_ALLOCATED zix_aligned_alloc(ZixAllocator* const ZIX_NULLABLE allocator, const size_t alignment, const size_t size) diff --git a/include/zix/attributes.h b/include/zix/attributes.h index 249e6a6..f92f2b0 100644 --- a/include/zix/attributes.h +++ b/include/zix/attributes.h @@ -48,22 +48,13 @@ #endif /// A pure function in the public API that only reads memory -#define ZIX_PURE_API \ - ZIX_API \ - ZIX_PURE_FUNC \ - ZIX_NODISCARD +#define ZIX_PURE_API ZIX_API ZIX_PURE_FUNC ZIX_NODISCARD /// A const function in the public API that is pure and only reads parameters -#define ZIX_CONST_API \ - ZIX_API \ - ZIX_CONST_FUNC \ - ZIX_NODISCARD +#define ZIX_CONST_API ZIX_API ZIX_CONST_FUNC ZIX_NODISCARD /// A malloc function in the public API that returns allocated memory -#define ZIX_MALLOC_API \ - ZIX_API \ - ZIX_MALLOC_FUNC \ - ZIX_NODISCARD +#define ZIX_MALLOC_API ZIX_API ZIX_MALLOC_FUNC ZIX_NODISCARD // Printf-like format functions #ifdef __GNUC__ diff --git a/include/zix/btree.h b/include/zix/btree.h index ddade81..de9f788 100644 --- a/include/zix/btree.h +++ b/include/zix/btree.h @@ -59,9 +59,7 @@ typedef void (*ZixBTreeDestroyFunc)(void* ZIX_UNSPECIFIED ptr, Searching can be done with a custom comparator that supports wildcards, see zix_btree_lower_bound() for details. */ -ZIX_API -ZIX_NODISCARD -ZixBTree* ZIX_ALLOCATED +ZIX_API ZIX_NODISCARD ZixBTree* ZIX_ALLOCATED zix_btree_new(ZixAllocator* ZIX_NULLABLE allocator, ZixBTreeCompareFunc ZIX_NONNULL cmp, const void* ZIX_UNSPECIFIED cmp_data); @@ -76,8 +74,7 @@ zix_btree_new(ZixAllocator* ZIX_NULLABLE allocator, @param destroy_data Opaque user data pointer to pass to `destroy`. */ -ZIX_API -void +ZIX_API void zix_btree_free(ZixBTree* ZIX_NULLABLE t, ZixBTreeDestroyFunc ZIX_NULLABLE destroy, const void* ZIX_NULLABLE destroy_data); @@ -92,15 +89,13 @@ zix_btree_free(ZixBTree* ZIX_NULLABLE t, @param destroy_data Opaque user data pointer to pass to `destroy`. */ -ZIX_API -void +ZIX_API void zix_btree_clear(ZixBTree* ZIX_NONNULL t, ZixBTreeDestroyFunc ZIX_NULLABLE destroy, const void* ZIX_NULLABLE destroy_data); /// Return the number of elements in `t` -ZIX_PURE_API -size_t +ZIX_PURE_API size_t zix_btree_size(const ZixBTree* ZIX_NONNULL t); /** @@ -135,42 +130,34 @@ static const ZixBTreeIter zix_btree_end_iter = { }; /// Return the data at the given position in the tree -ZIX_PURE_API -void* ZIX_UNSPECIFIED +ZIX_PURE_API void* ZIX_UNSPECIFIED zix_btree_get(ZixBTreeIter ti); /// Return an iterator to the first (smallest) element in `t` -ZIX_PURE_API -ZixBTreeIter +ZIX_PURE_API ZixBTreeIter zix_btree_begin(const ZixBTree* ZIX_NONNULL t); /// Return an iterator to the end of `t` (one past the last element) -ZIX_CONST_API -ZixBTreeIter +ZIX_CONST_API ZixBTreeIter zix_btree_end(const ZixBTree* ZIX_NULLABLE t); /// Return true iff `lhs` is equal to `rhs` -ZIX_CONST_API -bool +ZIX_CONST_API bool zix_btree_iter_equals(ZixBTreeIter lhs, ZixBTreeIter rhs); /// Return true iff `i` is an iterator at the end of a tree -ZIX_NODISCARD -static inline bool +ZIX_NODISCARD static inline bool zix_btree_iter_is_end(const ZixBTreeIter i) { return i.level == 0 && !i.nodes[0]; } /// Increment `i` to point to the next element in the tree -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_btree_iter_increment(ZixBTreeIter* ZIX_NONNULL i); /// Return an iterator one past `iter` -ZIX_API -ZIX_NODISCARD -ZixBTreeIter +ZIX_API ZIX_NODISCARD ZixBTreeIter zix_btree_iter_next(ZixBTreeIter iter); /** @@ -185,8 +172,7 @@ zix_btree_iter_next(ZixBTreeIter iter); @return #ZIX_STATUS_SUCCESS on success, #ZIX_STATUS_EXISTS, or #ZIX_STATUS_NO_MEM. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_btree_insert(ZixBTree* ZIX_NONNULL t, void* ZIX_UNSPECIFIED e); /** @@ -203,8 +189,7 @@ zix_btree_insert(ZixBTree* ZIX_NONNULL t, void* ZIX_UNSPECIFIED e); @return #ZIX_STATUS_SUCCESS on success, or #ZIX_STATUS_NOT_FOUND. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_btree_remove(ZixBTree* ZIX_NONNULL t, const void* ZIX_UNSPECIFIED e, void* ZIX_UNSPECIFIED* ZIX_NONNULL out, @@ -223,8 +208,7 @@ zix_btree_remove(ZixBTree* ZIX_NONNULL t, @return #ZIX_STATUS_SUCCESS on success, or #ZIX_STATUS_NOT_FOUND. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_btree_find(const ZixBTree* ZIX_NONNULL t, const void* ZIX_UNSPECIFIED e, ZixBTreeIter* ZIX_NONNULL ti); @@ -245,8 +229,7 @@ zix_btree_find(const ZixBTree* ZIX_NONNULL t, @return #ZIX_STATUS_SUCCESS. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_btree_lower_bound(const ZixBTree* ZIX_NONNULL t, ZixBTreeCompareFunc ZIX_NULLABLE compare_key, const void* ZIX_NULLABLE compare_key_data, diff --git a/include/zix/bump_allocator.h b/include/zix/bump_allocator.h index c69de92..ecb2383 100644 --- a/include/zix/bump_allocator.h +++ b/include/zix/bump_allocator.h @@ -52,8 +52,7 @@ typedef struct { } ZixBumpAllocator; /// Return a bump allocator that works within a provided buffer -ZIX_API -ZixBumpAllocator +ZIX_API ZixBumpAllocator zix_bump_allocator(size_t capacity, void* ZIX_NONNULL buffer); /** diff --git a/include/zix/digest.h b/include/zix/digest.h index deffaf0..3b23c3f 100644 --- a/include/zix/digest.h +++ b/include/zix/digest.h @@ -29,8 +29,7 @@ ZIX_BEGIN_DECLS This can be used for any size or alignment. */ -ZIX_PURE_API -uint32_t +ZIX_PURE_API uint32_t zix_digest32(uint32_t seed, const void* ZIX_NONNULL buf, size_t len); /** @@ -39,8 +38,7 @@ zix_digest32(uint32_t seed, const void* ZIX_NONNULL buf, size_t len); Both the buffer and size must be aligned to 32 bits. For data that fits these requirements, this is equivalent to, but faster than, zix_digest32(). */ -ZIX_PURE_API -uint32_t +ZIX_PURE_API uint32_t zix_digest32_aligned(uint32_t seed, const void* ZIX_NONNULL buf, size_t len); /** @@ -48,8 +46,7 @@ zix_digest32_aligned(uint32_t seed, const void* ZIX_NONNULL buf, size_t len); This can be used for any size or alignment. */ -ZIX_PURE_API -uint64_t +ZIX_PURE_API uint64_t zix_digest64(uint64_t seed, const void* ZIX_NONNULL buf, size_t len); /** @@ -58,8 +55,7 @@ zix_digest64(uint64_t seed, const void* ZIX_NONNULL buf, size_t len); Both the buffer and size must be aligned to 64 bits. For data that fits these requirements, this is equivalent to, but faster than, zix_digest64(). */ -ZIX_PURE_API -uint64_t +ZIX_PURE_API uint64_t zix_digest64_aligned(uint64_t seed, const void* ZIX_NONNULL buf, size_t len); /** @@ -70,8 +66,7 @@ zix_digest64_aligned(uint64_t seed, const void* ZIX_NONNULL buf, size_t len); Internally, this simply dispatches to zix_digest32() or zix_digest64() as appropriate. */ -ZIX_PURE_API -size_t +ZIX_PURE_API size_t zix_digest(size_t seed, const void* ZIX_NONNULL buf, size_t len); /** @@ -84,8 +79,7 @@ zix_digest(size_t seed, const void* ZIX_NONNULL buf, size_t len); Internally, this simply dispatches to zix_digest32_aligned() or zix_digest64_aligned() as appropriate. */ -ZIX_PURE_API -size_t +ZIX_PURE_API size_t zix_digest_aligned(size_t seed, const void* ZIX_NONNULL buf, size_t len); /** diff --git a/include/zix/filesystem.h b/include/zix/filesystem.h index 221e165..878cd93 100644 --- a/include/zix/filesystem.h +++ b/include/zix/filesystem.h @@ -51,8 +51,7 @@ typedef uint32_t ZixCopyOptions; @param options Options to control the kind of copy and error conditions. @return #ZIX_STATUS_SUCCESS if `dst` was successfully created, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_copy_file(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NONNULL src, const char* ZIX_NONNULL dst, @@ -64,8 +63,7 @@ zix_copy_file(ZixAllocator* ZIX_NULLABLE allocator, @return #ZIX_STATUS_SUCCESS if `dir_path` was successfully created, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_create_directory(const char* ZIX_NONNULL dir_path); /** @@ -77,8 +75,7 @@ zix_create_directory(const char* ZIX_NONNULL dir_path); @return #ZIX_STATUS_SUCCESS if `dir_path` was successfully created, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_create_directory_like(const char* ZIX_NONNULL dir_path, const char* ZIX_NONNULL existing_path); @@ -92,8 +89,7 @@ zix_create_directory_like(const char* ZIX_NONNULL dir_path, @return #ZIX_STATUS_SUCCESS if all directories in `dir_path` were successfully created (or already existed), or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_create_directories(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NONNULL dir_path); @@ -102,8 +98,7 @@ zix_create_directories(ZixAllocator* ZIX_NULLABLE allocator, @return #ZIX_STATUS_SUCCESS, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_create_hard_link(const char* ZIX_NONNULL target_path, const char* ZIX_NONNULL link_path); @@ -116,8 +111,7 @@ zix_create_hard_link(const char* ZIX_NONNULL target_path, @return #ZIX_STATUS_SUCCESS, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_create_symlink(const char* ZIX_NONNULL target_path, const char* ZIX_NONNULL link_path); @@ -129,8 +123,7 @@ zix_create_symlink(const char* ZIX_NONNULL target_path, @return #ZIX_STATUS_SUCCESS, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_create_directory_symlink(const char* ZIX_NONNULL target_path, const char* ZIX_NONNULL link_path); @@ -146,14 +139,12 @@ zix_create_directory_symlink(const char* ZIX_NONNULL target_path, @return The path of the created directory, or null. */ -ZIX_MALLOC_API -char* ZIX_NULLABLE +ZIX_MALLOC_API char* ZIX_NULLABLE zix_create_temporary_directory(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NONNULL path_pattern); /// Remove the file or empty directory at `path` -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_remove(const char* ZIX_NONNULL path); /** @@ -173,8 +164,7 @@ zix_remove(const char* ZIX_NONNULL path); parameter is always the directory path passed to this function, the `name` parameter is the name of the directory entry (not its full path). */ -ZIX_API -void +ZIX_API void zix_dir_for_each(const char* ZIX_NONNULL path, void* ZIX_NULLABLE data, void (*ZIX_NONNULL f)(const char* ZIX_NONNULL path, @@ -193,9 +183,7 @@ zix_dir_for_each(const char* ZIX_NONNULL path, @return True if the two files have byte-for-byte identical contents. */ -ZIX_API -ZIX_NODISCARD -bool +ZIX_API ZIX_NODISCARD bool zix_file_equals(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NONNULL a_path, const char* ZIX_NONNULL b_path); @@ -228,8 +216,7 @@ zix_file_equals(ZixAllocator* ZIX_NULLABLE allocator, @return A new canonical version of `path`, or null if it doesn't exist. */ -ZIX_MALLOC_API -char* ZIX_NULLABLE +ZIX_MALLOC_API char* ZIX_NULLABLE zix_canonical_path(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NULLABLE path); @@ -256,8 +243,7 @@ typedef enum { @param mode Lock mode. @return #ZIX_STATUS_SUCCESS if the file was locked, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_file_lock(FILE* ZIX_NONNULL file, ZixFileLockMode mode); /** @@ -267,8 +253,7 @@ zix_file_lock(FILE* ZIX_NONNULL file, ZixFileLockMode mode); @param mode Lock mode. @return #ZIX_STATUS_SUCCESS if the file was unlocked, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_file_unlock(FILE* ZIX_NONNULL file, ZixFileLockMode mode); /** @@ -309,8 +294,7 @@ typedef enum { /** Return the type of a file or directory, resolving symlinks. */ -ZIX_API -ZixFileType +ZIX_API ZixFileType zix_file_type(const char* ZIX_NONNULL path); /** @@ -319,8 +303,7 @@ zix_file_type(const char* ZIX_NONNULL path); On Windows, a directory symlink (actually a "reparse point") always appears as a directory. */ -ZIX_API -ZixFileType +ZIX_API ZixFileType zix_symlink_type(const char* ZIX_NONNULL path); /** @@ -332,8 +315,7 @@ zix_symlink_type(const char* ZIX_NONNULL path); @return A non-negative size in bytes, or -1 on error. */ -ZIX_API -ZixFileOffset +ZIX_API ZixFileOffset zix_file_size(const char* ZIX_NONNULL path); /** @@ -347,8 +329,7 @@ zix_file_size(const char* ZIX_NONNULL path); @param allocator Allocator used for the returned path. */ -ZIX_MALLOC_API -char* ZIX_ALLOCATED +ZIX_MALLOC_API char* ZIX_ALLOCATED zix_current_path(ZixAllocator* ZIX_NULLABLE allocator); /** @@ -358,8 +339,7 @@ zix_current_path(ZixAllocator* ZIX_NULLABLE allocator); @return A new path to a temporary directory, or null on error. */ -ZIX_MALLOC_API -char* ZIX_ALLOCATED +ZIX_MALLOC_API char* ZIX_ALLOCATED zix_temp_directory_path(ZixAllocator* ZIX_NULLABLE allocator); /** diff --git a/include/zix/hash.h b/include/zix/hash.h index 6cd2271..9447cd7 100644 --- a/include/zix/hash.h +++ b/include/zix/hash.h @@ -102,22 +102,18 @@ typedef bool (*ZixKeyEqualFunc)(const ZixHashKey* ZIX_NONNULL a, @param hash_func The key hashing function. @param equal_func A function to test keys for equality. */ -ZIX_API -ZIX_NODISCARD -ZixHash* ZIX_ALLOCATED +ZIX_API ZIX_NODISCARD ZixHash* ZIX_ALLOCATED zix_hash_new(ZixAllocator* ZIX_NULLABLE allocator, ZixKeyFunc ZIX_NONNULL key_func, ZixHashFunc ZIX_NONNULL hash_func, ZixKeyEqualFunc ZIX_NONNULL equal_func); /// Free `hash` -ZIX_API -void +ZIX_API void zix_hash_free(ZixHash* ZIX_NULLABLE hash); /// Return the number of elements in the hash -ZIX_PURE_API -size_t +ZIX_PURE_API size_t zix_hash_size(const ZixHash* ZIX_NONNULL hash); /** @@ -135,23 +131,19 @@ zix_hash_size(const ZixHash* ZIX_NONNULL hash); typedef size_t ZixHashIter; /// Return an iterator to the first record in a hash, or the end if it is empty -ZIX_PURE_API -ZixHashIter +ZIX_PURE_API ZixHashIter zix_hash_begin(const ZixHash* ZIX_NONNULL hash); /// Return an iterator one past the last possible record in a hash -ZIX_PURE_API -ZixHashIter +ZIX_PURE_API ZixHashIter zix_hash_end(const ZixHash* ZIX_NONNULL hash); /// Return the record pointed to by an iterator -ZIX_PURE_API -ZixHashRecord* ZIX_NULLABLE +ZIX_PURE_API ZixHashRecord* ZIX_NULLABLE zix_hash_get(const ZixHash* ZIX_NONNULL hash, ZixHashIter i); /// Return an iterator that has been advanced to the next record in a hash -ZIX_PURE_API -ZixHashIter +ZIX_PURE_API ZixHashIter zix_hash_next(const ZixHash* ZIX_NONNULL hash, ZixHashIter i); /** @@ -189,8 +181,7 @@ typedef struct { record with this key using zix_hash_insert_at() until the hash table is modified (which invalidates the position). */ -ZIX_API -ZixHashInsertPlan +ZIX_API ZixHashInsertPlan zix_hash_plan_insert(const ZixHash* ZIX_NONNULL hash, const ZixHashKey* ZIX_NONNULL key); @@ -214,8 +205,7 @@ zix_hash_plan_insert(const ZixHash* ZIX_NONNULL hash, be inserted, and the predicate must return true only if the key it is called with (the first argument) matches the key to be inserted. */ -ZIX_API -ZixHashInsertPlan +ZIX_API ZixHashInsertPlan zix_hash_plan_insert_prehashed(const ZixHash* ZIX_NONNULL hash, ZixHashCode code, ZixKeyMatchFunc ZIX_NONNULL predicate, @@ -228,8 +218,7 @@ zix_hash_plan_insert_prehashed(const ZixHash* ZIX_NONNULL hash, can be used to insert a new record, or to access the existing matching record. */ -ZIX_PURE_API -ZixHashRecord* ZIX_NULLABLE +ZIX_PURE_API ZixHashRecord* ZIX_NULLABLE zix_hash_record_at(const ZixHash* ZIX_NONNULL hash, ZixHashInsertPlan position); /** @@ -249,8 +238,7 @@ zix_hash_record_at(const ZixHash* ZIX_NONNULL hash, ZixHashInsertPlan position); @return ZIX_STATUS_SUCCESS, ZIX_STATUS_EXISTS if a record already exists at this position, or ZIX_STATUS_NO_MEM if growing the hash table failed. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_hash_insert_at(ZixHash* ZIX_NONNULL hash, ZixHashInsertPlan position, ZixHashRecord* ZIX_NONNULL record); @@ -269,8 +257,7 @@ zix_hash_insert_at(ZixHash* ZIX_NONNULL hash, @return ZIX_STATUS_SUCCESS, ZIX_STATUS_EXISTS, or ZIX_STATUS_NO_MEM. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_hash_insert(ZixHash* ZIX_NONNULL hash, ZixHashRecord* ZIX_NONNULL record); /** @@ -287,8 +274,7 @@ zix_hash_insert(ZixHash* ZIX_NONNULL hash, ZixHashRecord* ZIX_NONNULL record); @return ZIX_STATUS_SUCCES or ZIX_STATUS_BAD_ARG if `i` does not point at a removable record. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_hash_erase(ZixHash* ZIX_NONNULL hash, ZixHashIter i, ZixHashRecord* ZIX_NULLABLE* ZIX_NONNULL removed); @@ -301,8 +287,7 @@ zix_hash_erase(ZixHash* ZIX_NONNULL hash, @param removed Set to the removed record, or null. @return ZIX_STATUS_SUCCES or ZIX_STATUS_NOT_FOUND. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_hash_remove(ZixHash* ZIX_NONNULL hash, const ZixHashKey* ZIX_NONNULL key, ZixHashRecord* ZIX_NULLABLE* ZIX_NONNULL removed); @@ -323,8 +308,7 @@ zix_hash_remove(ZixHash* ZIX_NONNULL hash, @return An iterator to the matching record, or the end iterator if no such record exists. */ -ZIX_API -ZixHashIter +ZIX_API ZixHashIter zix_hash_find(const ZixHash* ZIX_NONNULL hash, const ZixHashKey* ZIX_NONNULL key); @@ -340,8 +324,7 @@ zix_hash_find(const ZixHash* ZIX_NONNULL hash, @return A pointer to the matching record, of null if no such record exists. */ -ZIX_API -ZixHashRecord* ZIX_NULLABLE +ZIX_API ZixHashRecord* ZIX_NULLABLE zix_hash_find_record(const ZixHash* ZIX_NONNULL hash, const ZixHashKey* ZIX_NONNULL key); diff --git a/include/zix/path.h b/include/zix/path.h index 22c8202..3fed43a 100644 --- a/include/zix/path.h +++ b/include/zix/path.h @@ -35,9 +35,7 @@ ZIX_BEGIN_DECLS */ /// Join path `a` and path `b` with a single directory separator between them -ZIX_API -ZIX_NODISCARD -char* ZIX_ALLOCATED +ZIX_API ZIX_NODISCARD char* ZIX_ALLOCATED zix_path_join(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NULLABLE a, const char* ZIX_NULLABLE b); @@ -55,9 +53,7 @@ zix_path_join(ZixAllocator* ZIX_NULLABLE allocator, converted to the preferred separator (backslash on Windows, slash everywhere else). */ -ZIX_API -ZIX_NODISCARD -char* ZIX_ALLOCATED +ZIX_API ZIX_NODISCARD char* ZIX_ALLOCATED zix_path_preferred(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NONNULL path); @@ -72,9 +68,7 @@ zix_path_preferred(ZixAllocator* ZIX_NULLABLE allocator, like case normalization or symbolic link dereferencing. For that, use zix_canonical_path(). */ -ZIX_API -ZIX_NODISCARD -char* ZIX_ALLOCATED +ZIX_API ZIX_NODISCARD char* ZIX_ALLOCATED zix_path_lexically_normal(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NONNULL path); @@ -85,9 +79,7 @@ zix_path_lexically_normal(ZixAllocator* ZIX_NULLABLE allocator, equivalent path relative to `base` is returned (which may contain up-references). */ -ZIX_API -ZIX_NODISCARD -char* ZIX_ALLOCATED +ZIX_API ZIX_NODISCARD char* ZIX_ALLOCATED zix_path_lexically_relative(ZixAllocator* ZIX_NULLABLE allocator, const char* ZIX_NONNULL path, const char* ZIX_NONNULL base); @@ -99,13 +91,11 @@ zix_path_lexically_relative(ZixAllocator* ZIX_NULLABLE allocator, */ /// Return the root name of `path` like "C:", or null -ZIX_PURE_WIN_API -ZixStringView +ZIX_PURE_WIN_API ZixStringView zix_path_root_name(const char* ZIX_NONNULL path); /// Return the root directory of `path` like "/" or "\", or null -ZIX_PURE_API -ZixStringView +ZIX_PURE_API ZixStringView zix_path_root_directory(const char* ZIX_NONNULL path); /** @@ -121,8 +111,7 @@ zix_path_root_directory(const char* ZIX_NONNULL path); @return The newly allocated root path of `path`, or null if it has no root or allocation failed. */ -ZIX_PURE_API -ZixStringView +ZIX_PURE_API ZixStringView zix_path_root_path(const char* ZIX_NONNULL path); /** @@ -131,8 +120,7 @@ zix_path_root_path(const char* ZIX_NONNULL path); If the path has no relative path (because it is empty or a root path), this returns null. */ -ZIX_PURE_API -ZixStringView +ZIX_PURE_API ZixStringView zix_path_relative_path(const char* ZIX_NONNULL path); /** @@ -151,8 +139,7 @@ zix_path_relative_path(const char* ZIX_NONNULL path); @return The newly allocated path to the parent of `path`, or null if it has no parent or allocation failed. */ -ZIX_PURE_API -ZixStringView +ZIX_PURE_API ZixStringView zix_path_parent_path(const char* ZIX_NONNULL path); /** @@ -161,8 +148,7 @@ zix_path_parent_path(const char* ZIX_NONNULL path); The filename is the name after the last directory separator. If the path has no filename, this returns null. */ -ZIX_PURE_API -ZixStringView +ZIX_PURE_API ZixStringView zix_path_filename(const char* ZIX_NONNULL path); /** @@ -171,8 +157,7 @@ zix_path_filename(const char* ZIX_NONNULL path); The "stem" is the filename without the extension, that is, everything up to the last "." if "." is not the first character. */ -ZIX_PURE_API -ZixStringView +ZIX_PURE_API ZixStringView zix_path_stem(const char* ZIX_NONNULL path); /** @@ -181,8 +166,7 @@ zix_path_stem(const char* ZIX_NONNULL path); The "extension" is everything past the last "." in the filename, if "." is not the first character. */ -ZIX_PURE_API -ZixStringView +ZIX_PURE_API ZixStringView zix_path_extension(const char* ZIX_NONNULL path); /** @@ -192,53 +176,43 @@ zix_path_extension(const char* ZIX_NONNULL path); */ /// Return true if `path` has a root path like "/" or "C:\" -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_path_has_root_path(const char* ZIX_NULLABLE path); /// Return true if `path` has a root name like "C:" -ZIX_PURE_WIN_API -bool +ZIX_PURE_WIN_API bool zix_path_has_root_name(const char* ZIX_NULLABLE path); /// Return true if `path` has a root directory like "/" or "\" -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_path_has_root_directory(const char* ZIX_NULLABLE path); /// Return true if `path` has a relative path "dir/file.txt" -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_path_has_relative_path(const char* ZIX_NULLABLE path); /// Return true if `path` has a parent path like "dir/" -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_path_has_parent_path(const char* ZIX_NULLABLE path); /// Return true if `path` has a filename like "file.txt" -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_path_has_filename(const char* ZIX_NULLABLE path); /// Return true if `path` has a stem like "file" -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_path_has_stem(const char* ZIX_NULLABLE path); /// Return true if `path` has an extension like ".txt" -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_path_has_extension(const char* ZIX_NULLABLE path); /// Return true if `path` is an absolute path -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_path_is_absolute(const char* ZIX_NULLABLE path); /// Return true if `path` is a relative path -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_path_is_relative(const char* ZIX_NULLABLE path); /** diff --git a/include/zix/ring.h b/include/zix/ring.h index db72f41..6829016 100644 --- a/include/zix/ring.h +++ b/include/zix/ring.h @@ -40,14 +40,11 @@ typedef struct ZixRingImpl ZixRing; At most `size` - 1 bytes may be stored in the ring at once. */ -ZIX_API -ZIX_NODISCARD -ZixRing* ZIX_ALLOCATED +ZIX_API ZIX_NODISCARD ZixRing* ZIX_ALLOCATED zix_ring_new(ZixAllocator* ZIX_NULLABLE allocator, uint32_t size); /// Destroy a ring -ZIX_API -void +ZIX_API void zix_ring_free(ZixRing* ZIX_NULLABLE ring); /** @@ -57,8 +54,7 @@ zix_ring_free(ZixRing* ZIX_NULLABLE ring); after zix_ring_new() to lock all ring memory to avoid page faults while using the ring. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_ring_mlock(ZixRing* ZIX_NONNULL ring); /** @@ -67,8 +63,7 @@ zix_ring_mlock(ZixRing* ZIX_NONNULL ring); This function is NOT thread-safe, it may only be called when there is no reader or writer. */ -ZIX_API -void +ZIX_API void zix_ring_reset(ZixRing* ZIX_NONNULL ring); /** @@ -77,8 +72,7 @@ zix_ring_reset(ZixRing* ZIX_NONNULL ring); This function returns a constant for any given ring, and may (but usually shouldn't) be called anywhere. */ -ZIX_PURE_API -uint32_t +ZIX_PURE_API uint32_t zix_ring_capacity(const ZixRing* ZIX_NONNULL ring); /** @@ -89,23 +83,19 @@ zix_ring_capacity(const ZixRing* ZIX_NONNULL ring); */ /// Return the number of bytes available for reading -ZIX_PURE_API -uint32_t +ZIX_PURE_API uint32_t zix_ring_read_space(const ZixRing* ZIX_NONNULL ring); /// Read from the ring without advancing the read head -ZIX_API -uint32_t +ZIX_API uint32_t zix_ring_peek(ZixRing* ZIX_NONNULL ring, void* ZIX_NONNULL dst, uint32_t size); /// Read from the ring and advance the read head -ZIX_API -uint32_t +ZIX_API uint32_t zix_ring_read(ZixRing* ZIX_NONNULL ring, void* ZIX_NONNULL dst, uint32_t size); /// Advance the read head, ignoring any data -ZIX_API -uint32_t +ZIX_API uint32_t zix_ring_skip(ZixRing* ZIX_NONNULL ring, uint32_t size); /** @@ -130,13 +120,11 @@ typedef struct { } ZixRingTransaction; /// Return the number of bytes available for writing -ZIX_PURE_API -uint32_t +ZIX_PURE_API uint32_t zix_ring_write_space(const ZixRing* ZIX_NONNULL ring); /// Write data to the ring -ZIX_API -uint32_t +ZIX_API uint32_t zix_ring_write(ZixRing* ZIX_NONNULL ring, const void* ZIX_NONNULL src, uint32_t size); @@ -155,9 +143,7 @@ zix_ring_write(ZixRing* ZIX_NONNULL ring, @param ring The ring to write data to. @return A new empty transaction. */ -ZIX_API -ZIX_NODISCARD -ZixRingTransaction +ZIX_API ZIX_NODISCARD ZixRingTransaction zix_ring_begin_write(ZixRing* ZIX_NONNULL ring); /** @@ -178,8 +164,7 @@ zix_ring_begin_write(ZixRing* ZIX_NONNULL ring); @param size Length of data to write in bytes. @return #ZIX_STATUS_NO_MEM or #ZIX_STATUS_SUCCESS. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_ring_amend_write(ZixRing* ZIX_NONNULL ring, ZixRingTransaction* ZIX_NONNULL tx, const void* ZIX_NONNULL src, @@ -198,8 +183,7 @@ zix_ring_amend_write(ZixRing* ZIX_NONNULL ring, @param tx The active transaction, from zix_ring_begin_write(). @return #ZIX_STATUS_SUCCESS. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_ring_commit_write(ZixRing* ZIX_NONNULL ring, const ZixRingTransaction* ZIX_NONNULL tx); diff --git a/include/zix/sem.h b/include/zix/sem.h index 42dd6c3..545aa8a 100644 --- a/include/zix/sem.h +++ b/include/zix/sem.h @@ -49,8 +49,7 @@ typedef struct ZixSemImpl ZixSem; @return #ZIX_STATUS_SUCCESS, or an unlikely error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_init(ZixSem* ZIX_NONNULL sem, unsigned initial); /** @@ -58,8 +57,7 @@ zix_sem_init(ZixSem* ZIX_NONNULL sem, unsigned initial); @return #ZIX_STATUS_SUCCESS, or an error. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_destroy(ZixSem* ZIX_NONNULL sem); /** @@ -71,8 +69,7 @@ zix_sem_destroy(ZixSem* ZIX_NONNULL sem); if the maximum possible value would have been exceeded, or #ZIX_STATUS_BAD_ARG if `sem` is invalid. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_post(ZixSem* ZIX_NONNULL sem); /** @@ -83,8 +80,7 @@ zix_sem_post(ZixSem* ZIX_NONNULL sem); @return #ZIX_STATUS_SUCCESS if `sem` was decremented, or #ZIX_STATUS_BAD_ARG if `sem` is invalid. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_wait(ZixSem* ZIX_NONNULL sem); /** @@ -94,8 +90,7 @@ zix_sem_wait(ZixSem* ZIX_NONNULL sem); #ZIX_STATUS_UNAVAILABLE if it was already zero, or #ZIX_STATUS_BAD_ARG if `sem` is invalid. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_try_wait(ZixSem* ZIX_NONNULL sem); /** @@ -108,8 +103,7 @@ zix_sem_try_wait(ZixSem* ZIX_NONNULL sem); the system does not support timed waits, or #ZIX_STATUS_BAD_ARG if `sem` is invalid. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_sem_timed_wait(ZixSem* ZIX_NONNULL sem, uint32_t seconds, uint32_t nanoseconds); diff --git a/include/zix/status.h b/include/zix/status.h index 47aede8..fce27bc 100644 --- a/include/zix/status.h +++ b/include/zix/status.h @@ -38,8 +38,7 @@ typedef enum { The returned string is always one sentence, with an uppercase first character, and no trailing period. */ -ZIX_CONST_API -const char* +ZIX_CONST_API const char* zix_strerror(ZixStatus status); /** diff --git a/include/zix/string_view.h b/include/zix/string_view.h index cfd478d..d6f39c5 100644 --- a/include/zix/string_view.h +++ b/include/zix/string_view.h @@ -40,9 +40,7 @@ typedef struct { // clang-format on /// Return a view of an empty string -ZIX_ALWAYS_INLINE_FUNC -ZIX_CONST_FUNC -static inline ZixStringView +ZIX_ALWAYS_INLINE_FUNC ZIX_CONST_FUNC static inline ZixStringView zix_empty_string(void) { const ZixStringView view = {"", 0U}; @@ -62,9 +60,7 @@ zix_empty_string(void) @param len Length of the substring in bytes, not including the trailing null terminator if present. */ -ZIX_ALWAYS_INLINE_FUNC -ZIX_CONST_FUNC -static inline ZixStringView +ZIX_ALWAYS_INLINE_FUNC ZIX_CONST_FUNC static inline ZixStringView zix_substring(const char* const ZIX_NONNULL str, const size_t len) { const ZixStringView view = {str, len}; @@ -78,9 +74,7 @@ zix_substring(const char* const ZIX_NONNULL str, const size_t len) @param str Pointer to the start of a null-terminated C string, or null. */ -ZIX_ALWAYS_INLINE_FUNC -ZIX_PURE_FUNC -static inline ZixStringView +ZIX_ALWAYS_INLINE_FUNC ZIX_PURE_FUNC static inline ZixStringView // NOLINTNEXTLINE(clang-diagnostic-unused-function) zix_string(const char* const ZIX_NULLABLE str) { @@ -90,8 +84,7 @@ zix_string(const char* const ZIX_NULLABLE str) /** Copy a string view into a newly allocated null-terminated string. */ -ZIX_MALLOC_API -char* ZIX_ALLOCATED +ZIX_MALLOC_API char* ZIX_ALLOCATED zix_string_view_copy(ZixAllocator* ZIX_NULLABLE allocator, ZixStringView view); /** @@ -101,8 +94,7 @@ zix_string_view_copy(ZixAllocator* ZIX_NULLABLE allocator, ZixStringView view); has fast paths for when the operands have different lengths, or point to the same string data. */ -ZIX_PURE_API -bool +ZIX_PURE_API bool zix_string_view_equals(ZixStringView lhs, ZixStringView rhs); /** diff --git a/include/zix/thread.h b/include/zix/thread.h index 2493ed3..dc9804c 100644 --- a/include/zix/thread.h +++ b/include/zix/thread.h @@ -62,8 +62,7 @@ typedef ZixThreadResult(ZIX_THREAD_FUNC* ZixThreadFunc)(void*); @return #ZIX_STATUS_SUCCESS on success, or #ZIX_STATUS_ERROR. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_thread_create(ZixThread* thread, size_t stack_size, ZixThreadFunc function, @@ -74,8 +73,7 @@ zix_thread_create(ZixThread* thread, @return #ZIX_STATUS_SUCCESS on success, or #ZIX_STATUS_ERROR. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_thread_join(ZixThread thread); /** diff --git a/include/zix/tree.h b/include/zix/tree.h index b51fa72..60bfe6c 100644 --- a/include/zix/tree.h +++ b/include/zix/tree.h @@ -37,9 +37,7 @@ typedef void (*ZixTreeDestroyFunc)(void* ZIX_UNSPECIFIED ptr, const void* ZIX_UNSPECIFIED user_data); /// Create a new (empty) tree -ZIX_API -ZIX_NODISCARD -ZixTree* ZIX_ALLOCATED +ZIX_API ZIX_NODISCARD ZixTree* ZIX_ALLOCATED zix_tree_new(ZixAllocator* ZIX_NULLABLE allocator, bool allow_duplicates, ZixTreeCompareFunc ZIX_NONNULL cmp, @@ -48,13 +46,11 @@ zix_tree_new(ZixAllocator* ZIX_NULLABLE allocator, const void* ZIX_NULLABLE destroy_user_data); /// Free `t` -ZIX_API -void +ZIX_API void zix_tree_free(ZixTree* ZIX_NULLABLE t); /// Return the number of elements in `t` -ZIX_PURE_API -size_t +ZIX_PURE_API size_t zix_tree_size(const ZixTree* ZIX_NONNULL t); /** @@ -67,48 +63,39 @@ zix_tree_size(const ZixTree* ZIX_NONNULL t); typedef struct ZixTreeNodeImpl ZixTreeIter; /// Return the data associated with the given tree item -ZIX_PURE_API -void* ZIX_UNSPECIFIED +ZIX_PURE_API void* ZIX_UNSPECIFIED zix_tree_get(const ZixTreeIter* ZIX_NULLABLE ti); /// Return an iterator to the first (smallest) element in `t` -ZIX_PURE_API -ZixTreeIter* ZIX_NULLABLE +ZIX_PURE_API ZixTreeIter* ZIX_NULLABLE zix_tree_begin(ZixTree* ZIX_NONNULL t); /// Return an iterator the the element one past the last element in `t` -ZIX_CONST_API -ZixTreeIter* ZIX_NULLABLE +ZIX_CONST_API ZixTreeIter* ZIX_NULLABLE zix_tree_end(ZixTree* ZIX_NONNULL t); /// Return true iff `i` is an iterator to the end of its tree -ZIX_CONST_API -bool +ZIX_CONST_API bool zix_tree_iter_is_end(const ZixTreeIter* ZIX_NULLABLE i); /// Return an iterator to the last (largest) element in `t` -ZIX_PURE_API -ZixTreeIter* ZIX_NULLABLE +ZIX_PURE_API ZixTreeIter* ZIX_NULLABLE zix_tree_rbegin(ZixTree* ZIX_NONNULL t); /// Return an iterator the the element one before the first element in `t` -ZIX_CONST_API -ZixTreeIter* ZIX_NULLABLE +ZIX_CONST_API ZixTreeIter* ZIX_NULLABLE zix_tree_rend(ZixTree* ZIX_NONNULL t); /// Return true iff `i` is an iterator to the reverse end of its tree -ZIX_CONST_API -bool +ZIX_CONST_API bool zix_tree_iter_is_rend(const ZixTreeIter* ZIX_NULLABLE i); /// Return an iterator that points to the element one past `i` -ZIX_PURE_API -ZixTreeIter* ZIX_NULLABLE +ZIX_PURE_API ZixTreeIter* ZIX_NULLABLE zix_tree_iter_next(ZixTreeIter* ZIX_NULLABLE i); /// Return an iterator that points to the element one before `i` -ZIX_PURE_API -ZixTreeIter* ZIX_NULLABLE +ZIX_PURE_API ZixTreeIter* ZIX_NULLABLE zix_tree_iter_prev(ZixTreeIter* ZIX_NULLABLE i); /** @@ -118,15 +105,13 @@ zix_tree_iter_prev(ZixTreeIter* ZIX_NULLABLE i); */ /// Insert the element `e` into `t` and point `ti` at the new element -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_tree_insert(ZixTree* ZIX_NONNULL t, void* ZIX_UNSPECIFIED e, ZixTreeIter* ZIX_NULLABLE* ZIX_NULLABLE ti); /// Remove the item pointed at by `ti` from `t` -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_tree_remove(ZixTree* ZIX_NONNULL t, ZixTreeIter* ZIX_NONNULL ti); /** @@ -140,8 +125,7 @@ zix_tree_remove(ZixTree* ZIX_NONNULL t, ZixTreeIter* ZIX_NONNULL ti); If no such item exists, `ti` is set to NULL. */ -ZIX_API -ZixStatus +ZIX_API ZixStatus zix_tree_find(const ZixTree* ZIX_NONNULL t, const void* ZIX_UNSPECIFIED e, ZixTreeIter* ZIX_NULLABLE* ZIX_NONNULL ti); diff --git a/src/allocator.c b/src/allocator.c index 6c18804..09e3271 100644 --- a/src/allocator.c +++ b/src/allocator.c @@ -15,16 +15,14 @@ #include <stdlib.h> -ZIX_MALLOC_FUNC -static void* +ZIX_MALLOC_FUNC static void* zix_default_malloc(ZixAllocator* const allocator, const size_t size) { (void)allocator; return malloc(size); } -ZIX_MALLOC_FUNC -static void* +ZIX_MALLOC_FUNC static void* zix_default_calloc(ZixAllocator* const allocator, const size_t nmemb, const size_t size) @@ -49,8 +47,7 @@ zix_default_free(ZixAllocator* const allocator, void* const ptr) free(ptr); } -ZIX_MALLOC_FUNC -static void* +ZIX_MALLOC_FUNC static void* zix_default_aligned_alloc(ZixAllocator* const allocator, const size_t alignment, const size_t size) diff --git a/src/btree.c b/src/btree.c index db7f922..66f8a38 100644 --- a/src/btree.c +++ b/src/btree.c @@ -78,8 +78,7 @@ zix_btree_node_new(ZixAllocator* const allocator, const bool leaf) return node; } -ZIX_PURE_FUNC -static ZixBTreeNode* +ZIX_PURE_FUNC static ZixBTreeNode* zix_btree_child(const ZixBTreeNode* const node, const unsigned i) { assert(!node->is_leaf); @@ -394,16 +393,14 @@ zix_btree_leaf_find(const ZixBTree* const t, t->cmp, t->cmp_data, n->data.leaf.vals, n->n_vals, e, equal); } -ZIX_PURE_FUNC -static inline bool +ZIX_PURE_FUNC static inline bool zix_btree_can_remove_from(const ZixBTreeNode* const n) { assert(n->n_vals >= zix_btree_min_vals(n)); return n->n_vals > zix_btree_min_vals(n); } -ZIX_PURE_FUNC -static inline bool +ZIX_PURE_FUNC static inline bool zix_btree_is_full(const ZixBTreeNode* const n) { assert(n->n_vals <= zix_btree_max_vals(n)); diff --git a/src/bump_allocator.c b/src/bump_allocator.c index 924a1c8..8096907 100644 --- a/src/bump_allocator.c +++ b/src/bump_allocator.c @@ -13,8 +13,7 @@ static const size_t min_alignment = sizeof(uintmax_t); -ZIX_PURE_FUNC -static size_t +ZIX_PURE_FUNC static size_t round_up_multiple(const size_t number, const size_t factor) { assert(factor); // Factor must be non-zero @@ -23,8 +22,7 @@ round_up_multiple(const size_t number, const size_t factor) return (number + factor - 1U) & ~(factor - 1U); } -ZIX_MALLOC_FUNC -static void* +ZIX_MALLOC_FUNC static void* zix_bump_malloc(ZixAllocator* const allocator, const size_t size) { ZixBumpAllocator* const state = (ZixBumpAllocator*)allocator; @@ -46,8 +44,7 @@ zix_bump_malloc(ZixAllocator* const allocator, const size_t size) return (void*)((char*)state->buffer + state->last); } -ZIX_MALLOC_FUNC -static void* +ZIX_MALLOC_FUNC static void* zix_bump_calloc(ZixAllocator* const allocator, const size_t nmemb, const size_t size) @@ -91,8 +88,7 @@ zix_bump_free(ZixAllocator* const allocator, void* const ptr) } } -ZIX_MALLOC_FUNC -static void* +ZIX_MALLOC_FUNC static void* zix_bump_aligned_alloc(ZixAllocator* const allocator, const size_t alignment, const size_t size) @@ -138,8 +134,7 @@ zix_bump_aligned_free(ZixAllocator* const allocator, void* const ptr) zix_bump_free(allocator, ptr); } -ZIX_CONST_FUNC -ZixBumpAllocator +ZIX_CONST_FUNC ZixBumpAllocator zix_bump_allocator(const size_t capacity, void* buffer) { const size_t aligned_top = (uintptr_t)buffer % min_alignment; diff --git a/src/errno_status.h b/src/errno_status.h index 2f81e4e..9c147db 100644 --- a/src/errno_status.h +++ b/src/errno_status.h @@ -8,13 +8,11 @@ #include "zix/status.h" /// Return an errno value converted to a status code -ZIX_CONST_FUNC -ZixStatus +ZIX_CONST_FUNC ZixStatus zix_errno_status(int e); /// Return success if `r` is non-zero, or `errno` as a status code otherwise -ZIX_PURE_FUNC -ZixStatus +ZIX_PURE_FUNC ZixStatus zix_errno_status_if(int r); #endif // ZIX_ERRNO_STATUS_H @@ -92,8 +92,7 @@ typedef struct { ZixIndexRange dir; } ZixRootSlices; -ZIX_PURE_FUNC -static ZixRootSlices +ZIX_PURE_FUNC static ZixRootSlices zix_path_root_slices(const char* const path) { // A root name not trailed by a separator has no root directory @@ -128,8 +127,7 @@ zix_string_ranges_equal(const char* const lhs, !strncmp(lhs + lhs_range.begin, rhs + rhs_range.begin, lhs_len)); } -ZIX_PURE_FUNC -static ZixIndexRange +ZIX_PURE_FUNC static ZixIndexRange zix_path_root_path_range(const char* const path) { const ZixRootSlices root = zix_path_root_slices(path); @@ -140,8 +138,7 @@ zix_path_root_path_range(const char* const path) : zix_make_range(root.name.begin, root.name.end + dir_len); } -ZIX_PURE_FUNC -static ZixIndexRange +ZIX_PURE_FUNC static ZixIndexRange zix_path_parent_path_range(const ZixStringView path) { if (!path.length) { @@ -178,8 +175,7 @@ zix_path_parent_path_range(const ZixStringView path) return zix_make_range(root.begin, root.begin + l + 1U - p); } -ZIX_PURE_FUNC -static ZixIndexRange +ZIX_PURE_FUNC static ZixIndexRange zix_path_filename_range(const ZixStringView path) { if (!path.length) { @@ -201,8 +197,7 @@ zix_path_filename_range(const ZixStringView path) return zix_make_range(f, path.length); } -ZIX_PURE_FUNC -static ZixIndexRange +ZIX_PURE_FUNC static ZixIndexRange zix_path_stem_range(const ZixStringView path) { const ZixIndexRange name = zix_path_filename_range(path); @@ -221,8 +216,7 @@ zix_path_stem_range(const ZixStringView path) return zix_is_empty_range(stem) ? name : stem; } -ZIX_PURE_FUNC -static ZixIndexRange +ZIX_PURE_FUNC static ZixIndexRange zix_path_extension_range(const ZixStringView path) { const ZixIndexRange stem = zix_path_stem_range(path); diff --git a/src/path_iter.h b/src/path_iter.h index b3b23e8..f57c6ef 100644 --- a/src/path_iter.h +++ b/src/path_iter.h @@ -20,12 +20,10 @@ typedef struct { ZixPathIterState state; } ZixPathIter; -ZIX_PURE_FUNC -ZixPathIter +ZIX_PURE_FUNC ZixPathIter zix_path_begin(const char* ZIX_NULLABLE path); -ZIX_PURE_FUNC -ZixPathIter +ZIX_PURE_FUNC ZixPathIter zix_path_next(const char* ZIX_NONNULL path, ZixPathIter iter); #endif // ZIX_PATH_ITER_H diff --git a/src/posix/filesystem_posix.c b/src/posix/filesystem_posix.c index be13995..cd53689 100644 --- a/src/posix/filesystem_posix.c +++ b/src/posix/filesystem_posix.c @@ -378,8 +378,7 @@ zix_file_unlock(FILE* const file, const ZixFileLockMode mode) #endif } -ZIX_CONST_FUNC -static ZixFileType +ZIX_CONST_FUNC static ZixFileType stat_file_type(const struct stat* sb) { typedef struct { diff --git a/test/failing_allocator.c b/test/failing_allocator.c index 53a5216..6cffc7b 100644 --- a/test/failing_allocator.c +++ b/test/failing_allocator.c @@ -23,8 +23,7 @@ attempt(ZixFailingAllocator* const allocator) return true; } -ZIX_MALLOC_FUNC -static void* +ZIX_MALLOC_FUNC static void* zix_failing_malloc(ZixAllocator* const allocator, const size_t size) { ZixFailingAllocator* const state = (ZixFailingAllocator*)allocator; @@ -33,8 +32,7 @@ zix_failing_malloc(ZixAllocator* const allocator, const size_t size) return attempt(state) ? base->malloc(base, size) : NULL; } -ZIX_MALLOC_FUNC -static void* +ZIX_MALLOC_FUNC static void* zix_failing_calloc(ZixAllocator* const allocator, const size_t nmemb, const size_t size) @@ -66,8 +64,7 @@ zix_failing_free(ZixAllocator* const allocator, void* const ptr) base->free(base, ptr); } -ZIX_MALLOC_FUNC -static void* +ZIX_MALLOC_FUNC static void* zix_failing_aligned_alloc(ZixAllocator* const allocator, const size_t alignment, const size_t size) @@ -88,8 +85,7 @@ zix_failing_aligned_free(ZixAllocator* const allocator, void* const ptr) base->aligned_free(base, ptr); } -ZIX_CONST_FUNC -ZixFailingAllocator +ZIX_CONST_FUNC ZixFailingAllocator zix_failing_allocator(void) { ZixFailingAllocator failing_allocator = { diff --git a/test/test_btree.c b/test/test_btree.c index a3183c6..6269c4b 100644 --- a/test/test_btree.c +++ b/test/test_btree.c @@ -20,8 +20,7 @@ #include <stdio.h> #include <stdlib.h> -ZIX_PURE_FUNC -static int +ZIX_PURE_FUNC static int int_cmp(const void* a, const void* b, const void* ZIX_UNUSED(user_data)) { const uintptr_t ia = (uintptr_t)a; diff --git a/test/test_digest.c b/test/test_digest.c index 7228f86..7e7e77a 100644 --- a/test/test_digest.c +++ b/test/test_digest.c @@ -116,8 +116,7 @@ test_digest_aligned(void) } } -ZIX_PURE_FUNC -int +ZIX_PURE_FUNC int main(void) { test_digest32(); diff --git a/test/test_hash.c b/test/test_hash.c index 8ee6b82..07ec529 100644 --- a/test/test_hash.c +++ b/test/test_hash.c @@ -47,24 +47,21 @@ test_fail(TestState* const state, const char* fmt, ...) return EXIT_FAILURE; } -ZIX_PURE_FUNC -static const char* +ZIX_PURE_FUNC static const char* identity(const char* record) { return record; } /// Decent hash function using zix_digest (murmur2) -ZIX_PURE_FUNC -static size_t +ZIX_PURE_FUNC static size_t decent_string_hash(const char* const str) { return zix_digest(0U, str, strlen(str)); } /// Terrible hash function from K&R first edition -ZIX_PURE_FUNC -static size_t +ZIX_PURE_FUNC static size_t terrible_string_hash(const char* str) { size_t hash = 0U; @@ -77,8 +74,7 @@ terrible_string_hash(const char* str) return hash; } -ZIX_PURE_FUNC -static size_t +ZIX_PURE_FUNC static size_t string_hash_aligned(const char* const str) { size_t length = strlen(str); @@ -87,22 +83,19 @@ string_hash_aligned(const char* const str) return zix_digest_aligned(0U, str, length); } -ZIX_PURE_FUNC -static size_t +ZIX_PURE_FUNC static size_t string_hash32(const char* const str) { return (size_t)zix_digest32(0U, str, strlen(str)); } -ZIX_PURE_FUNC -static size_t +ZIX_PURE_FUNC static size_t string_hash64(const char* const str) { return (size_t)zix_digest64(0U, str, strlen(str)); } -ZIX_PURE_FUNC -static size_t +ZIX_PURE_FUNC static size_t string_hash32_aligned(const char* const str) { size_t length = strlen(str); @@ -113,8 +106,7 @@ string_hash32_aligned(const char* const str) #if UINTPTR_MAX >= UINT64_MAX -ZIX_PURE_FUNC -static size_t +ZIX_PURE_FUNC static size_t string_hash64_aligned(const char* const str) { size_t length = strlen(str); @@ -298,8 +290,7 @@ stress(ZixAllocator* const allocator, const size_t n_elems) } /// Identity hash function for numeric strings for explicitly hitting cases -ZIX_PURE_FUNC -static size_t +ZIX_PURE_FUNC static size_t identity_index_hash(const char* const str) { return strtoul(str, NULL, 10); diff --git a/test/test_ring.c b/test/test_ring.c index 06d50ee..156d867 100644 --- a/test/test_ring.c +++ b/test/test_ring.c @@ -34,8 +34,7 @@ gen_msg(int* const msg, int start) return start; } -ZIX_PURE_FUNC -static int +ZIX_PURE_FUNC static int cmp_msg(const int* const msg1, const int* const msg2) { for (unsigned i = 0U; i < MSG_SIZE; ++i) { |