commit 9154055aa48317af46f837630d76538c880b30a5
parent bd7b2c7fa380a60e61bfa770a678004a501ca582
Author: Paul Walker <paul@pwjw.com>
Date: Fri, 23 Dec 2022 09:37:51 -0500
Review feedback: move to _GE, _LT, _EQ macros
Diffstat:
4 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -3,11 +3,11 @@ enable_testing()
# Extract the version from header file
file(READ "include/clap/version.h" clap_version_header)
-string(REGEX MATCH "CLAP_VERSION_MAJOR_DIGITS ([0-9]+)" _ ${clap_version_header})
+string(REGEX MATCH "CLAP_VERSION_MAJOR ([0-9]+)" _ ${clap_version_header})
set(CLAP_VERSION_MAJOR ${CMAKE_MATCH_1})
-string(REGEX MATCH "CLAP_VERSION_MINOR_DIGITS ([0-9]+)" _ ${clap_version_header})
+string(REGEX MATCH "CLAP_VERSION_MINOR ([0-9]+)" _ ${clap_version_header})
set(CLAP_VERSION_MINOR ${CMAKE_MATCH_1})
-string(REGEX MATCH "CLAP_VERSION_REVISION_DIGITS ([0-9]+)" _ ${clap_version_header})
+string(REGEX MATCH "CLAP_VERSION_REVISION ([0-9]+)" _ ${clap_version_header})
set(CLAP_VERSION_REVISION ${CMAKE_MATCH_1})
message(STATUS "CLAP version: ${CLAP_VERSION_MAJOR}.${CLAP_VERSION_MINOR}.${CLAP_VERSION_REVISION}")
diff --git a/ChangeLog.md b/ChangeLog.md
@@ -8,8 +8,10 @@
* Remove UTF-8 BOM from a few files
* [plugin-template.c](src/plugin-template.c): add state impl and some comments
* [audio-ports-activation.h](include/clap/ext/draft/audio-ports-activation.h): improved documentation
-* [version.h](include/clap/version.h): create `CLAP_VERSION_NUMBER` which can be used for preprocessor version checks
- and separate `CLAP_VERSION_MAJOR` (a uint32_t cast of the major version) from `CLAP_VERSION_MAJOR_DIGITS` (the actual digit)
+* [version.h](include/clap/version.h): Add a CLAP_VERSION_GE(maj,min,rev), _EQ and _LT macro. Remove the
+ uint32_t cast from CLAP_VERSION_MAJOR, _MINOR, and _REVISION macro, and introduce it to the CLAP_VERSION_INIT
+ macro. If you rely on these macros being a uint32_t or parse this header using external software, this
+ may be a breaking change.
# Changes in 1.1.4
diff --git a/include/clap/version.h b/include/clap/version.h
@@ -20,20 +20,18 @@ typedef struct clap_version {
}
#endif
-#define CLAP_VERSION_MAJOR_DIGITS 1
-#define CLAP_VERSION_MINOR_DIGITS 1
-#define CLAP_VERSION_REVISION_DIGITS 5
-
-#define CLAP_VERSION_MAJOR ((uint32_t)CLAP_VERSION_MAJOR_DIGITS)
-#define CLAP_VERSION_MINOR ((uint32_t)CLAP_VERSION_MINOR_DIGITS)
-#define CLAP_VERSION_REVISION ((uint32_t)CLAP_VERSION_REVISION_DIGITS)
+#define CLAP_VERSION_MAJOR 1
+#define CLAP_VERSION_MINOR 1
+#define CLAP_VERSION_REVISION 5
#define CLAP_VERSION_INIT \
- { CLAP_VERSION_MAJOR, CLAP_VERSION_MINOR, CLAP_VERSION_REVISION }
+ { (uint32_t)CLAP_VERSION_MAJOR, (uint32_t)CLAP_VERSION_MINOR, (uint32_t)CLAP_VERSION_REVISION }
-// CLAP_VERSION_NUMBER can be used as a preprocessor directive comparator, for
-// instance `#if CLAP_VERSION_NUMBER >= 0x010105` will be clap versions at or after 1.1.5
-#define CLAP_VERSION_NUMBER ((CLAP_VERSION_MAJOR_DIGITS << 16) + (CLAP_VERSION_MINOR_DIGIT << 8) + CLAP_VERSION_REVISION_DIGIT)
+#define CLAP_VERSION_LT(maj,min,rev) ((maj < CLAP_VERSION_MAJOR) || \
+ (maj == CLAP_VERSION_MAJOR && min < CLAP_VERSION_MINOR ) || \
+ (maj == CLAP_VERSION_MAJOR && min == CLAP_VERSION_MINOR && rev < CLAP_VERSION_REVISION))
+#define CLAP_VERSION_EQ(maj,min,rev) ((maj == CLAP_VERSION_MAJOR) && (min == CLAP_VERSION_MINOR) && (rev == CLAP_VERSION_REVISION))
+#define CLAP_VERSION_GE(maj,min,rev) (!CLAP_VERSION_LT(maj,min,rev))
static const CLAP_CONSTEXPR clap_version_t CLAP_VERSION = CLAP_VERSION_INIT;
@@ -44,10 +42,4 @@ clap_version_is_compatible(const clap_version_t v) {
}
-#if defined(__cplusplus) && __cplusplus >= 201703L
-// Static assert some version constraints
-static_assert(CLAP_VERSION_MAJOR_DIGITS < 256 && CLAP_VERSION_MAJOR_DIGITS >= 1);
-static_assert(CLAP_VERSION_MINOR_DIGITS < 256 && CLAP_VERSION_REVISION >= 0);
-static_assert(CLAP_VERSION_REVISION_DIGITS < 256 && CLAP_VERSION_REVISION_DIGITS >= 0);
-#endif
diff --git a/src/main.cc b/src/main.cc
@@ -2,8 +2,24 @@
// The purpose of this file is to check that all headers compile
+#if CLAP_VERSION_LT(CLAP_VERSION_MAJOR, CLAP_VERSION_MINOR, CLAP_VERSION_REVISION)
+SOFTWARE ERROR: CLAP_VERSION_LT is inconsistent
+#endif
+
+#if !CLAP_VERSION_EQ(CLAP_VERSION_MAJOR, CLAP_VERSION_MINOR, CLAP_VERSION_REVISION)
+SOFTWARE ERROR: CLAP_VERSION_EQ is inconsistent
+#endif
+
+#if !CLAP_VERSION_GE(CLAP_VERSION_MAJOR, CLAP_VERSION_MINOR, CLAP_VERSION_REVISION)
+SOFTWARE ERROR: CLAP_VERSION_GE is inconsistent
+#endif
+
+#if CLAP_VERSION_LT(1,1,5)
+SOFTWARE ERROR: CLAP_VERSION_GE was inroduced in 1.1.5 so we should be later than that version.
+#endif
+
static const CLAP_CONSTEXPR clap_version m = CLAP_VERSION;
int main(int, char **) {
return !clap_version_is_compatible(m);
-}
-\ No newline at end of file
+}