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)
set(CMAKE_CXX_STANDARD 20)
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)
if(APPLE)
@@ -43,11 +41,12 @@ add_test(NAME conflict_set_test COMMAND conflict_set_test)
# api smoke tests
# c99
# c90
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_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)
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 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,
/// The result of a check which intersects a write at a version >
/// readVersion
/* The result of a check which intersects a write at a version > */
/* readVersion */
ConflictSet_Conflict,
/// The result of a check with a readVersion older than the highest call to
/// `setOldestVersion`
/* The result of a check with a readVersion older than the highest call to */
/* `setOldestVersion` */
ConflictSet_TooOld
} ConflictSet_Result;
/// Bytes ordered lexicographically
/* Bytes ordered lexicographically */
typedef struct {
const uint8_t *p;
int len;
} ConflictSet_Key;
/// Denotes a set of keys to be checked for conflicts
/* Denotes a set of keys to be checked for conflicts */
typedef struct {
ConflictSet_Key begin;
/// `end` having length 0 denotes that this range is the single key {begin}.
/// Otherwise this denotes the range [begin, end)
/* `end` having length 0 denotes that this range is the single key {begin}. */
/* Otherwise this denotes the range [begin, end) */
ConflictSet_Key end;
int64_t readVersion;
} 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 {
ConflictSet_Key begin;
/// `end` having length 0 denotes that this range is the single key {begin}.
/// Otherwise this denotes the range [begin, end)
/* `end` having length 0 denotes that this range is the single key {begin}. */
/* Otherwise this denotes the range [begin, end) */
ConflictSet_Key end;
/// Write version must be greater than all write versions in all previous
/// calls to `addWrites`
/* Write version must be greater than all write versions in all previous */
/* calls to `addWrites` */
int64_t writeVersion;
} ConflictSet_WriteRange;
/// `reads` must be sorted ascending, and must not have adjacent or
/// overlapping ranges. The result of checking reads[i] is written in
/// results[i].
/* `reads` must be sorted ascending, and must not have adjacent or */
/* overlapping ranges. The result of checking reads[i] is written in */
/* results[i]. */
void ConflictSet_check(ConflictSet *cs, const ConflictSet_ReadRange *reads,
ConflictSet_Result *results, int count);
/// `writes` must be sorted ascending, and must not have adjacent or
/// overlapping ranges. Reads intersecting writes where readVersion <
/// writeVersion will result in `Conflict` (or `TooOld`, eventually)
/* `writes` must be sorted ascending, and must not have adjacent or */
/* overlapping ranges. Reads intersecting writes where readVersion < */
/* writeVersion will result in `Conflict` (or `TooOld`, eventually) */
void ConflictSet_addWrites(ConflictSet *cs,
const ConflictSet_WriteRange *writes, int count);
/// Reads where readVersion < oldestVersion will result in `TooOld`. Must be
/// greater than any previous oldestVersion.
/* Reads where readVersion < oldestVersion will result in `TooOld`. Must be */
/* greater than any previous oldestVersion. */
void ConflictSet_setOldestVersion(ConflictSet *cs, int64_t oldestVersion);
/// Reads where readVersion < oldestVersion will result in `TooOld`. There are
/// no writes initially.
/* Reads where readVersion < oldestVersion will result in `TooOld`. There are */
/* no writes initially. */
ConflictSet *ConflictSet_create(int64_t oldestVersion, uint64_t seed);
void ConflictSet_destroy(ConflictSet *cs);