From 03554253ae5dbdd12d619db81864b38d5e300171 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 20 Oct 2022 21:34:24 -0400 Subject: Factor out public declaration scope markers --- .clang-format | 2 ++ include/zix/allocator.h | 8 ++------ include/zix/attributes.h | 12 ++++++++++++ include/zix/btree.h | 8 ++------ include/zix/digest.h | 8 ++------ include/zix/function_types.h | 8 ++------ include/zix/hash.h | 8 ++------ include/zix/ring.h | 8 ++------ include/zix/sem.h | 8 ++------ include/zix/status.h | 8 ++------ include/zix/thread.h | 8 ++------ include/zix/tree.h | 8 ++------ 12 files changed, 34 insertions(+), 60 deletions(-) diff --git a/.clang-format b/.clang-format index 90caefc..d5bb2b7 100644 --- a/.clang-format +++ b/.clang-format @@ -20,8 +20,10 @@ KeepEmptyLinesAtTheStartOfBlocks: false SpacesInContainerLiterals: false StatementMacros: - ZIX_API + - ZIX_BEGIN_DECLS - ZIX_CONST_API - ZIX_CONST_API + - ZIX_END_DECLS - ZIX_MALLOC_API - ZIX_PURE_API - ZIX_THREAD_FUNC diff --git a/include/zix/allocator.h b/include/zix/allocator.h index 7a4f5ee..26db6d3 100644 --- a/include/zix/allocator.h +++ b/include/zix/allocator.h @@ -8,9 +8,7 @@ #include -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS /** @defgroup zix_allocator Allocator @@ -177,8 +175,6 @@ zix_aligned_free(ZixAllocator* const ZIX_NULLABLE allocator, @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_ALLOCATOR_H */ diff --git a/include/zix/attributes.h b/include/zix/attributes.h index 7c352d2..ea18760 100644 --- a/include/zix/attributes.h +++ b/include/zix/attributes.h @@ -10,6 +10,15 @@ @{ */ +// Public declaration scope +#ifdef __cplusplus +# define ZIX_BEGIN_DECLS extern "C" { +# define ZIX_END_DECLS } +#else +# define ZIX_BEGIN_DECLS +# define ZIX_END_DECLS +#endif + // ZIX_API must be used to decorate things in the public API #ifndef ZIX_API # if defined(_WIN32) && !defined(ZIX_STATIC) && defined(ZIX_INTERNAL) @@ -34,14 +43,17 @@ # define ZIX_MALLOC_FUNC #endif +/// A pure function in the public API that only reads memory #define ZIX_PURE_API \ ZIX_API \ ZIX_PURE_FUNC +/// A const function in the public API that is pure and only reads parameters #define ZIX_CONST_API \ ZIX_API \ ZIX_CONST_FUNC +/// A malloc function in the public API that returns allocated memory #define ZIX_MALLOC_API \ ZIX_API \ ZIX_MALLOC_FUNC diff --git a/include/zix/btree.h b/include/zix/btree.h index 33f47d1..0658be8 100644 --- a/include/zix/btree.h +++ b/include/zix/btree.h @@ -13,9 +13,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS /** @defgroup zix_btree BTree @@ -213,8 +211,6 @@ zix_btree_iter_next(ZixBTreeIter iter); @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_BTREE_H */ diff --git a/include/zix/digest.h b/include/zix/digest.h index 5a0eb16..4c15444 100644 --- a/include/zix/digest.h +++ b/include/zix/digest.h @@ -9,9 +9,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS /** @defgroup zix_digest Digest @@ -94,8 +92,6 @@ zix_digest_aligned(size_t seed, const void* ZIX_NONNULL buf, size_t len); @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_DIGEST_H */ diff --git a/include/zix/function_types.h b/include/zix/function_types.h index 8822847..e2a8958 100644 --- a/include/zix/function_types.h +++ b/include/zix/function_types.h @@ -8,9 +8,7 @@ #include -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS /** @defgroup zix_function_types Function Types @@ -30,8 +28,6 @@ typedef void (*ZixDestroyFunc)(void* ptr, const void* user_data); @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_FUNCTION_TYPES_H */ diff --git a/include/zix/hash.h b/include/zix/hash.h index 397e055..d362389 100644 --- a/include/zix/hash.h +++ b/include/zix/hash.h @@ -11,9 +11,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS /** @defgroup zix_hash Hash @@ -321,8 +319,6 @@ zix_hash_find_record(const ZixHash* ZIX_NONNULL hash, @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_HASH_H */ diff --git a/include/zix/ring.h b/include/zix/ring.h index 66662b7..ec255a4 100644 --- a/include/zix/ring.h +++ b/include/zix/ring.h @@ -10,9 +10,7 @@ #include -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS /** @defgroup zix_ring Ring @@ -208,8 +206,6 @@ zix_ring_commit_write(ZixRing* ZIX_NONNULL ring, @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_RING_H */ diff --git a/include/zix/sem.h b/include/zix/sem.h index 3777497..b22dfdd 100644 --- a/include/zix/sem.h +++ b/include/zix/sem.h @@ -15,9 +15,7 @@ # include #endif -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS #include @@ -147,8 +145,6 @@ struct ZixSemImpl { @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_SEM_H */ diff --git a/include/zix/status.h b/include/zix/status.h index fcd45fb..906b812 100644 --- a/include/zix/status.h +++ b/include/zix/status.h @@ -6,9 +6,7 @@ #include "zix/attributes.h" -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS /** @defgroup zix Zix C API @@ -43,8 +41,6 @@ zix_strerror(ZixStatus status); @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_STATUS_H */ diff --git a/include/zix/thread.h b/include/zix/thread.h index 14c525d..3ba4702 100644 --- a/include/zix/thread.h +++ b/include/zix/thread.h @@ -15,9 +15,7 @@ #include -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS /** @defgroup zix_thread Thread @@ -78,8 +76,6 @@ zix_thread_join(ZixThread thread); @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_THREAD_H */ diff --git a/include/zix/tree.h b/include/zix/tree.h index 7b77a7c..919cba9 100644 --- a/include/zix/tree.h +++ b/include/zix/tree.h @@ -12,9 +12,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +ZIX_BEGIN_DECLS /** @defgroup zix_tree Tree @@ -120,8 +118,6 @@ zix_tree_iter_prev(ZixTreeIter* ZIX_NULLABLE i); @} */ -#ifdef __cplusplus -} /* extern "C" */ -#endif +ZIX_END_DECLS #endif /* ZIX_TREE_H */ -- cgit v1.2.1