@@ -44,10 +44,17 @@ However, participation requires adherence to fundamental ground rules:
4444 This variant should be considered the standard for all documentation efforts.
4545 For instance, opt for "initialize" over "initialise" and "color" rather than "colour".
4646
47+ ### Code Formatting Tools
48+ 4749Software requirement: [ clang-format] ( https://clang.llvm.org/docs/ClangFormat.html ) version 18 or later.
4850
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.
5158
5259## Coding Style for Modern C
5360
@@ -203,6 +210,12 @@ Use [snake_case](https://en.wikipedia.org/wiki/Snake_case) for naming convention
203210and avoid using "camelCase."
204211Additionally, do not use Hungarian notation or any other unnecessary prefixes or suffixes.
205212
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+ 206219When declaring pointers, follow these spacing conventions:
207220``` c
208221const char *name; /* Const pointer; '*' with the name and a space before it */
@@ -365,17 +378,21 @@ int inspect(obj_t *obj)
365378}
366379```
367380
368- Instead, consider this approach :
381+ Prefer early return for error conditions :
369382```c
370383int inspect(obj_t *obj)
371384{
372385 if (!cond)
373386 return -1;
387+
388+ /* Main logic here */
374389 ...
375390 return 0;
376391}
377392```
378393
394+ This pattern reduces nesting and keeps the main logic at the primary indentation level.
395+ 379396However, be careful not to make the logic more convoluted in an attempt to simplify nesting.
380397
381398### ` if ` statements
@@ -391,15 +408,16 @@ Curly brackets and spacing follow the K&R style:
391408 }
392409```
393410
394- Simple and succinct one-line if-statements may omit curly brackets:
411+ Simple one-line if-statements may omit curly brackets:
395412```c
396413 if (!valid)
397414 return -1;
398415```
399416
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)
403421
404422Wrap long conditions to the if-statement indentation adding extra 4 spaces:
405423``` c
@@ -877,22 +895,22 @@ Author: Jim Huang <jserv@ccns.ncku.edu.tw>
877895Date: Mon Feb 24 13:08:32 2025 +0800
878896
879897 Introduce CPU architecture filtering in scheduler
880-
898+
881899 In environments with mixed CPU architectures, it is crucial to ensure
882900 that an instance runs only on a host with a compatible CPU
883901 type—preventing, for example, a RISC-V instance from being scheduled on
884902 an Arm host.
885-
903+
886904 This new scheduler filter enforces that requirement by comparing an
887905 instance's architecture against the host's allowed architectures. For
888906 the libvirt driver, the host's guest capabilities are queried, and the
889907 permitted architectures are recorded in the permitted_instances_types
890908 list within the host's cpu_info dictionary.
891-
909+
892910 The filter systematically excludes hosts that do not support the
893911 instance's CPU architecture. Additionally, RISC-V has been added to the
894912 set of acceptable architectures for scheduling.
895-
913+
896914 Note that the CPU architecture filter is disabled by default.
897915```
898916
0 commit comments