summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--src/zix/btree.c35
-rw-r--r--src/zix/btree.h10
-rw-r--r--src/zix/common.h15
-rw-r--r--src/zix/digest.c16
-rw-r--r--src/zix/digest.h8
-rw-r--r--src/zix/hash.c14
-rw-r--r--src/zix/hash.h2
-rw-r--r--wscript2
9 files changed, 64 insertions, 44 deletions
diff --git a/NEWS b/NEWS
index c6979ab..506fb04 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+sord (0.16.7) unstable;
+
+ * Clean up code
+
+ -- David Robillard <d@drobilla.net> Wed, 11 Nov 2020 12:28:08 +0000
+
sord (0.16.6) stable;
* Fix potential crash or incorrectness issues with GCC 10
diff --git a/src/zix/btree.c b/src/zix/btree.c
index 0a8010f..3dc2d57 100644
--- a/src/zix/btree.c
+++ b/src/zix/btree.c
@@ -108,7 +108,7 @@ zix_btree_node_new(const bool leaf)
return node;
}
-ZIX_API ZixBTree*
+ZixBTree*
zix_btree_new(const ZixComparator cmp,
const void* const cmp_data,
const ZixDestroyFunc destroy)
@@ -147,7 +147,7 @@ zix_btree_free_rec(ZixBTree* const t, ZixBTreeNode* const n)
}
}
-ZIX_API void
+void
zix_btree_free(ZixBTree* const t)
{
if (t) {
@@ -156,7 +156,7 @@ zix_btree_free(ZixBTree* const t)
}
}
-ZIX_API size_t
+size_t
zix_btree_size(const ZixBTree* const t)
{
return t->size;
@@ -292,7 +292,7 @@ zix_btree_node_find(const ZixBTree* const t,
return first;
}
-ZIX_API ZixStatus
+ZixStatus
zix_btree_insert(ZixBTree* const t, void* const e)
{
ZixBTreeNode* parent = NULL; // Parent of n
@@ -504,7 +504,7 @@ zix_btree_remove_max(ZixBTree* const t, ZixBTreeNode* n)
return n->vals[--n->n_vals];
}
-ZIX_API ZixStatus
+ZixStatus
zix_btree_remove(ZixBTree* const t,
const void* const e,
void** const out,
@@ -622,7 +622,7 @@ zix_btree_remove(ZixBTree* const t,
return ZIX_STATUS_ERROR;
}
-ZIX_API ZixStatus
+ZixStatus
zix_btree_find(const ZixBTree* const t,
const void* const e,
ZixBTreeIter** const ti)
@@ -653,7 +653,7 @@ zix_btree_find(const ZixBTree* const t,
return ZIX_STATUS_NOT_FOUND;
}
-ZIX_API ZixStatus
+ZixStatus
zix_btree_lower_bound(const ZixBTree* const t,
const void* const e,
ZixBTreeIter** const ti)
@@ -709,7 +709,7 @@ zix_btree_lower_bound(const ZixBTree* const t,
return ZIX_STATUS_SUCCESS;
}
-ZIX_API void*
+void*
zix_btree_get(const ZixBTreeIter* const ti)
{
const ZixBTreeIterFrame* const frame = &ti->stack[ti->level];
@@ -718,7 +718,7 @@ zix_btree_get(const ZixBTreeIter* const ti)
return frame->node->vals[frame->index];
}
-ZIX_API ZixBTreeIter*
+ZixBTreeIter*
zix_btree_begin(const ZixBTree* const t)
{
ZixBTreeIter* const i = zix_btree_iter_new(t);
@@ -741,13 +741,13 @@ zix_btree_begin(const ZixBTree* const t)
return i;
}
-ZIX_API ZixBTreeIter*
+ZixBTreeIter*
zix_btree_end(const ZixBTree* const t)
{
return zix_btree_iter_new(t);
}
-ZIX_API ZixBTreeIter*
+ZixBTreeIter*
zix_btree_iter_copy(const ZixBTreeIter* const i)
{
if (!i) {
@@ -762,20 +762,19 @@ zix_btree_iter_copy(const ZixBTreeIter* const i)
return j;
}
-ZIX_API bool
+bool
zix_btree_iter_is_end(const ZixBTreeIter* const i)
{
return !i || i->stack[0].node == NULL;
}
-ZIX_API bool
+bool
zix_btree_iter_equals(const ZixBTreeIter* const lhs, const ZixBTreeIter* const rhs)
{
if (zix_btree_iter_is_end(lhs) && zix_btree_iter_is_end(rhs)) {
return true;
- } else if (zix_btree_iter_is_end(lhs) || zix_btree_iter_is_end(rhs)) {
- return false;
- } else if (!lhs || !rhs || lhs->level != rhs->level) {
+ } else if (zix_btree_iter_is_end(lhs) || zix_btree_iter_is_end(rhs) ||
+ lhs->level != rhs->level) {
return false;
}
@@ -785,7 +784,7 @@ zix_btree_iter_equals(const ZixBTreeIter* const lhs, const ZixBTreeIter* const r
(lhs->level + 1) * sizeof(ZixBTreeIterFrame));
}
-ZIX_API void
+void
zix_btree_iter_increment(ZixBTreeIter* const i)
{
ZixBTreeIterFrame* f = &i->stack[i->level];
@@ -826,7 +825,7 @@ zix_btree_iter_increment(ZixBTreeIter* const i)
}
}
-ZIX_API void
+void
zix_btree_iter_free(ZixBTreeIter* const i)
{
free(i);
diff --git a/src/zix/btree.h b/src/zix/btree.h
index 4c972f6..c1610a8 100644
--- a/src/zix/btree.h
+++ b/src/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/src/zix/common.h b/src/zix/common.h
index 3271858..f7ec4c3 100644
--- a/src/zix/common.h
+++ b/src/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/src/zix/digest.c b/src/zix/digest.c
index 889cfde..2ac1715 100644
--- a/src/zix/digest.c
+++ b/src/zix/digest.c
@@ -27,13 +27,13 @@
// SSE 4.2 CRC32
-ZIX_API uint32_t
+uint32_t
zix_digest_start(void)
{
return 1;
}
-ZIX_API uint32_t
+uint32_t
zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
{
const uint8_t* str = (const uint8_t*)buf;
@@ -57,7 +57,7 @@ zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
return hash;
}
-ZIX_API uint32_t
+uint32_t
zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len)
{
assert((uintptr_t)buf % sizeof(uint64_t) == 0);
@@ -73,7 +73,7 @@ zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len)
return hash;
}
-ZIX_API uint32_t
+uint32_t
zix_digest_add_ptr(const uint32_t hash, const void* const ptr)
{
#if UINTPTR_MAX == UINT64_MAX
@@ -87,13 +87,13 @@ zix_digest_add_ptr(const uint32_t hash, const void* const ptr)
// Classic DJB hash
-ZIX_API uint32_t
+uint32_t
zix_digest_start(void)
{
return 5381;
}
-ZIX_API uint32_t
+uint32_t
zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
{
const uint8_t* str = (const uint8_t*)buf;
@@ -105,7 +105,7 @@ zix_digest_add(uint32_t hash, const void* const buf, const size_t len)
return hash;
}
-ZIX_API uint32_t
+uint32_t
zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len)
{
assert((uintptr_t)buf % sizeof(uint64_t) == 0);
@@ -114,7 +114,7 @@ zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len)
return zix_digest_add(hash, buf, len);
}
-ZIX_API uint32_t
+uint32_t
zix_digest_add_ptr(const uint32_t hash, const void* const ptr)
{
return zix_digest_add(hash, &ptr, sizeof(ptr));
diff --git a/src/zix/digest.h b/src/zix/digest.h
index 16ba9b9..c9f3ec0 100644
--- a/src/zix/digest.h
+++ b/src/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
diff --git a/src/zix/hash.c b/src/zix/hash.c
index c4a2dba..35eaf24 100644
--- a/src/zix/hash.c
+++ b/src/zix/hash.c
@@ -51,7 +51,7 @@ zix_hash_value(ZixHashEntry* entry)
return entry + 1;
}
-ZIX_API ZixHash*
+ZixHash*
zix_hash_new(ZixHashFunc hash_func,
ZixEqualFunc equal_func,
size_t value_size)
@@ -72,7 +72,7 @@ zix_hash_new(ZixHashFunc hash_func,
return hash;
}
-ZIX_API void
+void
zix_hash_free(ZixHash* hash)
{
if (!hash) {
@@ -92,7 +92,7 @@ zix_hash_free(ZixHash* hash)
free(hash);
}
-ZIX_API size_t
+size_t
zix_hash_size(const ZixHash* hash)
{
return hash->count;
@@ -144,7 +144,7 @@ find_entry(const ZixHash* hash,
return NULL;
}
-ZIX_API void*
+void*
zix_hash_find(const ZixHash* hash, const void* value)
{
const unsigned h_nomod = hash->hash_func(value);
@@ -153,7 +153,7 @@ zix_hash_find(const ZixHash* hash, const void* value)
return entry ? zix_hash_value(entry) : 0;
}
-ZIX_API ZixStatus
+ZixStatus
zix_hash_insert(ZixHash* hash, const void* value, void** inserted)
{
unsigned h_nomod = hash->hash_func(value);
@@ -191,7 +191,7 @@ zix_hash_insert(ZixHash* hash, const void* value, void** inserted)
return ZIX_STATUS_SUCCESS;
}
-ZIX_API ZixStatus
+ZixStatus
zix_hash_remove(ZixHash* hash, const void* value)
{
const unsigned h_nomod = hash->hash_func(value);
@@ -221,7 +221,7 @@ zix_hash_remove(ZixHash* hash, const void* value)
return ZIX_STATUS_NOT_FOUND;
}
-ZIX_API void
+void
zix_hash_foreach(ZixHash* hash,
ZixHashVisitFunc f,
void* user_data)
diff --git a/src/zix/hash.h b/src/zix/hash.h
index 9546a64..2550676 100644
--- a/src/zix/hash.h
+++ b/src/zix/hash.h
@@ -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);
/**
diff --git a/wscript b/wscript
index 79e6697..bcd96df 100644
--- a/wscript
+++ b/wscript
@@ -11,7 +11,7 @@ from waflib.extras import autowaf
# major increment <=> incompatible changes
# minor increment <=> compatible changes (additions)
# micro increment <=> no interface changes
-SORD_VERSION = '0.16.6'
+SORD_VERSION = '0.16.7'
SORD_MAJOR_VERSION = '0'
# Mandatory waf variables