lz4
/
CODING_STYLE
57 строк · 3.4 Кб
1LZ4 CODING STYLE
2================
3
4When contributing code and patches to the `LZ4` project, the following rules are expected to be followed for a successful merge.
5
6
7Library
8-------
9
10The library's source code in `lib/` directory has a BSD 2-clause license.
11It's designed to be integrated into 3rd party applications.
12
13It adheres relatively strictly to vanilla `C90`, with the following exceptions:
14- `long long` type is required, in order to support 64-bit values
15- Variadic Macros are used for debug mode (but not required in release mode)
16
17Beyond that, all other rules and limitations of C90 must be respected, including `/* ... */` comment style only, and variable declaration at top of block only. The automated CI test suite will check for these rules.
18
19The code is allowed to use more modern variants (C99 / C11 / C23) when useful
20as long as it provides a clean C90 backup for older compilers.
21For example, C99+ compilers will employ the `restrict` keyword, while `C90` ones will ignore it, thanks to conditional macros.
22This ensures maximum portability across a wide range of systems.
23
24Moreover, in the interest of safety, the code has to respect a fairly strigent list of additional restrictions, provided through warning flags, the list of which is maintained within `Makefile`.
25Among the less common ones, we want the source to be compatible with `-Wc++-compat`, which ensures that the code can be compiled "as is", with no modification, as C++ code. It makes it possible to copy-paste the code into other C++ source files, or the source files are just dropped into a C++ environment which then compiles them as C++ source files.
26
27
28Command Line Interface
29----------------------
30
31The CLI executable's source code in `programs/` directory has a GPLv2+ license.
32While it's designed to be portable and freely distributable, it's not meant to be integrated into 3rd party applications.
33The license difference is meant to reflect that choice.
34
35Similar to the library, the CLI adheres relatively strictly to vanilla `C90`, and features the same exceptions:
36- `long long` requirement for 64-bit values
37- Variadic Macros for console messages (now used all the time, not just debug mode)
38
39The code can also use system-specific libraries and symbols (such as `posix` ones)
40as long as it provides a backup for plain `C90` platforms.
41It's even allowed to lose capabilities, as long as the CLI can be cleanly compiled on `C90`.
42For example, systems without `<pthread>` support nor Completion Ports will just not feature multi-threading support, and run single threaded.
43
44In the interest of build familiarity, the CLI source code also respects the same set of advanced warning flags as the library.
45That being said, this last part is debatable and could deviate in the future.
46For example, there are less reasons to support `-Wc++-compat` on the CLI side, since it's not meant to be integrated into 3rd party applications.
47
48
49Others
50------
51
52The repository includes other directories with their own set of compilable projects, such as `tests/`, `examples/` and `contrib/`.
53
54These repositories do not have to respect the same set of restrictions, and can employ a larger array of different languages.
55For example, some tests employ `sh`, and others employ `python`.
56
57These directories may nonetheless include several targets employing the same coding convention as the `lz4` library. This is in a no way a rule, more like a side effect of build familiarity.
58