This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathHACKING
127 lines (93 loc) · 3.28 KB
/
HACKING
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Buxton Hacking
--------------
Note that in order to contribute to Buxton you should first fork the
repository on GitHub [1], and create a pull request to master from your
feature branch.
Indentation
-----------
Buxton uses tabs for indentation, with a tab width of 8. Ensure you do
not mix spaces with tabs, all source files within Buxton provide modelines,
please ensure your editor complies.
Coding Style
------------
Always use a fail-first approach, ensuring you exit from your function if
there is erroneous input, for example, and not deep within a function.
Buxton does not use spaces after function invocations, example:
buxton_function(x, y, z);
Whereas this is considered invalid:
buxton_function (x, y, z);
Spaces should still be used for loops, if-checks, etc:
while (someCondition) {
}
And not:
while(someCondition) {
}
When using internal (core/library) functionality, and not the *public API*,
you should use helpers/workflow that already exist. For example we have
automatic macros for freeing various types of data:
_cleanup_buxton_key_ BuxtonKey key;
This ensures that where appropriate, your memory is automatically free'd
when it is out of scope. For more information please consult src/shared/util.h
All if-blocks should have curly braces (brackets) and parentheses, even if
they are single line checks.
A valid example:
if (connected) {
/* Do something */
}
dosomethingelse();
Invalid:
if (connected)
/* Do something */
dosomethingelse();
Additionally, curly braces should always be on the same line as the conditional,
and are only on separate lines in the opening body of a function declaration.
A valid example in a conditional check:
if (someCondition) {
/* Do something */
}
An invalid conditional check:
if (someCondition)
{
/* Do something */
}
An invalid function declaration:
void doSomething(void) {
/* Body */
}
Whereas this would be a valid example:
void doSomething(void)
{
/* Body */
}
Always use C style comments (/* */) unless it is a FIXME (also try
to avoid these where possible.)
/* Valid comment */
// Invalid comment
//FIXME: Valid FIXME statement with short description
A word on data types:
----------
When using the public API please ensure you keep your data types consistent
with those publicly accessible. This means ensuring you are using uint64_t,
uint32_t, etc.
When using internal APIs, ensure that you use all available internal data
types, such as BuxtonList, BuxtonArray, taking note of the pros and cons
of vector approaches versus linked-list, etc. In order of degrading performance
and resource usage:
BuxtonArray (simple vector)
BuxtonList (doubly linked list)
Hashmap (key,value hashmap)
Mixing APIs
-----------
Note that internal library APIs may not be mixed with the public consumable
API, as only the public API has guarantee of stability, and is unlikely
to change. This means you should not use the cleanup helpers, etc, within
your public components.
Final note
---------
If changing "core" (daemon/library/cli) functionality, ensure that you
run "make check" and "make distcheck" to validate changes. Always aim
to provide maximum coverage (as checked by gcov), which may mean providing
extra unit tests within test/ - Provide these as a separate commit if
necessary.
---
* [1] https://github.com/intel/buxton