diff options
author | David Robillard <d@drobilla.net> | 2020-11-11 12:22:28 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-11 12:26:56 +0100 |
commit | 3c18febd87234f54c149bb4a6353e3b0e0103db7 (patch) | |
tree | 26c32150fada522778e8df63b747fbe10e7aa3dc /zix | |
parent | 387f52cd29b6078d441da5fd07a951a481c10b6d (diff) | |
download | zix-3c18febd87234f54c149bb4a6353e3b0e0103db7.tar.gz zix-3c18febd87234f54c149bb4a6353e3b0e0103db7.tar.bz2 zix-3c18febd87234f54c149bb4a6353e3b0e0103db7.zip |
Add const, pure, and malloc function attributes
Diffstat (limited to 'zix')
-rw-r--r-- | zix/bitset.h | 6 | ||||
-rw-r--r-- | zix/btree.h | 10 | ||||
-rw-r--r-- | zix/chunk.h | 4 | ||||
-rw-r--r-- | zix/common.h | 15 | ||||
-rw-r--r-- | zix/digest.h | 8 | ||||
-rw-r--r-- | zix/hash.h | 2 | ||||
-rw-r--r-- | zix/ring.h | 13 | ||||
-rw-r--r-- | zix/sorted_array.c | 2 | ||||
-rw-r--r-- | zix/sorted_array.h | 16 | ||||
-rw-r--r-- | zix/tree.h | 20 | ||||
-rw-r--r-- | zix/trie_util.h | 2 |
11 files changed, 63 insertions, 35 deletions
diff --git a/zix/bitset.h b/zix/bitset.h index 0e31063..5214669 100644 --- a/zix/bitset.h +++ b/zix/bitset.h @@ -74,20 +74,20 @@ zix_bitset_reset(ZixBitset* b, ZixBitsetTally* t, size_t i); /** Return the `i`th bit in `t`. */ -ZIX_API bool +ZIX_PURE_API bool zix_bitset_get(const ZixBitset* b, size_t i); /** Return the number of set bits in `b` up to bit `i` (non-inclusive). */ -ZIX_API size_t +ZIX_PURE_API size_t zix_bitset_count_up_to(const ZixBitset* b, const ZixBitsetTally* t, size_t i); /** Return the number of set bits in `b` up to bit `i` (non-inclusive) if bit `i` is set, or (size_t)-1 otherwise. */ -ZIX_API size_t +ZIX_PURE_API size_t zix_bitset_count_up_to_if(const ZixBitset* b, const ZixBitsetTally* t, size_t i); /** diff --git a/zix/btree.h b/zix/btree.h index 4c972f6..c1610a8 100644 --- a/zix/btree.h +++ b/zix/btree.h @@ -68,7 +68,7 @@ zix_btree_free(ZixBTree* t); /** Return the number of elements in `t`. */ -ZIX_API size_t +ZIX_PURE_API size_t zix_btree_size(const ZixBTree* t); /** @@ -113,7 +113,7 @@ zix_btree_lower_bound(const ZixBTree* t, const void* e, ZixBTreeIter** ti); /** Return the data associated with the given tree item. */ -ZIX_API void* +ZIX_PURE_API void* zix_btree_get(const ZixBTreeIter* ti); /** @@ -121,7 +121,7 @@ zix_btree_get(const ZixBTreeIter* ti); The returned iterator must be freed with zix_btree_iter_free(). */ -ZIX_API ZixBTreeIter* +ZIX_PURE_API ZixBTreeIter* zix_btree_begin(const ZixBTree* t); /** @@ -141,13 +141,13 @@ zix_btree_iter_copy(const ZixBTreeIter* i); /** Return true iff `lhs` is equal to `rhs`. */ -ZIX_API bool +ZIX_PURE_API bool zix_btree_iter_equals(const ZixBTreeIter* lhs, const ZixBTreeIter* rhs); /** Return true iff `i` is an iterator to the end of its tree. */ -ZIX_API bool +ZIX_PURE_API bool zix_btree_iter_is_end(const ZixBTreeIter* i); /** diff --git a/zix/chunk.h b/zix/chunk.h index 162df41..193e537 100644 --- a/zix/chunk.h +++ b/zix/chunk.h @@ -35,10 +35,10 @@ typedef struct { size_t len; /**< Length of memory chunk */ } ZixChunk; -ZIX_API uint32_t +ZIX_PURE_API uint32_t zix_chunk_hash(const ZixChunk* chunk); -ZIX_API bool +ZIX_PURE_API bool zix_chunk_equal(const ZixChunk* a, const ZixChunk* b); #ifdef __cplusplus diff --git a/zix/common.h b/zix/common.h index 3271858..f7ec4c3 100644 --- a/zix/common.h +++ b/zix/common.h @@ -46,6 +46,21 @@ # define ZIX_API # define ZIX_PRIVATE static #endif + +#ifdef __GNUC__ +# define ZIX_PURE_FUNC __attribute__((pure)) +# define ZIX_CONST_FUNC __attribute__((const)) +# define ZIX_MALLOC_FUNC __attribute__((malloc)) +#else +# define ZIX_PURE_FUNC +# define ZIX_CONST_FUNC +# define ZIX_MALLOC_FUNC +#endif + +#define ZIX_PURE_API ZIX_API ZIX_PURE_FUNC +#define ZIX_CONST_API ZIX_API ZIX_CONST_FUNC +#define ZIX_MALLOC_API ZIX_API ZIX_MALLOC_FUNC + /** @endcond */ #ifdef __cplusplus diff --git a/zix/digest.h b/zix/digest.h index 16ba9b9..c9f3ec0 100644 --- a/zix/digest.h +++ b/zix/digest.h @@ -29,7 +29,7 @@ extern "C" { /** Return an initial empty digest value. */ -ZIX_API uint32_t +ZIX_CONST_API uint32_t zix_digest_start(void); /** @@ -37,7 +37,7 @@ zix_digest_start(void); This can be used for any size or alignment. */ -ZIX_API uint32_t +ZIX_PURE_API uint32_t zix_digest_add(uint32_t hash, const void* buf, size_t len); /** @@ -45,7 +45,7 @@ zix_digest_add(uint32_t hash, const void* buf, size_t len); Both `buf` and `len` must be evenly divisible by 8 (64 bits). */ -ZIX_API uint32_t +ZIX_PURE_API uint32_t zix_digest_add_64(uint32_t hash, const void* buf, size_t len); /** @@ -53,7 +53,7 @@ zix_digest_add_64(uint32_t hash, const void* buf, size_t len); This hashes the value of the pointer itself, and does not dereference `ptr`. */ -ZIX_API uint32_t +ZIX_CONST_API uint32_t zix_digest_add_ptr(uint32_t hash, const void* ptr); #ifdef __cplusplus @@ -73,7 +73,7 @@ zix_hash_free(ZixHash* hash); /** Return the number of elements in `hash`. */ -ZIX_API size_t +ZIX_PURE_API size_t zix_hash_size(const ZixHash* hash); /** @@ -17,6 +17,8 @@ #ifndef ZIX_RING_H #define ZIX_RING_H +#include "zix/common.h" + #include <stdint.h> #ifdef __cplusplus @@ -44,12 +46,14 @@ typedef struct ZixRingImpl ZixRing; At most `size` - 1 bytes may be stored in the ring at once. */ +ZIX_MALLOC_API ZixRing* zix_ring_new(uint32_t size); /** Destroy a ring. */ +ZIX_API void zix_ring_free(ZixRing* ring); @@ -62,6 +66,7 @@ zix_ring_free(ZixRing* ring); ring to be truly real-time safe). */ +ZIX_API void zix_ring_mlock(ZixRing* ring); @@ -71,48 +76,56 @@ zix_ring_mlock(ZixRing* ring); This function is NOT thread-safe, it may only be called when there are no readers or writers. */ +ZIX_API void zix_ring_reset(ZixRing* ring); /** Return the number of bytes of space available for reading. */ +ZIX_CONST_API uint32_t zix_ring_read_space(const ZixRing* ring); /** Return the number of bytes of space available for writing. */ +ZIX_CONST_API uint32_t zix_ring_write_space(const ZixRing* ring); /** Return the capacity (i.e. total write space when empty). */ +ZIX_CONST_API uint32_t zix_ring_capacity(const ZixRing* ring); /** Read from the ring without advancing the read head. */ +ZIX_API uint32_t zix_ring_peek(ZixRing* ring, void* dst, uint32_t size); /** Read from the ring and advance the read head. */ +ZIX_API uint32_t zix_ring_read(ZixRing* ring, void* dst, uint32_t size); /** Skip data in the ring (advance read head without reading). */ +ZIX_API uint32_t zix_ring_skip(ZixRing* ring, uint32_t size); /** Write data to the ring. */ +ZIX_API uint32_t zix_ring_write(ZixRing* ring, const void* src, uint32_t size); diff --git a/zix/sorted_array.c b/zix/sorted_array.c index 038bc23..ffab77c 100644 --- a/zix/sorted_array.c +++ b/zix/sorted_array.c @@ -72,7 +72,7 @@ zix_sorted_array_free(ZixSortedArray* a) } size_t -zix_sorted_array_size(ZixSortedArray* a) +zix_sorted_array_size(const ZixSortedArray* a) { return a->num_elems; } diff --git a/zix/sorted_array.h b/zix/sorted_array.h index 3e94ca5..5acd50e 100644 --- a/zix/sorted_array.h +++ b/zix/sorted_array.h @@ -61,9 +61,9 @@ zix_sorted_array_free(ZixSortedArray* a); /** Return the number of elements in `a`. */ -ZIX_API +ZIX_PURE_API size_t -zix_sorted_array_size(ZixSortedArray* a); +zix_sorted_array_size(const ZixSortedArray* a); /** Insert the element `e` into `a` and point `ai` at the new element. @@ -94,42 +94,42 @@ zix_sorted_array_find(const ZixSortedArray* a, /** Return the element at index `index`. */ -ZIX_API +ZIX_PURE_API void* zix_sorted_array_index(const ZixSortedArray* a, size_t index); /** Return the data associated with the given array item. */ -ZIX_API +ZIX_CONST_API void* zix_sorted_array_get_data(ZixSortedArrayIter ai); /** Return an iterator to the first (smallest) element in `a`. */ -ZIX_API +ZIX_PURE_API ZixSortedArrayIter zix_sorted_array_begin(ZixSortedArray* a); /** Return an iterator the the element one past the last element in `a`. */ -ZIX_API +ZIX_PURE_API ZixSortedArrayIter zix_sorted_array_end(ZixSortedArray* a); /** Return true iff `a` is an iterator to the end of its tree. */ -ZIX_API +ZIX_PURE_API bool zix_sorted_array_iter_is_end(ZixSortedArray* a, ZixSortedArrayIter i); /** Return an iterator that points to the element one past `a`. */ -ZIX_API +ZIX_PURE_API ZixSortedArrayIter zix_sorted_array_iter_next(ZixSortedArray* a, ZixSortedArrayIter i); @@ -61,7 +61,7 @@ zix_tree_free(ZixTree* t); /** Return the number of elements in `t`. */ -ZIX_API size_t +ZIX_PURE_API size_t zix_tree_size(const ZixTree* t); /** @@ -86,55 +86,55 @@ zix_tree_find(const ZixTree* t, const void* e, ZixTreeIter** ti); /** Return the data associated with the given tree item. */ -ZIX_API void* +ZIX_PURE_API void* zix_tree_get(const ZixTreeIter* ti); /** Return an iterator to the first (smallest) element in `t`. */ -ZIX_API ZixTreeIter* +ZIX_PURE_API ZixTreeIter* zix_tree_begin(ZixTree* t); /** Return an iterator the the element one past the last element in `t`. */ -ZIX_API ZixTreeIter* +ZIX_CONST_API ZixTreeIter* zix_tree_end(ZixTree* t); /** Return true iff `i` is an iterator to the end of its tree. */ -ZIX_API bool +ZIX_CONST_API bool zix_tree_iter_is_end(const ZixTreeIter* i); /** Return an iterator to the last (largest) element in `t`. */ -ZIX_API ZixTreeIter* +ZIX_PURE_API ZixTreeIter* zix_tree_rbegin(ZixTree* t); /** Return an iterator the the element one before the first element in `t`. */ -ZIX_API ZixTreeIter* +ZIX_CONST_API ZixTreeIter* zix_tree_rend(ZixTree* t); /** Return true iff `i` is an iterator to the reverse end of its tree. */ -ZIX_API bool +ZIX_CONST_API bool zix_tree_iter_is_rend(const ZixTreeIter* i); /** Return an iterator that points to the element one past `i`. */ -ZIX_API ZixTreeIter* +ZIX_PURE_API ZixTreeIter* zix_tree_iter_next(ZixTreeIter* i); /** Return an iterator that points to the element one before `i`. */ -ZIX_API ZixTreeIter* +ZIX_PURE_API ZixTreeIter* zix_tree_iter_prev(ZixTreeIter* i); /** diff --git a/zix/trie_util.h b/zix/trie_util.h index c10f30a..ff125e1 100644 --- a/zix/trie_util.h +++ b/zix/trie_util.h @@ -42,7 +42,7 @@ zix_trie_find_key(const uint8_t* const keys, const size_t n, const uint8_t k) #else /** Return the index of the first element in `keys` >= `k`, or `n`. */ -static inline size_t +static inline ZIX_PURE_FUNC size_t zix_trie_find_key(const uint8_t* const keys, const size_t n, const uint8_t k) { size_t first = 0; |