@@ -44,10 +44,17 @@ However, participation requires adherence to fundamental ground rules:
44
44
This variant should be considered the standard for all documentation efforts.
45
45
For instance, opt for "initialize" over "initialise" and "color" rather than "colour".
46
46
47
+ ### Code Formatting Tools
48
+
47
49
Software requirement: [ clang-format] ( https://clang.llvm.org/docs/ClangFormat.html ) version 18 or later.
48
50
49
- This repository consistently contains an up-to-date ` .clang-format ` file with rules that match the explained ones.
50
- For maintaining a uniform coding style, execute the command ` clang-format -i *.{c,h} ` .
51
+ This repository contains a ` .clang-format ` file that enforces the coding style described below.
52
+ To format your code, run:
53
+ ``` bash
54
+ clang-format -i * .{c,h}
55
+ ```
56
+
57
+ ** Note** : The pre-commit hooks will verify code formatting automatically.
51
58
52
59
## Coding Style for Modern C
53
60
@@ -203,6 +210,12 @@ Use [snake_case](https://en.wikipedia.org/wiki/Snake_case) for naming convention
203
210
and avoid using "camelCase."
204
211
Additionally, do not use Hungarian notation or any other unnecessary prefixes or suffixes.
205
212
213
+ #### Pointer NULL checks
214
+
215
+ Both ` if (!ptr) ` and ` if (ptr == NULL) ` are acceptable for checking NULL pointers.
216
+ The ` !ptr ` form is idiomatic C and widely used throughout the codebase.
217
+ Choose one style and use it consistently within a function or module.
218
+
206
219
When declaring pointers, follow these spacing conventions:
207
220
``` c
208
221
const char *name; /* Const pointer; '*' with the name and a space before it */
@@ -365,17 +378,21 @@ int inspect(obj_t *obj)
365
378
}
366
379
```
367
380
368
- Instead, consider this approach :
381
+ Prefer early return for error conditions :
369
382
```c
370
383
int inspect(obj_t *obj)
371
384
{
372
385
if (!cond)
373
386
return -1;
387
+
388
+ /* Main logic here */
374
389
...
375
390
return 0;
376
391
}
377
392
```
378
393
394
+ This pattern reduces nesting and keeps the main logic at the primary indentation level.
395
+
379
396
However, be careful not to make the logic more convoluted in an attempt to simplify nesting.
380
397
381
398
### ` if ` statements
@@ -391,15 +408,16 @@ Curly brackets and spacing follow the K&R style:
391
408
}
392
409
```
393
410
394
- Simple and succinct one-line if-statements may omit curly brackets:
411
+ Simple one-line if-statements may omit curly brackets:
395
412
```c
396
413
if (!valid)
397
414
return -1;
398
415
```
399
416
400
- However, do prefer curly brackets with multi-line or more complex statements.
401
- If one branch uses curly brackets, then all other branches shall use the
402
- curly brackets too.
417
+ Curly brackets are required when:
418
+ - The statement spans multiple lines
419
+ - The statement is complex or contains nested operations
420
+ - Any branch in an if-else chain uses curly brackets (then all branches must use them)
403
421
404
422
Wrap long conditions to the if-statement indentation adding extra 4 spaces:
405
423
``` c
877
895
Date: Mon Feb 24 13:08:32 2025 +0800
878
896
879
897
Introduce CPU architecture filtering in scheduler
880
-
898
+
881
899
In environments with mixed CPU architectures, it is crucial to ensure
882
900
that an instance runs only on a host with a compatible CPU
883
901
type—preventing, for example, a RISC-V instance from being scheduled on
884
902
an Arm host.
885
-
903
+
886
904
This new scheduler filter enforces that requirement by comparing an
887
905
instance's architecture against the host's allowed architectures. For
888
906
the libvirt driver, the host's guest capabilities are queried, and the
889
907
permitted architectures are recorded in the permitted_instances_types
890
908
list within the host's cpu_info dictionary.
891
-
909
+
892
910
The filter systematically excludes hosts that do not support the
893
911
instance's CPU architecture. Additionally, RISC-V has been added to the
894
912
set of acceptable architectures for scheduling.
895
-
913
+
896
914
Note that the CPU architecture filter is disabled by default.
897
915
```
898
916
0 commit comments