Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ scripts/format.sh --fix # rewrite in place

### 1.2 Notes

- `meson setup` generates the optional `seqlock_version.h` into the build directory; `seqlock.h` does not include it.
- `include/seqlock.h` defines the version macros, and `meson setup` fails when they differ from `project(version:)`, so a release updates both. `include/seqlock_version.h` is a deprecated header that includes `seqlock.h`.
- The build produces only a static library. The only Meson option is `build_tests`.
- `SEQLOCK_COUNTER_TYPE` and the backend macros must be identical for the library and every caller; nothing detects a mismatch. `seqlock.h` includes `seqlock_conf.h` with quotes, so configuration is by `-D` only, never by a replacement header.
- ThreadSanitizer needs a 4 KiB-page kernel with a 48-bit address space on AArch64, and AddressSanitizer does not start on a 39-bit one; use a plain native build there.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Changed

- `seqlock.h` defines `SEQLOCK_VERSION_MAJOR`, `_MINOR`, `_PATCH`, `SEQLOCK_VERSION`, `SEQLOCK_VERSION_STRING` and a new `SEQLOCK_VERSION_NUMBER` (`long`, `MAJOR * 10000 + MINOR * 100 + PATCH`), so a copied-in header carries its version. `seqlock_version.h` is no longer generated; it is installed as a deprecated header that includes `seqlock.h`. Meson fails to configure when the header and `project(version:)` disagree, and the build needs Meson 0.57 or later.
- The build produces and installs only the static library. The shared library, which neither `seqlock_dep` nor `seqlock.pc` linked, is no longer built.
- CI installs Meson, Ninja and gcovr with `uv` instead of `pip`.
- CI gates on 100% branch coverage as well as line coverage. The reader retry branches are reached deterministically by a single-threaded test, and the no-atomics backend is built and tested alongside the C11 backend.
Expand Down
20 changes: 0 additions & 20 deletions config/seqlock_version.h.in

This file was deleted.

