Support c89

This commit is contained in:
2024-01-22 11:48:59 -08:00
parent b39979a471
commit 387b04d7a3
2 changed files with 27 additions and 28 deletions

View File

@@ -6,8 +6,6 @@ project(
LANGUAGES C CXX) LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
add_compile_options(-fdata-sections -ffunction-sections -fPIE) add_compile_options(-fdata-sections -ffunction-sections -fPIE)
if(APPLE) if(APPLE)
@@ -43,11 +41,12 @@ add_test(NAME conflict_set_test COMMAND conflict_set_test)
# api smoke tests # api smoke tests
# c99 # c90
add_executable(conflict_set_c_api_test conflict_set_c_api_test.c ConflictSet.h) add_executable(conflict_set_c_api_test conflict_set_c_api_test.c ConflictSet.h)
target_link_libraries(conflict_set_c_api_test PRIVATE conflict_set) target_link_libraries(conflict_set_c_api_test PRIVATE conflict_set)
target_compile_options(conflict_set_c_api_test PRIVATE -UNDEBUG) target_compile_options(conflict_set_c_api_test PRIVATE -UNDEBUG)
set_property(TARGET conflict_set_c_api_test PROPERTY C_STANDARD 99) set_property(TARGET conflict_set_c_api_test PROPERTY C_STANDARD 90)
set_property(TARGET conflict_set_c_api_test PROPERTY C_STANDARD_REQUIRED ON)
add_test(NAME conflict_set_c_api_test COMMAND conflict_set_c_api_test) add_test(NAME conflict_set_c_api_test COMMAND conflict_set_c_api_test)
target_compile_options(conflict_set_c_api_test PRIVATE -Wall -Wextra -Wpedantic -Wunreachable-code -Werror) target_compile_options(conflict_set_c_api_test PRIVATE -Wall -Wextra -Wpedantic -Wunreachable-code -Werror)

View File

@@ -78,54 +78,54 @@ private:
typedef struct ConflictSet ConflictSet; typedef struct ConflictSet ConflictSet;
typedef enum { typedef enum {
/// The result of a check which does not intersect any conflicting writes /* The result of a check which does not intersect any conflicting writes */
ConflictSet_Commit, ConflictSet_Commit,
/// The result of a check which intersects a write at a version > /* The result of a check which intersects a write at a version > */
/// readVersion /* readVersion */
ConflictSet_Conflict, ConflictSet_Conflict,
/// The result of a check with a readVersion older than the highest call to /* The result of a check with a readVersion older than the highest call to */
/// `setOldestVersion` /* `setOldestVersion` */
ConflictSet_TooOld ConflictSet_TooOld
} ConflictSet_Result; } ConflictSet_Result;
/// Bytes ordered lexicographically /* Bytes ordered lexicographically */
typedef struct { typedef struct {
const uint8_t *p; const uint8_t *p;
int len; int len;
} ConflictSet_Key; } ConflictSet_Key;
/// Denotes a set of keys to be checked for conflicts /* Denotes a set of keys to be checked for conflicts */
typedef struct { typedef struct {
ConflictSet_Key begin; ConflictSet_Key begin;
/// `end` having length 0 denotes that this range is the single key {begin}. /* `end` having length 0 denotes that this range is the single key {begin}. */
/// Otherwise this denotes the range [begin, end) /* Otherwise this denotes the range [begin, end) */
ConflictSet_Key end; ConflictSet_Key end;
int64_t readVersion; int64_t readVersion;
} ConflictSet_ReadRange; } ConflictSet_ReadRange;
/// Denotes a set of keys to be considered written at `writeVersion` /* Denotes a set of keys to be considered written at `writeVersion` */
typedef struct { typedef struct {
ConflictSet_Key begin; ConflictSet_Key begin;
/// `end` having length 0 denotes that this range is the single key {begin}. /* `end` having length 0 denotes that this range is the single key {begin}. */
/// Otherwise this denotes the range [begin, end) /* Otherwise this denotes the range [begin, end) */
ConflictSet_Key end; ConflictSet_Key end;
/// Write version must be greater than all write versions in all previous /* Write version must be greater than all write versions in all previous */
/// calls to `addWrites` /* calls to `addWrites` */
int64_t writeVersion; int64_t writeVersion;
} ConflictSet_WriteRange; } ConflictSet_WriteRange;
/// `reads` must be sorted ascending, and must not have adjacent or /* `reads` must be sorted ascending, and must not have adjacent or */
/// overlapping ranges. The result of checking reads[i] is written in /* overlapping ranges. The result of checking reads[i] is written in */
/// results[i]. /* results[i]. */
void ConflictSet_check(ConflictSet *cs, const ConflictSet_ReadRange *reads, void ConflictSet_check(ConflictSet *cs, const ConflictSet_ReadRange *reads,
ConflictSet_Result *results, int count); ConflictSet_Result *results, int count);
/// `writes` must be sorted ascending, and must not have adjacent or /* `writes` must be sorted ascending, and must not have adjacent or */
/// overlapping ranges. Reads intersecting writes where readVersion < /* overlapping ranges. Reads intersecting writes where readVersion < */
/// writeVersion will result in `Conflict` (or `TooOld`, eventually) /* writeVersion will result in `Conflict` (or `TooOld`, eventually) */
void ConflictSet_addWrites(ConflictSet *cs, void ConflictSet_addWrites(ConflictSet *cs,
const ConflictSet_WriteRange *writes, int count); const ConflictSet_WriteRange *writes, int count);
/// Reads where readVersion < oldestVersion will result in `TooOld`. Must be /* Reads where readVersion < oldestVersion will result in `TooOld`. Must be */
/// greater than any previous oldestVersion. /* greater than any previous oldestVersion. */
void ConflictSet_setOldestVersion(ConflictSet *cs, int64_t oldestVersion); void ConflictSet_setOldestVersion(ConflictSet *cs, int64_t oldestVersion);
/// Reads where readVersion < oldestVersion will result in `TooOld`. There are /* Reads where readVersion < oldestVersion will result in `TooOld`. There are */
/// no writes initially. /* no writes initially. */
ConflictSet *ConflictSet_create(int64_t oldestVersion, uint64_t seed); ConflictSet *ConflictSet_create(int64_t oldestVersion, uint64_t seed);
void ConflictSet_destroy(ConflictSet *cs); void ConflictSet_destroy(ConflictSet *cs);