summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format9
-rw-r--r--.clang-tidy2
-rw-r--r--NEWS7
-rw-r--r--README.md6
-rw-r--r--benchmark/dict_bench.c3
-rw-r--r--doc/Doxyfile.in1
-rw-r--r--include/zix/allocator.h4
-rw-r--r--include/zix/attributes.h13
-rw-r--r--include/zix/btree.h3
-rw-r--r--include/zix/filesystem.h9
-rw-r--r--include/zix/hash.h5
-rw-r--r--include/zix/path.h4
-rw-r--r--include/zix/ring.h4
-rw-r--r--include/zix/sem.h4
-rw-r--r--include/zix/string_view.h2
-rw-r--r--include/zix/tree.h1
-rw-r--r--meson.build5
-rw-r--r--src/filesystem.c9
-rw-r--r--src/hash.c2
-rw-r--r--src/path.c7
-rw-r--r--src/posix/filesystem_posix.c9
-rw-r--r--src/tree.c2
-rw-r--r--test/meson.build36
-rw-r--r--test/test_digest.c3
-rw-r--r--test/test_filesystem.c20
-rw-r--r--test/test_hash.c29
-rw-r--r--test/test_ring.c2
-rw-r--r--test/test_thread.c9
-rw-r--r--test/test_tree.c4
29 files changed, 152 insertions, 62 deletions
diff --git a/.clang-format b/.clang-format
index e8e993c..6245b22 100644
--- a/.clang-format
+++ b/.clang-format
@@ -19,15 +19,18 @@ IndentPPDirectives: AfterHash
KeepEmptyLinesAtTheStartOfBlocks: false
SpacesInContainerLiterals: false
StatementMacros:
+ - FALLTHROUGH
+ - ZIX_ALWAYS_INLINE_FUNC
- ZIX_API
- ZIX_BEGIN_DECLS
- ZIX_CONST_API
- - 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
- - ZIX_THREAD_FUNC
- - ZIX_UNUSED
- _Pragma
...
diff --git a/.clang-tidy b/.clang-tidy
index 5380ced..1c5a762 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -5,8 +5,10 @@ Checks: >
*,
-altera-*,
-bugprone-assignment-in-if-condition,
+ -bugprone-switch-missing-default-case,
-hicpp-multiway-paths-covered,
-llvmlibc-*,
+ -misc-include-cleaner,
-readability-identifier-length,
WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
diff --git a/NEWS b/NEWS
index fab3fd4..7e95197 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,13 @@
-zix (0.4.3) unstable; urgency=medium
+zix (0.5.0) unstable; urgency=medium
+ * Add ZIX_NODISCARD attribute
* Avoid fdatasync() on Darwin
+ * Fix build on POSIX systems without PATH_MAX defined
* Fix library current_version on MacOS
* Fix nullability annotations for zix_canonical_path() and friends
+ * Fix ring unit test when mlock() is unavailable
- -- David Robillard <d@drobilla.net> Thu, 14 Mar 2024 16:59:01 +0000
+ -- David Robillard <d@drobilla.net> Sun, 23 Jun 2024 12:18:29 +0000
zix (0.4.2) stable; urgency=medium
diff --git a/README.md b/README.md
index 6e1dd35..654c3d4 100644
--- a/README.md
+++ b/README.md
@@ -39,9 +39,9 @@ Zix is continually tested on:
* Debian GNU/Linux 11 (x86, x64, arm32, and arm64)
* Fedora 36 (x64)
- * FreeBSD 13.2 (x64)
- * MacOS 11.7 (x64)
- * Node 12 (as wasm via emscripten)
+ * FreeBSD 13 (x64)
+ * MacOS 14 (M2)
+ * Node 12 (as wasm via emscripten 2.0.12)
* Windows 10 (x86)
Dependencies
diff --git a/benchmark/dict_bench.c b/benchmark/dict_bench.c
index 5d9acd0..279e6ad 100644
--- a/benchmark/dict_bench.c
+++ b/benchmark/dict_bench.c
@@ -45,7 +45,8 @@ 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/Doxyfile.in b/doc/Doxyfile.in
index cce012f..741fe1a 100644
--- a/doc/Doxyfile.in
+++ b/doc/Doxyfile.in
@@ -37,6 +37,7 @@ PREDEFINED = ZIX_ALLOCATED= \
ZIX_END_DECLS= \
ZIX_MALLOC_API= \
ZIX_MALLOC_FUNC= \
+ ZIX_NODISCARD= \
ZIX_NONNULL= \
ZIX_NULLABLE= \
ZIX_PURE_API= \
diff --git a/include/zix/allocator.h b/include/zix/allocator.h
index 619697e..bace039 100644
--- a/include/zix/allocator.h
+++ b/include/zix/allocator.h
@@ -108,6 +108,7 @@ 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(ZixAllocator* const ZIX_NULLABLE allocator, const size_t size)
{
@@ -117,6 +118,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_calloc(ZixAllocator* const ZIX_NULLABLE allocator,
const size_t nmemb,
@@ -128,6 +130,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_realloc(ZixAllocator* const ZIX_NULLABLE allocator,
void* const ZIX_NULLABLE ptr,
@@ -149,6 +152,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_aligned_alloc(ZixAllocator* const ZIX_NULLABLE allocator,
const size_t alignment,
diff --git a/include/zix/attributes.h b/include/zix/attributes.h
index 518e5fb..249e6a6 100644
--- a/include/zix/attributes.h
+++ b/include/zix/attributes.h
@@ -38,27 +38,32 @@
# define ZIX_PURE_FUNC __attribute__((pure))
# define ZIX_CONST_FUNC __attribute__((const))
# define ZIX_MALLOC_FUNC __attribute__((malloc))
+# define ZIX_NODISCARD __attribute__((warn_unused_result))
#else
# define ZIX_ALWAYS_INLINE_FUNC ///< Should absolutely always be inlined
# define ZIX_PURE_FUNC ///< Only reads memory
# define ZIX_CONST_FUNC ///< Only reads its parameters
-# define ZIX_MALLOC_FUNC ///< Allocates memory
+# define ZIX_MALLOC_FUNC ///< Allocates memory with no pointers in it
+# define ZIX_NODISCARD ///< Returns a value that must be used
#endif
/// A pure function in the public API that only reads memory
#define ZIX_PURE_API \
ZIX_API \
- ZIX_PURE_FUNC
+ 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_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_MALLOC_FUNC \
+ ZIX_NODISCARD
// Printf-like format functions
#ifdef __GNUC__
diff --git a/include/zix/btree.h b/include/zix/btree.h
index 3161817..ddade81 100644
--- a/include/zix/btree.h
+++ b/include/zix/btree.h
@@ -60,6 +60,7 @@ typedef void (*ZixBTreeDestroyFunc)(void* ZIX_UNSPECIFIED ptr,
zix_btree_lower_bound() for details.
*/
ZIX_API
+ZIX_NODISCARD
ZixBTree* ZIX_ALLOCATED
zix_btree_new(ZixAllocator* ZIX_NULLABLE allocator,
ZixBTreeCompareFunc ZIX_NONNULL cmp,
@@ -154,6 +155,7 @@ 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_btree_iter_is_end(const ZixBTreeIter i)
{
@@ -167,6 +169,7 @@ zix_btree_iter_increment(ZixBTreeIter* ZIX_NONNULL i);
/// Return an iterator one past `iter`
ZIX_API
+ZIX_NODISCARD
ZixBTreeIter
zix_btree_iter_next(ZixBTreeIter iter);
diff --git a/include/zix/filesystem.h b/include/zix/filesystem.h
index 9abafe1..221e165 100644
--- a/include/zix/filesystem.h
+++ b/include/zix/filesystem.h
@@ -146,7 +146,7 @@ zix_create_directory_symlink(const char* ZIX_NONNULL target_path,
@return The path of the created directory, or null.
*/
-ZIX_API
+ZIX_MALLOC_API
char* ZIX_NULLABLE
zix_create_temporary_directory(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NONNULL path_pattern);
@@ -194,6 +194,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_file_equals(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NONNULL a_path,
@@ -227,7 +228,7 @@ zix_file_equals(ZixAllocator* ZIX_NULLABLE allocator,
@return A new canonical version of `path`, or null if it doesn't exist.
*/
-ZIX_API
+ZIX_MALLOC_API
char* ZIX_NULLABLE
zix_canonical_path(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NULLABLE path);
@@ -346,7 +347,7 @@ zix_file_size(const char* ZIX_NONNULL path);
@param allocator Allocator used for the returned path.
*/
-ZIX_API
+ZIX_MALLOC_API
char* ZIX_ALLOCATED
zix_current_path(ZixAllocator* ZIX_NULLABLE allocator);
@@ -357,7 +358,7 @@ zix_current_path(ZixAllocator* ZIX_NULLABLE allocator);
@return A new path to a temporary directory, or null on error.
*/
-ZIX_API
+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 e425b9f..6cd2271 100644
--- a/include/zix/hash.h
+++ b/include/zix/hash.h
@@ -28,14 +28,14 @@ ZIX_BEGIN_DECLS
#if defined(ZIX_HASH_KEY_TYPE)
typedef ZIX_HASH_KEY_TYPE ZixHashKey;
#else
-typedef void ZixHashKey; ///< The type of a key within a record
+typedef void ZixHashKey; ///< The type of a key within a record
#endif
// ZIX_HASH_RECORD_TYPE can be defined to make the API more type-safe
#if defined(ZIX_HASH_RECORD_TYPE)
typedef ZIX_HASH_RECORD_TYPE ZixHashRecord;
#else
-typedef void ZixHashRecord; ///< The type of a hash table record
+typedef void ZixHashRecord; ///< The type of a hash table record
#endif
// ZIX_HASH_SEARCH_DATA_TYPE can be defined to make the API more type-safe
@@ -103,6 +103,7 @@ typedef bool (*ZixKeyEqualFunc)(const ZixHashKey* ZIX_NONNULL a,
@param equal_func A function to test keys for equality.
*/
ZIX_API
+ZIX_NODISCARD
ZixHash* ZIX_ALLOCATED
zix_hash_new(ZixAllocator* ZIX_NULLABLE allocator,
ZixKeyFunc ZIX_NONNULL key_func,
diff --git a/include/zix/path.h b/include/zix/path.h
index 13225e6..22c8202 100644
--- a/include/zix/path.h
+++ b/include/zix/path.h
@@ -36,6 +36,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_path_join(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NULLABLE a,
@@ -55,6 +56,7 @@ zix_path_join(ZixAllocator* ZIX_NULLABLE allocator,
else).
*/
ZIX_API
+ZIX_NODISCARD
char* ZIX_ALLOCATED
zix_path_preferred(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NONNULL path);
@@ -71,6 +73,7 @@ zix_path_preferred(ZixAllocator* ZIX_NULLABLE allocator,
zix_canonical_path().
*/
ZIX_API
+ZIX_NODISCARD
char* ZIX_ALLOCATED
zix_path_lexically_normal(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NONNULL path);
@@ -83,6 +86,7 @@ zix_path_lexically_normal(ZixAllocator* ZIX_NULLABLE allocator,
up-references).
*/
ZIX_API
+ZIX_NODISCARD
char* ZIX_ALLOCATED
zix_path_lexically_relative(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NONNULL path,
diff --git a/include/zix/ring.h b/include/zix/ring.h
index 61c99be..db72f41 100644
--- a/include/zix/ring.h
+++ b/include/zix/ring.h
@@ -40,7 +40,8 @@ typedef struct ZixRingImpl ZixRing;
At most `size` - 1 bytes may be stored in the ring at once.
*/
-ZIX_MALLOC_API
+ZIX_API
+ZIX_NODISCARD
ZixRing* ZIX_ALLOCATED
zix_ring_new(ZixAllocator* ZIX_NULLABLE allocator, uint32_t size);
@@ -155,6 +156,7 @@ zix_ring_write(ZixRing* ZIX_NONNULL ring,
@return A new empty transaction.
*/
ZIX_API
+ZIX_NODISCARD
ZixRingTransaction
zix_ring_begin_write(ZixRing* ZIX_NONNULL ring);
diff --git a/include/zix/sem.h b/include/zix/sem.h
index 8aa205e..42dd6c3 100644
--- a/include/zix/sem.h
+++ b/include/zix/sem.h
@@ -30,8 +30,8 @@ ZIX_BEGIN_DECLS
This is an integer that is never negative, and has two main operations:
increment (post) and decrement (wait). If a decrement can't be performed
- (because the value is 0) the caller will be blocked until another thread posts
- and the operation can succeed.
+ (because the value is 0) the caller will be blocked until another thread
+ posts and the operation can succeed.
Semaphores can be created with any starting value, but typically this will
be 0 so the semaphore can be used as a simple signal where each post
diff --git a/include/zix/string_view.h b/include/zix/string_view.h
index f13f8d1..f463c1f 100644
--- a/include/zix/string_view.h
+++ b/include/zix/string_view.h
@@ -89,7 +89,7 @@ zix_string(const char* const ZIX_NULLABLE str)
/**
Copy a string view into a newly allocated null-terminated string.
*/
-ZIX_API
+ZIX_MALLOC_API
char* ZIX_ALLOCATED
zix_string_view_copy(ZixAllocator* ZIX_NULLABLE allocator, ZixStringView view);
diff --git a/include/zix/tree.h b/include/zix/tree.h
index 0ad37f2..b51fa72 100644
--- a/include/zix/tree.h
+++ b/include/zix/tree.h
@@ -38,6 +38,7 @@ typedef void (*ZixTreeDestroyFunc)(void* ZIX_UNSPECIFIED ptr,
/// Create a new (empty) tree
ZIX_API
+ZIX_NODISCARD
ZixTree* ZIX_ALLOCATED
zix_tree_new(ZixAllocator* ZIX_NULLABLE allocator,
bool allow_duplicates,
diff --git a/meson.build b/meson.build
index 0675045..f84642b 100644
--- a/meson.build
+++ b/meson.build
@@ -12,10 +12,11 @@ project(
],
license: 'ISC',
meson_version: '>= 0.56.0',
- version: '0.4.3',
+ version: '0.5.0',
)
zix_src_root = meson.current_source_dir()
+zix_build_root = meson.current_build_dir()
major_version = meson.project_version().split('.')[0]
version_suffix = '-@0@'.format(major_version)
versioned_name = 'zix' + version_suffix
@@ -409,7 +410,7 @@ libzix = library(
versioned_name,
sources,
c_args: c_suppressions + library_c_args,
- darwin_versions: ['0.4.0', meson.project_version()],
+ darwin_versions: ['0.5.0', meson.project_version()],
dependencies: dependencies,
gnu_symbol_visibility: 'hidden',
include_directories: include_dirs,
diff --git a/src/filesystem.c b/src/filesystem.c
index 95005ae..61487e9 100644
--- a/src/filesystem.c
+++ b/src/filesystem.c
@@ -49,17 +49,18 @@ zix_create_directories(ZixAllocator* const allocator,
// Create each directory down the path
while (p.state != ZIX_PATH_END) {
- const char old_end = path[p.range.end];
+ char* const end = &path[p.range.end];
+ const char old_last = *end;
- path[p.range.end] = '\0';
+ *end = '\0';
if (zix_file_type(path) != ZIX_FILE_TYPE_DIRECTORY) {
if ((st = zix_create_directory(path))) {
break;
}
}
- path[p.range.end] = old_end;
- p = zix_path_next(path, p);
+ *end = old_last;
+ p = zix_path_next(path, p);
}
zix_free(allocator, path);
diff --git a/src/hash.c b/src/hash.c
index 7fc345d..7576eba 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -175,7 +175,7 @@ rehash(ZixHash* const hash, const size_t old_n_entries)
// Reinsert every element into the new array
for (size_t i = 0U; i < old_n_entries; ++i) {
- ZixHashEntry* const entry = &old_entries[i];
+ const ZixHashEntry* const entry = &old_entries[i];
if (entry->value) {
assert(hash->mask == hash->n_entries - 1U);
diff --git a/src/path.c b/src/path.c
index c0140e4..404557a 100644
--- a/src/path.c
+++ b/src/path.c
@@ -356,10 +356,9 @@ zix_path_lexically_normal(ZixAllocator* const allocator, const char* const path)
size_t last = r;
size_t next = 0;
for (size_t i = root_len; i < r;) {
- if (last < r && i > 2 && i + 1 <= r && result[i - 2] == sep &&
- result[i - 1] == '.' && result[i] == '.' &&
- (!result[i + 1] || is_dir_sep(result[i + 1]))) {
- if (i < r && result[i + 1] == sep) {
+ if (last < r && i > 2U && result[i - 2U] == sep && result[i - 1U] == '.' &&
+ result[i] == '.' && (!result[i + 1U] || is_dir_sep(result[i + 1U]))) {
+ if (result[i + 1] == sep) {
++i;
}
diff --git a/src/posix/filesystem_posix.c b/src/posix/filesystem_posix.c
index c752e4a..be13995 100644
--- a/src/posix/filesystem_posix.c
+++ b/src/posix/filesystem_posix.c
@@ -27,6 +27,7 @@
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
@@ -89,7 +90,7 @@ copy_path(ZixAllocator* const allocator,
#if !defined(PATH_MAX) && USE_PATHCONF
static size_t
-max_path_size(void)
+max_path_size(const char* const path)
{
const long path_max = pathconf(path, _PC_PATH_MAX);
return (path_max > 0) ? (size_t)path_max : zix_system_page_size();
@@ -98,8 +99,10 @@ max_path_size(void)
#elif !defined(PATH_MAX)
static size_t
-max_path_size(void)
+max_path_size(const char* const path)
{
+ (void)path;
+
return zix_system_page_size();
}
@@ -439,7 +442,7 @@ zix_current_path(ZixAllocator* const allocator)
#elif USE_PATHCONF
// Others don't so we have to query PATH_MAX at runtime to allocate the result
- const size_t size = max_path_size();
+ const size_t size = max_path_size(".");
char* const buffer = (char*)zix_calloc(allocator, size, 1);
char* const current = getcwd(buffer, size);
if (!current) {
diff --git a/src/tree.c b/src/tree.c
index 3c705c6..5e3aa61 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -507,6 +507,8 @@ zix_tree_remove(ZixTree* t, ZixTreeIter* ti)
t->root = replace;
}
+ assert(n->left);
+
replace->parent = n->parent;
replace->left = n->left;
n->left->parent = replace;
diff --git a/test/meson.build b/test/meson.build
index 15f449c..166de7d 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -23,6 +23,40 @@ if not meson.is_subproject() and get_option('lint')
suite: 'data',
)
endif
+
+ # Check code formatting
+ clang_format = find_program('clang-format', required: false)
+ if clang_format.found()
+ test(
+ 'format',
+ clang_format,
+ args: ['--Werror', '--dry-run'] + c_headers + sources,
+ suite: 'code',
+ )
+ endif
+
+ # Check code with cppcheck
+ if not meson.is_subproject()
+ cppcheck = find_program('cppcheck', required: false)
+ if cppcheck.found()
+ compdb_path = join_paths(zix_build_root, 'compile_commands.json')
+ test(
+ 'cppcheck',
+ cppcheck,
+ args: [
+ '--check-level=exhaustive',
+ '--enable=warning,style,performance,portability',
+ '--error-exitcode=1',
+ '--project=' + compdb_path,
+ '--suppress=constParameterCallback',
+ '--suppress=constParameterPointer',
+ '--suppress=unreadVariable',
+ '-q',
+ ],
+ suite: 'code',
+ )
+ endif
+ endif
endif
# Set warning suppression flags specific to tests
@@ -103,7 +137,7 @@ foreach test, cases : sequential_tests
endforeach
endforeach
-# Test multi-threaded
+# Test multi-threaded
if thread_dep.found()
foreach test, cases : threaded_tests
sources = common_test_sources + files('test_@0@.c'.format(test))
diff --git a/test/test_digest.c b/test/test_digest.c
index 7e7e77a..7228f86 100644
--- a/test/test_digest.c
+++ b/test/test_digest.c
@@ -116,7 +116,8 @@ test_digest_aligned(void)
}
}
-ZIX_PURE_FUNC int
+ZIX_PURE_FUNC
+int
main(void)
{
test_digest32();
diff --git a/test/test_filesystem.c b/test/test_filesystem.c
index 4a1ad4f..87a3d15 100644
--- a/test/test_filesystem.c
+++ b/test/test_filesystem.c
@@ -162,14 +162,18 @@ test_file_type(void)
const socklen_t addr_len = sizeof(struct sockaddr_un);
struct sockaddr_un* const addr = (struct sockaddr_un*)calloc(1, addr_len);
- addr->sun_family = AF_UNIX;
- strncpy(addr->sun_path, file_path, sizeof(addr->sun_path) - 1);
-
- const int fd = bind(sock, (struct sockaddr*)addr, addr_len);
- if (fd >= 0) {
- assert(zix_file_type(file_path) == ZIX_FILE_TYPE_SOCKET);
- assert(!zix_remove(file_path));
- close(fd);
+ if (strlen(file_path) < sizeof(addr->sun_path)) {
+ addr->sun_family = AF_UNIX;
+ strncpy(addr->sun_path, file_path, sizeof(addr->sun_path) - 1);
+
+ const int fd = bind(sock, (struct sockaddr*)addr, addr_len);
+ if (fd >= 0) {
+ assert(zix_file_type(file_path) == ZIX_FILE_TYPE_SOCKET);
+ assert(!zix_remove(file_path));
+ close(fd);
+ }
+ } else {
+ fprintf(stderr, "warning: Skipped socket test with oddly long TMPDIR\n");
}
close(sock);
diff --git a/test/test_hash.c b/test/test_hash.c
index b1de72a..3d3ca95 100644
--- a/test/test_hash.c
+++ b/test/test_hash.c
@@ -47,21 +47,24 @@ 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;
@@ -74,7 +77,8 @@ 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);
@@ -83,19 +87,22 @@ 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);
@@ -106,7 +113,8 @@ 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);
@@ -135,7 +143,7 @@ stress_with(ZixAllocator* const allocator,
static const size_t string_length = 15;
char* const buffer = (char*)calloc(1, n_elems * (string_length + 1));
- char** const strings = state.strings = (char**)calloc(sizeof(char*), n_elems);
+ char** const strings = state.strings = (char**)calloc(n_elems, sizeof(char*));
state.buffer = buffer;
state.strings = strings;
ENSURE(&state, buffer && state.strings, "Failed to allocate strings\n");
@@ -290,7 +298,8 @@ 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 46abe05..b1845ce 100644
--- a/test/test_ring.c
+++ b/test/test_ring.c
@@ -101,7 +101,7 @@ test_ring(const unsigned size)
assert(zix_ring_write_space(ring) == zix_ring_capacity(ring));
const ZixStatus st = zix_ring_mlock(ring);
- assert(!st || st == ZIX_STATUS_NOT_SUPPORTED);
+ assert(!st || st == ZIX_STATUS_NOT_SUPPORTED || st == ZIX_STATUS_UNAVAILABLE);
static const size_t stack_size = (size_t)MSG_SIZE * 4U;
diff --git a/test/test_thread.c b/test/test_thread.c
index 8cfc9f4..09edde6 100644
--- a/test/test_thread.c
+++ b/test/test_thread.c
@@ -3,6 +3,7 @@
#undef NDEBUG
+#include "zix/status.h"
#include "zix/thread.h"
#include <assert.h>
@@ -32,8 +33,12 @@ main(int argc, char** argv)
SharedData data = {argc + (int)strlen(argv[0]), 0};
- assert(!zix_thread_create(&thread, 128, thread_func, &data));
- assert(!zix_thread_join(thread));
+ ZixStatus st = zix_thread_create(&thread, 128, thread_func, &data);
+ assert(!st);
+
+ st = zix_thread_join(thread);
+ assert(!st);
+
assert(data.output == data.input * 7);
return 0;
diff --git a/test/test_tree.c b/test/test_tree.c
index 5f093d3..fae6d85 100644
--- a/test/test_tree.c
+++ b/test/test_tree.c
@@ -21,7 +21,7 @@
#include <stdlib.h>
#include <time.h>
-static uintptr_t seed = 1;
+static size_t seed = 1;
static int
int_cmp(const void* a, const void* b, const void* ZIX_UNUSED(user_data))
@@ -237,7 +237,7 @@ main(int argc, char** argv)
if (argc > 2) {
seed = strtoul(argv[2], NULL, 10);
} else {
- seed = (uintptr_t)time(NULL);
+ seed = (size_t)time(NULL);
}
}