22 changes: 22 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,25 @@ record_load(const record_cell_t *cell, void *out)
```

`size` must not exceed `RECORD_MAX_BYTES` and must not change while the cell is in use, because the reader and the writer both copy that many bytes.

## Version

`seqlock.h` defines the release it belongs to, so a copied-in header still identifies itself:

<!-- snippet: skip -->
```c
#define SEQLOCK_VERSION_MAJOR 0
#define SEQLOCK_VERSION_MINOR 1
#define SEQLOCK_VERSION_PATCH 1
#define SEQLOCK_VERSION "0.1.1"
```

`SEQLOCK_VERSION_NUMBER` is `MAJOR * 10000 + MINOR * 100 + PATCH` as a `long`, so it holds any version where `int` is 16 bits. Compare it in the preprocessor to require a minimum release:

```c
#if SEQLOCK_VERSION_NUMBER < 101L
#error "seqlock 0.1.1 or later is required"
#endif
```

`SEQLOCK_VERSION_STRING` is the same string as `SEQLOCK_VERSION`. `seqlock_version.h` is a deprecated header that includes `seqlock.h`, kept so existing includes compile until the next major release.
2 changes: 1 addition & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Breaking the single-writer rule, or calling `init` while the cell is in use, is

## MISRA C:2023

`misch` analyses `include/` and `src/` once for each backend: the `__atomic` backend in the base configuration, and the C11 and uniprocessor backends through the `c11` and `no_atomics` profiles in `misra.toml`, because each backend compiles different code. Each analysis has a baseline in `analysis/baseline/` that records its accepted findings, and CI fails on any finding outside it. No deviation is recorded for any finding.
`misch` analyses `include/` and `src/` once for each backend: the `__atomic` backend in the base configuration, and the C11 and uniprocessor backends through the `c11` and `no_atomics` profiles in `misra.toml`, because each backend compiles different code. Each analysis has a baseline in `analysis/baseline/` that records its accepted findings, and CI fails on any finding outside it. The only recorded deviation is an inline one of Rule 2.5 (unused macro) for the version macros in `seqlock.h`, which exist for consumers and are not used by the library.

The baselines hold 42, 36 and 35 findings. All three share the same core of Rules 2.5, 8.7, 12.1, 15.5 and 20.10. The rest follow from the backend: Rule 17.3 only for the `__atomic` backend, whose builtins have no declaration; Rule 10.4 only for the C11 backend; and Rules 12.3 and 13.4 only for the uniprocessor backend, whose counter-store macro uses the comma operator and an assignment as an operand. Full tool-driven compliance needs a certified static analyser, which this repository does not vendor.

Expand Down
5 changes: 2 additions & 3 deletions docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Keep both headers in the same directory, because `seqlock.h` includes `seqlock_c
#include "seqlock.h"
```

`seqlock_version.h` exists only in Meson builds.
`seqlock.h` defines the version macros described in [api.md](api.md#version).

## Meson subproject

Expand Down Expand Up @@ -55,10 +55,9 @@ The install contains `libseqlock.a`, the headers in a `seqlock/` subdirectory, a
<!-- snippet: skip -->
```c
#include <seqlock/seqlock.h>
#include <seqlock/seqlock_version.h>
```

`seqlock_version.h` defines `SEQLOCK_VERSION_STRING` as the version string, and `SEQLOCK_VERSION_MAJOR`, `SEQLOCK_VERSION_MINOR` and `SEQLOCK_VERSION_PATCH` as integers.
`seqlock_version.h` is installed beside it as a deprecated header that includes `seqlock.h`.

## Configuration

Expand Down
26 changes: 26 additions & 0 deletions include/seqlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@
#include <stddef.h>
#include <stdint.h>

/* ================ VERSION ================================================= */

/**
* @name Version
* @brief Release of this header, for diagnostics and @c #if checks.
*
* @details
* @c SEQLOCK_VERSION_NUMBER is @c MAJOR*10000 @c + @c MINOR*100
* @c + @c PATCH with type @c long, so it cannot overflow where @c int is
* 16 bits. The Meson build fails to configure when these values differ
* from the project version.
* @{
*/
/* cppcheck-suppress-begin misra-c2012-2.5 ; @deviation Public version macros
* for consumer diagnostics and #if checks; the library does not use them. */
#define SEQLOCK_VERSION_MAJOR 0
#define SEQLOCK_VERSION_MINOR 1
#define SEQLOCK_VERSION_PATCH 1
#define SEQLOCK_VERSION "0.1.1"
#define SEQLOCK_VERSION_STRING SEQLOCK_VERSION
#define SEQLOCK_VERSION_NUMBER \
((SEQLOCK_VERSION_MAJOR * 10000L) + (SEQLOCK_VERSION_MINOR * 100L) \
+ SEQLOCK_VERSION_PATCH)
/* cppcheck-suppress-end misra-c2012-2.5 ; @deviation As above. */
/** @} */

/* ================ COMPILE-TIME GUARANTEES ================================= */

/* The protocol relies on unsigned wraparound and parity (even/odd); a signed
Expand Down
19 changes: 19 additions & 0 deletions include/seqlock_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* SPDX-License-Identifier: MIT
*
* @file seqlock_version.h
*
* @brief
* Deprecated: the version macros are defined in seqlock.h.
*
* @details
* This header includes seqlock.h so that existing includes keep compiling.
* It will be removed in the next major release.
*/

#ifndef SEQLOCK_VERSION_H_
#define SEQLOCK_VERSION_H_

#include "seqlock.h"

#endif /* SEQLOCK_VERSION_H_ */
50 changes: 28 additions & 22 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(
'seqlock',
'c',
version: '0.1.1',
meson_version: '>=0.57.0',
default_options: [
'c_std=c11',
'warning_level=3',
Expand All @@ -13,43 +14,48 @@ project(

project_description = 'A small Meson-based sequence lock library in C'

ver = meson.project_version().split('.')
major = ver[0].to_int()
minor = ver[1].to_int()
patch = ver[2].to_int()
# include/seqlock.h defines the version macros, so a copy-in build has them.
# Configuration fails when they differ from the project version.

conf = configuration_data()
conf.set_quoted('VERSION', meson.project_version())
conf.set('MAJOR', major)
conf.set('MINOR', minor)
conf.set('PATCH', patch)

generated_version_header = configure_file(
input: 'config' / 'seqlock_version.h.in',
output: 'seqlock_version.h',
configuration: conf,
install: true,
install_dir: get_option('includedir') / 'seqlock',
)
fs = import('fs')
version_parts = meson.project_version().split('.')
version_macros = {
'SEQLOCK_VERSION_MAJOR': version_parts[0],
'SEQLOCK_VERSION_MINOR': version_parts[1],
'SEQLOCK_VERSION_PATCH': version_parts[2],
'SEQLOCK_VERSION': '"' + meson.project_version() + '"',
}
header_lines = []
foreach line : fs.read('include' / 'seqlock.h').split('\n')
header_lines += ' '.join(line.split())
endforeach
foreach name, value : version_macros
if '#define @0@ @1@'.format(name, value) not in header_lines
error('include/seqlock.h must define @0@ as @1@'.format(name, value))
endif
endforeach

public_headers = include_directories('include')
generated_headers = include_directories('.')

library_sources = files('src/seqlock.c')

seqlock_lib = static_library(
'seqlock',
library_sources,
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
install: true,
)

install_headers('include/seqlock.h', 'include/seqlock_conf.h', subdir: 'seqlock')
install_headers(
'include/seqlock.h',
'include/seqlock_conf.h',
'include/seqlock_version.h',
subdir: 'seqlock',
)

seqlock_dep = declare_dependency(
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
link_with: seqlock_lib,
sources: generated_version_header,
)

meson.override_dependency('seqlock', seqlock_dep)
Expand Down
18 changes: 9 additions & 9 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test_basic_exe = executable(
'test_seqlock',
files('test_seqlock.c'),
dependencies: [seqlock_dep],
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
)
test('seqlock basic', test_basic_exe)

Expand All @@ -17,7 +17,7 @@ test_core_exe = executable(
'test_seqlock_core',
files('test_seqlock_core.c'),
dependencies: [seqlock_dep],
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
)
test('seqlock core', test_core_exe)

Expand All @@ -26,7 +26,7 @@ test_try_exe = executable(
'test_seqlock_try_load',
files('test_seqlock_try_load.c'),
dependencies: [seqlock_dep],
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
)
test('seqlock try_load', test_try_exe)

Expand All @@ -35,7 +35,7 @@ test_wrap_exe = executable(
'test_seqlock_wrap',
files('test_seqlock_wrap.c'),
dependencies: [seqlock_dep],
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
)
test('seqlock wrap', test_wrap_exe)

Expand All @@ -50,7 +50,7 @@ foreach backend : [['c11', 'SEQLOCK_USE_C11_ATOMICS'], ['no_atomics', 'SEQLOCK_U
'test_seqlock_' + backend[0],
files('test_seqlock_backend.c') + library_sources,
c_args: ['-D@0@=1'.format(backend[1])],
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
),
)
endforeach
Expand All @@ -63,7 +63,7 @@ test_retry_exe = executable(
'test_seqlock_retry',
files('test_seqlock_retry.c'),
dependencies: [seqlock_dep],
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
)
test('seqlock retry', test_retry_exe)

Expand All @@ -74,7 +74,7 @@ test_retry_relax_exe = executable(
'-DSEQLOCK_TEST_RELAX_HOOK=1',
'-DSEQLOCK_CPU_RELAX()=do { extern void seqlock_test_relax(void); seqlock_test_relax(); } while (0)',
],
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
)
test('seqlock retry relax', test_retry_relax_exe)

Expand All @@ -85,7 +85,7 @@ test_mt_exe = executable(
'test_seqlock_mt',
files('test_seqlock_mt.c'),
dependencies: [seqlock_dep, thread_dep],
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
)
test('seqlock mt', test_mt_exe, timeout: 120)

Expand All @@ -94,7 +94,7 @@ test_soak_exe = executable(
'test_seqlock_soak',
files('test_seqlock_soak.c'),
dependencies: [seqlock_dep, thread_dep],
include_directories: [public_headers, generated_headers],
include_directories: public_headers,
)
test('seqlock soak', test_soak_exe, timeout: 180)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_seqlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "seqlock.h"
#include "seqlock_test.h"
#include "seqlock_version.h"

#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -151,6 +152,16 @@ TEST_CASE(test_large_payload)
}
}

/* The deprecated version header still exposes the macros from seqlock.h. */
TEST_CASE(test_version_macros)
{
TEST_ASSERT(SEQLOCK_VERSION_NUMBER
== ((SEQLOCK_VERSION_MAJOR * 10000L)
+ (SEQLOCK_VERSION_MINOR * 100L)
+ SEQLOCK_VERSION_PATCH));
TEST_ASSERT(SEQLOCK_VERSION_STRING[0] != '\0');
}

int
main(void)
{
Expand All @@ -162,6 +173,7 @@ main(void)
run_test(test_even_counter_advances_by_two, "even_counter_advances");
run_test(test_null_validation, "null_validation");
run_test(test_large_payload, "large_payload");
run_test(test_version_macros, "version_macros");

(void)fprintf(stdout, "\n=== all basic tests passed ===\n\n");
return EXIT_SUCCESS;
Expand Down
Loading